Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/TimeZoneMonitor.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/TimeZoneMonitor.java b/content/public/android/java/src/org/chromium/content/browser/TimeZoneMonitor.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..63d752012765a810725d517a6bb71e60def06b0b |
| --- /dev/null |
| +++ b/content/public/android/java/src/org/chromium/content/browser/TimeZoneMonitor.java |
| @@ -0,0 +1,71 @@ |
| +// Copyright 2014 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.content.browser; |
| + |
| +import android.content.BroadcastReceiver; |
| +import android.content.Context; |
| +import android.content.Intent; |
| +import android.content.IntentFilter; |
| +import android.util.Log; |
| + |
| +import org.chromium.base.CalledByNative; |
| +import org.chromium.base.JNINamespace; |
| + |
| +/** |
| + * Android implementation details for content::TimeZoneMonitorAndroid. |
| + */ |
| +@JNINamespace("content") |
| +class TimeZoneMonitor extends BroadcastReceiver { |
|
bulach
2014/04/29 08:33:44
nit: it's a bit more common to use an anonymous in
Mark Mentovai
2014/04/29 16:01:05
bulach wrote:
|
| + private static final String TAG = "TimeZoneMonitor"; |
| + |
| + private final Context mAppContext; |
| + private final IntentFilter mFilter = new IntentFilter(Intent.ACTION_TIMEZONE_CHANGED); |
| + |
| + private long mNativePtr; |
| + |
| + protected TimeZoneMonitor(Context context) { |
|
bulach
2014/04/29 08:33:44
nit: private?
|
| + mAppContext = context.getApplicationContext(); |
| + } |
| + |
| + @CalledByNative |
| + static TimeZoneMonitor getInstance(Context appContext) { |
|
bulach
2014/04/29 08:33:44
nit: as above, perhaps fold this with start to avo
|
| + return new TimeZoneMonitor(appContext); |
| + } |
| + |
| + /** |
| + * Start listening for intents. |
| + * @param nativePtr The native content::TimeZoneMonitorAndroid to notify of time zone changes. |
| + */ |
| + @CalledByNative |
| + void start(long nativePtr) { |
| + mNativePtr = nativePtr; |
| + mAppContext.registerReceiver(this, mFilter); |
| + } |
| + |
| + /** |
| + * Stop listening for intents. |
| + */ |
| + @CalledByNative |
| + void stop() { |
| + mAppContext.unregisterReceiver(this); |
| + mNativePtr = 0; |
| + } |
| + |
| + @Override |
| + public void onReceive(Context context, Intent intent) { |
| + if (!intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) { |
| + Log.e(TAG, "unexpected intent"); |
| + return; |
| + } |
| + |
| + nativeTimeZoneChangedFromJava(mNativePtr); |
| + } |
| + |
| + /** |
| + * Native JNI call to content::TimeZoneMonitorAndroid::TimeZoneChanged. |
| + * See content/browser/time_zone_monitor_android.cc. |
| + */ |
| + private native void nativeTimeZoneChangedFromJava(long nativeTimeZoneMonitorAndroid); |
| +} |