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

COVERAGE SUMMARY FOR SOURCE FILE [WeakContext.java]

nameclass, %method, %block, %line, %
WeakContext.java50%  (1/2)17%  (1/6)12%  (6/49)18%  (2/11)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class WeakContext$10%   (0/1)0%   (0/2)0%   (0/15)0%   (0/2)
WeakContext$1 (Context, String): void 0%   (0/1)0%   (0/9)0%   (0/1)
call (): Object 0%   (0/1)0%   (0/6)0%   (0/1)
     
class WeakContext100% (1/1)25%  (1/4)18%  (6/34)20%  (2/10)
WeakContext (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getContext (): Context 0%   (0/1)0%   (0/4)0%   (0/1)
getSystemService (String): Object 0%   (0/1)0%   (0/21)0%   (0/6)
initializeWeakContext (Context): void 100% (1/1)100% (6/6)100% (2/2)

1// Copyright (c) 2012 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.lang.ref.WeakReference;
10import java.util.concurrent.Callable;
11 
12// Holds a WeakReference to Context to allow it to be GC'd.
13// Also provides utility functions to getSystemService from the UI or any
14// other thread (may return null, if the Context has been nullified).
15public class WeakContext {
16    private static WeakReference<Context> sWeakContext;
17 
18    public static void initializeWeakContext(final Context context) {
19        sWeakContext = new WeakReference<Context>(context);
20    }
21 
22    public static Context getContext() {
23        return sWeakContext.get();
24    }
25 
26    // Returns a system service. May be called from any thread.
27    // If necessary, it will send a message to the main thread to acquire the
28    // service, and block waiting for it to complete.
29    // May return null if context is no longer available.
30    public static Object getSystemService(final String name) {
31        final Context context = sWeakContext.get();
32        if (context == null) {
33            return null;
34        }
35        if (ThreadUtils.runningOnUiThread()) {
36            return context.getSystemService(name);
37        }
38        return ThreadUtils.runOnUiThreadBlockingNoException(new Callable<Object>() {
39          @Override
40          public Object call() {
41            return context.getSystemService(name);
42          }
43        });
44    }
45}

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