Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 | |
| 5 package org.chromium.content.browser; | |
| 6 | |
| 7 import android.content.BroadcastReceiver; | |
| 8 import android.content.Context; | |
| 9 import android.content.Intent; | |
| 10 import android.content.IntentFilter; | |
| 11 import android.util.Log; | |
| 12 | |
| 13 import org.chromium.base.CalledByNative; | |
| 14 import org.chromium.base.JNINamespace; | |
| 15 | |
| 16 /** | |
| 17 * Android implementation details for content::TimeZoneMonitorAndroid. | |
| 18 */ | |
| 19 @JNINamespace("content") | |
| 20 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:
| |
| 21 private static final String TAG = "TimeZoneMonitor"; | |
| 22 | |
| 23 private final Context mAppContext; | |
| 24 private final IntentFilter mFilter = new IntentFilter(Intent.ACTION_TIMEZONE _CHANGED); | |
| 25 | |
| 26 private long mNativePtr; | |
| 27 | |
| 28 protected TimeZoneMonitor(Context context) { | |
|
bulach
2014/04/29 08:33:44
nit: private?
| |
| 29 mAppContext = context.getApplicationContext(); | |
| 30 } | |
| 31 | |
| 32 @CalledByNative | |
| 33 static TimeZoneMonitor getInstance(Context appContext) { | |
|
bulach
2014/04/29 08:33:44
nit: as above, perhaps fold this with start to avo
| |
| 34 return new TimeZoneMonitor(appContext); | |
| 35 } | |
| 36 | |
| 37 /** | |
| 38 * Start listening for intents. | |
| 39 * @param nativePtr The native content::TimeZoneMonitorAndroid to notify of time zone changes. | |
| 40 */ | |
| 41 @CalledByNative | |
| 42 void start(long nativePtr) { | |
| 43 mNativePtr = nativePtr; | |
| 44 mAppContext.registerReceiver(this, mFilter); | |
| 45 } | |
| 46 | |
| 47 /** | |
| 48 * Stop listening for intents. | |
| 49 */ | |
| 50 @CalledByNative | |
| 51 void stop() { | |
| 52 mAppContext.unregisterReceiver(this); | |
| 53 mNativePtr = 0; | |
| 54 } | |
| 55 | |
| 56 @Override | |
| 57 public void onReceive(Context context, Intent intent) { | |
| 58 if (!intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED)) { | |
| 59 Log.e(TAG, "unexpected intent"); | |
| 60 return; | |
| 61 } | |
| 62 | |
| 63 nativeTimeZoneChangedFromJava(mNativePtr); | |
| 64 } | |
| 65 | |
| 66 /** | |
| 67 * Native JNI call to content::TimeZoneMonitorAndroid::TimeZoneChanged. | |
| 68 * See content/browser/time_zone_monitor_android.cc. | |
| 69 */ | |
| 70 private native void nativeTimeZoneChangedFromJava(long nativeTimeZoneMonitor Android); | |
| 71 } | |
| OLD | NEW |