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_IMPL_INVALIDATION_SERVICE_ANDROID_H_
6 #define COMPONENTS_INVALIDATION_IMPL_INVALIDATION_SERVICE_ANDROID_H_
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/impl/invalidation_logger.h"
18 #include "components/invalidation/impl/invalidator_registrar.h"
19 #include "components/invalidation/public/invalidation_service.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
{
32 explicit 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 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
;
53 void Invalidate(JNIEnv
* env
,
60 // The InvalidationServiceAndroid always reports that it is enabled.
61 // This is used only by unit tests.
62 void TriggerStateChangeForTest(syncer::InvalidatorState state
);
64 static bool RegisterJni(JNIEnv
* env
);
67 typedef std::map
<invalidation::ObjectId
,
69 syncer::ObjectIdLessThan
> ObjectIdVersionMap
;
71 // Friend class so that InvalidationServiceFactoryAndroid has access to
72 // private member object java_ref_.
73 friend class InvalidationServiceFactoryAndroid
;
75 // Points to a Java instance of InvalidationService.
76 base::android::ScopedJavaGlobalRef
<jobject
> java_ref_
;
78 syncer::InvalidatorRegistrar invalidator_registrar_
;
79 syncer::InvalidatorState invalidator_state_
;
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_
;
86 // The invalidation logger object we use to record state changes
88 InvalidationLogger logger_
;
90 DISALLOW_COPY_AND_ASSIGN(InvalidationServiceAndroid
);
93 } // namespace invalidation
95 #endif // COMPONENTS_INVALIDATION_IMPL_INVALIDATION_SERVICE_ANDROID_H_