Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / invalidation / invalidation_service_android.h
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 CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_
6 #define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_
7
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/threading/non_thread_safe.h"
12 #include "chrome/browser/invalidation/invalidation_service.h"
13 #include "components/browser_context_keyed_service/browser_context_keyed_service.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "sync/notifier/invalidator_registrar.h"
17
18 class Profile;
19
20 namespace invalidation {
21 class InvalidationLogger;
22 class InvalidationControllerAndroid;
23
24 // This InvalidationService is used to deliver invalidations on Android.  The
25 // Android operating system has its own mechanisms for delivering invalidations.
26 // This class uses the NotificationService to communicate with a thin wrapper
27 // around Android's invalidations service.
28 class InvalidationServiceAndroid
29     : public base::NonThreadSafe,
30       public InvalidationService,
31       public content::NotificationObserver {
32  public:
33   // Takes ownership of |invalidation_controller|.
34   InvalidationServiceAndroid(
35       Profile* profile,
36       InvalidationControllerAndroid* invalidation_controller);
37   virtual ~InvalidationServiceAndroid();
38
39   // InvalidationService implementation.
40   //
41   // Note that this implementation does not properly support Ack-tracking,
42   // fetching the invalidator state, or querying the client's ID.  Support for
43   // exposing the client ID should be available soon; see crbug.com/172391.
44   virtual void RegisterInvalidationHandler(
45       syncer::InvalidationHandler* handler) OVERRIDE;
46   virtual void UpdateRegisteredInvalidationIds(
47       syncer::InvalidationHandler* handler,
48       const syncer::ObjectIdSet& ids) OVERRIDE;
49   virtual void UnregisterInvalidationHandler(
50       syncer::InvalidationHandler* handler) OVERRIDE;
51   virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE;
52   virtual std::string GetInvalidatorClientId() const OVERRIDE;
53   virtual InvalidationLogger* GetInvalidationLogger() OVERRIDE;
54
55   // content::NotificationObserver implementation.
56   virtual void Observe(int type,
57                        const content::NotificationSource& source,
58                        const content::NotificationDetails& details) OVERRIDE;
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  private:
65   syncer::InvalidatorRegistrar invalidator_registrar_;
66   content::NotificationRegistrar registrar_;
67   syncer::InvalidatorState invalidator_state_;
68   scoped_ptr<InvalidationControllerAndroid> invalidation_controller_;
69
70   DISALLOW_COPY_AND_ASSIGN(InvalidationServiceAndroid);
71 };
72
73 }  // namespace invalidation
74
75 #endif  // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_