Use component installer mechanism instead of extensions for supervised user whitelists.
[chromium-blink-merge.git] / components / invalidation / invalidation_service_android.h
blob4a9e77aa749a63382233078029f62293db7ec39b
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 virtual ~InvalidationServiceAndroid();
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 virtual void RegisterInvalidationHandler(
41 syncer::InvalidationHandler* handler) override;
42 virtual void UpdateRegisteredInvalidationIds(
43 syncer::InvalidationHandler* handler,
44 const syncer::ObjectIdSet& ids) override;
45 virtual void UnregisterInvalidationHandler(
46 syncer::InvalidationHandler* handler) override;
47 virtual syncer::InvalidatorState GetInvalidatorState() const override;
48 virtual std::string GetInvalidatorClientId() const override;
49 virtual InvalidationLogger* GetInvalidationLogger() override;
50 virtual void RequestDetailedStatus(
51 base::Callback<void(const base::DictionaryValue&)> caller) const
52 override;
53 virtual IdentityProvider* GetIdentityProvider() override;
55 void RequestSync(JNIEnv* env,
56 jobject obj,
57 jint object_source,
58 jstring object_id,
59 jlong version,
60 jstring state);
62 void RequestSyncForAllTypes(JNIEnv* env, jobject obj);
64 // The InvalidationServiceAndroid always reports that it is enabled.
65 // This is used only by unit tests.
66 void TriggerStateChangeForTest(syncer::InvalidatorState state);
68 static bool RegisterJni(JNIEnv* env);
70 private:
71 typedef std::map<invalidation::ObjectId,
72 int64,
73 syncer::ObjectIdLessThan> ObjectIdVersionMap;
75 // Friend class so that InvalidationServiceFactoryAndroid has access to
76 // private member object java_ref_.
77 friend class InvalidationServiceFactoryAndroid;
79 // Points to a Java instance of InvalidationService.
80 base::android::ScopedJavaGlobalRef<jobject> java_ref_;
82 syncer::InvalidatorRegistrar invalidator_registrar_;
83 syncer::InvalidatorState invalidator_state_;
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_;
90 // The invalidation logger object we use to record state changes
91 // and invalidations.
92 InvalidationLogger logger_;
94 void DispatchInvalidations(
95 syncer::ObjectIdInvalidationMap& object_invalidation_map);
97 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceAndroid);
100 } // namespace invalidation
102 #endif // COMPONENTS_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_