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