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 CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_ |
6 #define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_ | 6 #define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_ |
7 | 7 |
| 8 #include <vector> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" |
9 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
10 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
11 #include "chrome/browser/invalidation/invalidation_service.h" | 14 #include "chrome/browser/invalidation/invalidation_service.h" |
12 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" | 15 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
13 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
14 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
15 #include "sync/notifier/invalidator_registrar.h" | 18 #include "sync/notifier/invalidator_registrar.h" |
16 | 19 |
| 20 #if defined(OS_ANDROID) |
| 21 #include "base/android/jni_android.h" |
| 22 #include "base/android/jni_helper.h" |
| 23 #endif // defined(OS_ANDROID) |
| 24 |
17 class Profile; | 25 class Profile; |
18 | 26 |
19 namespace invalidation { | 27 namespace invalidation { |
20 | 28 |
21 // This InvalidationService is used to deliver invalidations on Android. The | 29 // This InvalidationService is used to deliver invalidations on Android. The |
22 // Android operating system has its own mechanisms for delivering invalidations. | 30 // Android operating system has its own mechanisms for delivering invalidations. |
23 // This class uses the NotificationService to communicate with a thin wrapper | 31 // This class uses the NotificationService to communicate with a thin wrapper |
24 // around Android's invalidations service. | 32 // around Android's invalidations service. |
25 class InvalidationServiceAndroid | 33 class InvalidationServiceAndroid |
26 : public base::NonThreadSafe, | 34 : public base::NonThreadSafe, |
(...skipping 23 matching lines...) Expand all Loading... |
50 | 58 |
51 // content::NotificationObserver implementation. | 59 // content::NotificationObserver implementation. |
52 virtual void Observe(int type, | 60 virtual void Observe(int type, |
53 const content::NotificationSource& source, | 61 const content::NotificationSource& source, |
54 const content::NotificationDetails& details) OVERRIDE; | 62 const content::NotificationDetails& details) OVERRIDE; |
55 | 63 |
56 // The InvalidationServiceAndroid always reports that it is enabled. | 64 // The InvalidationServiceAndroid always reports that it is enabled. |
57 // This is used only by unit tests. | 65 // This is used only by unit tests. |
58 void TriggerStateChangeForTest(syncer::InvalidatorState state); | 66 void TriggerStateChangeForTest(syncer::InvalidatorState state); |
59 | 67 |
| 68 // Replace the callback invoked when the Android invalidation controller |
| 69 // registration is updated. |
| 70 // The first parameter of the callback is the list of object sources, and the |
| 71 // second parameter is the parallel list of object names. |
| 72 // Used only for unit tests. |
| 73 typedef base::Callback< |
| 74 void(const std::vector<int>&, const std::vector<std::string>&)> |
| 75 UpdateRegistrationCallback; |
| 76 void SetUpdateRegistrationCallbackForTest( |
| 77 const UpdateRegistrationCallback& callback); |
| 78 |
60 private: | 79 private: |
| 80 // Update object registration with the Android invalidation controller. |
| 81 void UpdateRegistration(); |
| 82 |
| 83 // Determine if any object in a set needs to be registered with the Android |
| 84 // invalidation controller. |
| 85 bool IsRegistrationRequired(const syncer::ObjectIdSet& ids); |
| 86 |
| 87 // Determine if an object with the given id needs to be registered with the |
| 88 // Android invalidation controller. |
| 89 bool IsRegistrationRequired(const invalidation::ObjectId& id); |
| 90 |
61 syncer::InvalidatorRegistrar invalidator_registrar_; | 91 syncer::InvalidatorRegistrar invalidator_registrar_; |
62 content::NotificationRegistrar registrar_; | 92 content::NotificationRegistrar registrar_; |
63 syncer::InvalidatorState invalidator_state_; | 93 syncer::InvalidatorState invalidator_state_; |
64 | 94 |
| 95 #if defined(OS_ANDROID) |
| 96 // The Android invalidation controller. |
| 97 base::android::ScopedJavaGlobalRef<jobject> invalidation_controller_; |
| 98 #endif // defined(OS_ANDROID) |
| 99 |
| 100 // The callback to invoke in unit tests when updating the object registration. |
| 101 UpdateRegistrationCallback update_registration_callback_; |
| 102 |
65 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceAndroid); | 103 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceAndroid); |
66 }; | 104 }; |
67 | 105 |
| 106 #if defined(OS_ANDROID) |
| 107 bool RegisterInvalidationController(JNIEnv* env); |
| 108 #endif // defined(OS_ANDROID) |
| 109 |
68 } // namespace invalidation | 110 } // namespace invalidation |
69 | 111 |
70 #endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_ | 112 #endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_ |
OLD | NEW |