EMMA Coverage Report (generated Fri Aug 23 16:39:17 PDT 2013)
[all classes][org.chromium.base]

COVERAGE SUMMARY FOR SOURCE FILE [ContextTypes.java]

nameclass, %method, %block, %line, %
ContextTypes.java67%  (2/3)64%  (7/11)70%  (53/76)73%  (12.4/17)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ContextTypes100% (1/1)62%  (5/8)69%  (45/65)73%  (11/15)
contains (Context): boolean 0%   (0/1)0%   (0/5)0%   (0/1)
isRunningInWebapp (Context): boolean 0%   (0/1)0%   (0/9)0%   (0/1)
remove (Context): void 0%   (0/1)0%   (0/6)0%   (0/2)
ContextTypes (): void 100% (1/1)100% (8/8)100% (3/3)
ContextTypes (ContextTypes$1): void 100% (1/1)100% (3/3)100% (1/1)
getInstance (): ContextTypes 100% (1/1)100% (2/2)100% (1/1)
getType (Context): int 100% (1/1)100% (13/13)100% (2/2)
put (Context, int): void 100% (1/1)100% (19/19)100% (4/4)
     
class ContextTypes$10%   (0/1)100% (0/0)100% (0/0)100% (0/0)
     
class ContextTypes$ContextTypesHolder100% (1/1)67%  (2/3)73%  (8/11)70%  (1.4/2)
ContextTypes$ContextTypesHolder (): void 0%   (0/1)0%   (0/3)0%   (0/1)
<static initializer> 100% (1/1)100% (6/6)100% (1/1)
access$100 (): ContextTypes 100% (1/1)100% (2/2)100% (1/1)

1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4 
5package org.chromium.base;
6 
7import android.content.Context;
8 
9import java.util.concurrent.ConcurrentHashMap;
10import java.util.Map;
11 
12/**
13 * Maintains the {@link Context}-to-"context type" mapping. The context type
14 * {@code MODE_APP} is chosen for the application context associated with
15 * the activity running in application mode, while {@code MODE_NORMAL} for main
16 * Chromium activity.
17 *
18 * <p>Used as singleton instance.
19 */
20public class ContextTypes {
21 
22    // Available context types.
23    public static final int CONTEXT_TYPE_NORMAL = 1;
24    public static final int CONTEXT_TYPE_WEBAPP = 2;
25 
26    private final Map<Context, Integer> mContextMap;
27 
28    private ContextTypes() {
29        mContextMap = new ConcurrentHashMap<Context, Integer>();
30    }
31 
32    private static class ContextTypesHolder {
33        private static final ContextTypes INSTANCE = new ContextTypes();
34    }
35 
36    public static ContextTypes getInstance() {
37        return ContextTypesHolder.INSTANCE;
38    }
39 
40    /**
41     * Adds the mapping for the given {@link Context}.
42     *
43     * @param context {@link Context} in interest
44     * @param type the type associated with the context
45     * @throws IllegalArgumentException if type is not a valid one.
46     */
47    public void put(Context context, int type) throws IllegalArgumentException {
48        if (type != CONTEXT_TYPE_NORMAL && type != CONTEXT_TYPE_WEBAPP) {
49            throw new IllegalArgumentException("Wrong context type");
50        }
51        mContextMap.put(context, type);
52    }
53 
54    /**
55     * Removes the mapping for the given context.
56     *
57     * @param context {@link Context} in interest
58     */
59    public void remove(Context context) {
60        mContextMap.remove(context);
61    }
62 
63    /**
64     * Returns type of the given context.
65     *
66     * @param context {@link Context} in interest
67     * @return type associated with the context. Returns {@code MODE_NORMAL} by
68     *     default if the mapping for the queried context is not present.
69     */
70    public int getType(Context context) {
71        Integer contextType = mContextMap.get(context);
72        return contextType == null ? CONTEXT_TYPE_NORMAL : contextType;
73    }
74 
75    /**
76     * Returns whether activity is running in web app mode.
77     *
78     * @param appContext {@link Context} in interest
79     * @return {@code true} when activity is running in web app mode.
80     */
81    @CalledByNative
82    public static boolean isRunningInWebapp(Context appContext) {
83        return ContextTypes.getInstance().getType(appContext)
84                == CONTEXT_TYPE_WEBAPP;
85    }
86 
87    /**
88     * Checks if the mapping exists for the given context.
89     *
90     * @param context {@link Context} in interest
91     * @return {@code true} if the mapping exists; otherwise {@code false}
92     */
93    public boolean contains(Context context) {
94        return mContextMap.containsKey(context);
95    }
96}

[all classes][org.chromium.base]
EMMA 2.0.5312 (C) Vladimir Roubtsov