Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 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 | |
| 5 #ifndef BASE_ANDROID_ACTIVITY_STATUS_H_ | |
| 6 #define BASE_ANDROID_ACTIVITY_STATUS_H_ | |
| 7 | |
| 8 #include <jni.h> | |
| 9 | |
| 10 #include "base/android/jni_android.h" | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/callback.h" | |
|
gavinp
2013/04/26 07:37:53
Not needed. Favour "base/callback_forward.h" in he
digit1
2013/04/26 12:32:40
Good point, thanks. Done.
| |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/memory/singleton.h" | |
| 15 #include "base/observer_list_threadsafe.h" | |
| 16 | |
| 17 template <typename T> struct LeakySingletonTraits; | |
| 18 | |
| 19 namespace base { | |
| 20 namespace android { | |
| 21 | |
| 22 enum ActivityState { | |
| 23 #define DEFINE_ACTIVITY_STATE(x,y) ACTIVITY_STATE_ ## x = y, | |
| 24 #include "base/android/activity_state_list.h" | |
| 25 #undef DEFINE_ACTIVITY_STATE | |
| 26 }; | |
| 27 | |
| 28 // A native helper class to listen to activity state changes from | |
| 29 // any thread. Clients should simply sub-class their own StateListener | |
| 30 // which overrides the OnActivityStateChange method. To stop receiving | |
| 31 // events, simply delete the StateListener instance. StateListener objects | |
| 32 // can be created on any thread, and their OnActivityStateChange() method | |
| 33 // will always ne called from the thread that created them. | |
|
gavinp
2013/04/26 07:37:53
nit "always be called"
digit1
2013/04/26 12:32:40
Done.
| |
| 34 // | |
| 35 BASE_EXPORT class ActivityStatus { | |
| 36 public: | |
| 37 class StateListener { | |
| 38 public: | |
| 39 StateListener(); | |
| 40 virtual ~StateListener(); | |
| 41 | |
| 42 virtual void OnActivityStateChange(ActivityState new_state) = 0; | |
| 43 }; | |
| 44 | |
| 45 static ActivityStatus* GetInstance(); | |
| 46 | |
| 47 static bool RegisterBindings(JNIEnv* env); | |
| 48 | |
| 49 // Internal use only: must be public to be called from JNI. | |
| 50 void OnActivityStateChange(ActivityState new_state); | |
| 51 | |
| 52 private: | |
| 53 friend struct DefaultSingletonTraits<ActivityStatus>; | |
| 54 | |
| 55 ActivityStatus(); | |
| 56 ~ActivityStatus(); | |
|
gavinp
2013/04/26 07:37:53
~ActivityStatus() isn't defined anywhere. It's not
digit1
2013/04/26 12:32:40
Ah, I've added an empty body. I guess this won't m
| |
| 57 | |
| 58 void RegisterStateListener(StateListener* state_listener); | |
| 59 void UnregisterStateListener(StateListener* state_listener); | |
| 60 | |
| 61 scoped_refptr<ObserverListThreadSafe<StateListener> > observers_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(ActivityStatus); | |
| 64 }; | |
| 65 | |
| 66 } // namespace android | |
| 67 } // namespace base | |
| 68 | |
| 69 #endif // BASE_ANDROID_ACTIVITY_STATUS_H_ | |
| OLD | NEW |