[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / components / invalidation / invalidation_service_android.h
blobc8e0a5125d6dbdfa5d76e902e91fd2ef7190d0be
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.
5 #ifndef COMPONENTS_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_
6 #define COMPONENTS_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_
8 #include <jni.h>
9 #include <map>
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"
22 namespace invalidation {
24 class InvalidationLogger;
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 InvalidationServiceAndroid(jobject context);
33 ~InvalidationServiceAndroid() override;
35 // InvalidationService implementation.
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 void 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;
53 void RequestSync(JNIEnv* env,
54 jobject obj,
55 jint object_source,
56 jstring object_id,
57 jlong version,
58 jstring state);
60 void RequestSyncForAllTypes(JNIEnv* env, jobject obj);
62 // The InvalidationServiceAndroid always reports that it is enabled.
63 // This is used only by unit tests.
64 void TriggerStateChangeForTest(syncer::InvalidatorState state);
66 static bool RegisterJni(JNIEnv* env);
68 private:
69 typedef std::map<invalidation::ObjectId,
70 int64,
71 syncer::ObjectIdLessThan> ObjectIdVersionMap;
73 // Friend class so that InvalidationServiceFactoryAndroid has access to
74 // private member object java_ref_.
75 friend class InvalidationServiceFactoryAndroid;
77 // Points to a Java instance of InvalidationService.
78 base::android::ScopedJavaGlobalRef<jobject> java_ref_;
80 syncer::InvalidatorRegistrar invalidator_registrar_;
81 syncer::InvalidatorState invalidator_state_;
83 // The invalidation API spec allows for the possibility of redundant
84 // invalidations, so keep track of the max versions and drop
85 // invalidations with old versions.
86 ObjectIdVersionMap max_invalidation_versions_;
88 // The invalidation logger object we use to record state changes
89 // and invalidations.
90 InvalidationLogger logger_;
92 void DispatchInvalidations(
93 syncer::ObjectIdInvalidationMap& object_invalidation_map);
95 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceAndroid);
98 } // namespace invalidation
100 #endif // COMPONENTS_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_