Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/datausage/ExternalDataUseObserverAndroid.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/datausage/ExternalDataUseObserverAndroid.java b/chrome/android/java/src/org/chromium/chrome/browser/datausage/ExternalDataUseObserverAndroid.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..379abbf00b3cff0f1cfdfcbd8598284a1dba089b |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/datausage/ExternalDataUseObserverAndroid.java |
| @@ -0,0 +1,51 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.datausage; |
| + |
| +import android.content.Context; |
| + |
| +import org.chromium.base.annotations.CalledByNative; |
| +import org.chromium.base.annotations.JNINamespace; |
| +import org.chromium.chrome.browser.ChromeApplication; |
| +import org.chromium.chrome.browser.util.NonThreadSafe; |
| + |
| +/** |
| + * This class provides a base class implementation of a data use observer that is external to |
| + * Chromium. This class is not thread safe. |
|
newt (away)
2015/10/12 18:01:18
Based on the commit message, this class will only
tbansal1
2015/10/12 22:39:13
It is easier if we keep it on IO thread since the
|
| + */ |
| +@JNINamespace("chrome::android") |
| +public class ExternalDataUseObserverAndroid { |
| + private static final Object LOCK = new Object(); |
| + private static NonThreadSafe sThreadCheck = null; |
|
newt (away)
2015/10/12 18:01:18
Most classes in Chrome aren't thread safe, and we
tbansal1
2015/10/12 22:39:13
Removed.
|
| + private static ExternalDataUseObserverAndroid sExternalDataUseObserverAndroid; |
|
newt (away)
2015/10/12 18:01:18
Avoid statics, especially if they contain non-triv
tbansal1
2015/10/12 22:39:14
Removed.
|
| + |
| + @CalledByNative |
| + private static ExternalDataUseObserverAndroid create(Context context, long nativePtr) { |
| + synchronized (LOCK) { |
| + if (sExternalDataUseObserverAndroid == null) { |
| + assert sThreadCheck == null; |
| + assert sExternalDataUseObserverAndroid == null; |
| + sThreadCheck = new NonThreadSafe(); |
| + |
| + sExternalDataUseObserverAndroid = |
| + ((ChromeApplication) context) |
| + .createExternalDataUseObserverAndroid(nativePtr); |
| + } |
| + } |
| + return sExternalDataUseObserverAndroid; |
| + } |
| + |
| + @CalledByNative |
| + private void onDataUse(String tag, long bytesDownloaded, long bytesUploaded) { |
| + assert sThreadCheck.calledOnValidThread(); |
| + } |
| + |
| + /** |
| + * Creates an instance of |@link #sExternalDataUseObserverAndroid}. |
| + */ |
| + public ExternalDataUseObserverAndroid() { |
|
newt (away)
2015/10/12 18:01:18
looks like this should be protected
tbansal1
2015/10/12 22:39:13
It complains because ChromeApplication is unable t
|
| + assert sThreadCheck.calledOnValidThread(); |
| + } |
| +} |