OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_ | 5 #ifndef COMPONENTS_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_ |
6 #define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_ | 6 #define COMPONENTS_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_ |
7 | 7 |
| 8 #include <jni.h> |
| 9 #include <map> |
| 10 |
| 11 #include "base/android/jni_android.h" |
| 12 #include "base/android/scoped_java_ref.h" |
8 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
11 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
12 #include "components/invalidation/invalidation_logger.h" | 17 #include "components/invalidation/invalidation_logger.h" |
13 #include "components/invalidation/invalidation_service.h" | 18 #include "components/invalidation/invalidation_service.h" |
14 #include "components/invalidation/invalidator_registrar.h" | 19 #include "components/invalidation/invalidator_registrar.h" |
15 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
16 #include "content/public/browser/notification_observer.h" | |
17 #include "content/public/browser/notification_registrar.h" | |
18 | |
19 class Profile; | |
20 | 21 |
21 namespace invalidation { | 22 namespace invalidation { |
22 class InvalidationControllerAndroid; | 23 |
23 class InvalidationLogger; | 24 class InvalidationLogger; |
24 | 25 |
25 // This InvalidationService is used to deliver invalidations on Android. The | 26 // This InvalidationService is used to deliver invalidations on Android. The |
26 // Android operating system has its own mechanisms for delivering invalidations. | 27 // Android operating system has its own mechanisms for delivering invalidations. |
27 // This class uses the NotificationService to communicate with a thin wrapper | |
28 // around Android's invalidations service. | |
29 class InvalidationServiceAndroid | 28 class InvalidationServiceAndroid |
30 : public base::NonThreadSafe, | 29 : public base::NonThreadSafe, |
31 public InvalidationService, | 30 public InvalidationService { |
32 public content::NotificationObserver { | |
33 public: | 31 public: |
34 // Takes ownership of |invalidation_controller|. | 32 InvalidationServiceAndroid(jobject context); |
35 InvalidationServiceAndroid( | |
36 Profile* profile, | |
37 InvalidationControllerAndroid* invalidation_controller); | |
38 virtual ~InvalidationServiceAndroid(); | 33 virtual ~InvalidationServiceAndroid(); |
39 | 34 |
40 // InvalidationService implementation. | 35 // InvalidationService implementation. |
41 // | 36 // |
42 // Note that this implementation does not properly support Ack-tracking, | 37 // Note that this implementation does not properly support Ack-tracking, |
43 // fetching the invalidator state, or querying the client's ID. Support for | 38 // fetching the invalidator state, or querying the client's ID. Support for |
44 // exposing the client ID should be available soon; see crbug.com/172391. | 39 // exposing the client ID should be available soon; see crbug.com/172391. |
45 virtual void RegisterInvalidationHandler( | 40 virtual void RegisterInvalidationHandler( |
46 syncer::InvalidationHandler* handler) OVERRIDE; | 41 syncer::InvalidationHandler* handler) OVERRIDE; |
47 virtual void UpdateRegisteredInvalidationIds( | 42 virtual void UpdateRegisteredInvalidationIds( |
48 syncer::InvalidationHandler* handler, | 43 syncer::InvalidationHandler* handler, |
49 const syncer::ObjectIdSet& ids) OVERRIDE; | 44 const syncer::ObjectIdSet& ids) OVERRIDE; |
50 virtual void UnregisterInvalidationHandler( | 45 virtual void UnregisterInvalidationHandler( |
51 syncer::InvalidationHandler* handler) OVERRIDE; | 46 syncer::InvalidationHandler* handler) OVERRIDE; |
52 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; | 47 virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE; |
53 virtual std::string GetInvalidatorClientId() const OVERRIDE; | 48 virtual std::string GetInvalidatorClientId() const OVERRIDE; |
54 virtual InvalidationLogger* GetInvalidationLogger() OVERRIDE; | 49 virtual InvalidationLogger* GetInvalidationLogger() OVERRIDE; |
55 virtual void RequestDetailedStatus( | 50 virtual void RequestDetailedStatus( |
56 base::Callback<void(const base::DictionaryValue&)> caller) const | 51 base::Callback<void(const base::DictionaryValue&)> caller) const |
57 OVERRIDE; | 52 OVERRIDE; |
58 virtual IdentityProvider* GetIdentityProvider() OVERRIDE; | 53 virtual IdentityProvider* GetIdentityProvider() OVERRIDE; |
59 | 54 |
60 // content::NotificationObserver implementation. | 55 void RequestSync(JNIEnv* env, |
61 virtual void Observe(int type, | 56 jobject obj, |
62 const content::NotificationSource& source, | 57 jint object_source, |
63 const content::NotificationDetails& details) OVERRIDE; | 58 jstring object_id, |
| 59 jlong version, |
| 60 jstring state); |
| 61 |
| 62 void RequestSyncForAllTypes(JNIEnv* env, jobject obj); |
64 | 63 |
65 // The InvalidationServiceAndroid always reports that it is enabled. | 64 // The InvalidationServiceAndroid always reports that it is enabled. |
66 // This is used only by unit tests. | 65 // This is used only by unit tests. |
67 void TriggerStateChangeForTest(syncer::InvalidatorState state); | 66 void TriggerStateChangeForTest(syncer::InvalidatorState state); |
68 | 67 |
| 68 static bool RegisterJni(JNIEnv* env); |
| 69 |
69 private: | 70 private: |
| 71 typedef std::map<invalidation::ObjectId, |
| 72 int64, |
| 73 syncer::ObjectIdLessThan> ObjectIdVersionMap; |
| 74 |
| 75 // Friend class so that InvalidationServiceFactoryAndroid has access to |
| 76 // private member object java_ref_. |
| 77 friend class InvalidationServiceFactoryAndroid; |
| 78 |
| 79 // Points to a Java instance of InvalidationService. |
| 80 base::android::ScopedJavaGlobalRef<jobject> java_ref_; |
| 81 |
70 syncer::InvalidatorRegistrar invalidator_registrar_; | 82 syncer::InvalidatorRegistrar invalidator_registrar_; |
71 content::NotificationRegistrar registrar_; | |
72 syncer::InvalidatorState invalidator_state_; | 83 syncer::InvalidatorState invalidator_state_; |
73 scoped_ptr<InvalidationControllerAndroid> invalidation_controller_; | 84 |
| 85 // The invalidation API spec allows for the possibility of redundant |
| 86 // invalidations, so keep track of the max versions and drop |
| 87 // invalidations with old versions. |
| 88 ObjectIdVersionMap max_invalidation_versions_; |
74 | 89 |
75 // The invalidation logger object we use to record state changes | 90 // The invalidation logger object we use to record state changes |
76 // and invalidations. | 91 // and invalidations. |
77 InvalidationLogger logger_; | 92 InvalidationLogger logger_; |
78 | 93 |
| 94 void DispatchInvalidations( |
| 95 syncer::ObjectIdInvalidationMap& object_invalidation_map); |
| 96 |
79 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceAndroid); | 97 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceAndroid); |
80 }; | 98 }; |
81 | 99 |
82 } // namespace invalidation | 100 } // namespace invalidation |
83 | 101 |
84 #endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_ | 102 #endif // COMPONENTS_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_ |
OLD | NEW |