1a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// found in the LICENSE file.
4a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
5a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#ifndef CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_
6a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_
7a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
8a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/basictypes.h"
9a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/compiler_specific.h"
1058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
11a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/threading/non_thread_safe.h"
120de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)#include "components/invalidation/invalidation_logger.h"
130de6073388f4e2780db8536178b129cd8f6ab386Torne (Richard Coles)#include "components/invalidation/invalidation_service.h"
1446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "components/invalidation/invalidator_registrar.h"
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "components/keyed_service/core/keyed_service.h"
16a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "content/public/browser/notification_observer.h"
17a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "content/public/browser/notification_registrar.h"
18a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
19a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class Profile;
20a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
21a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace invalidation {
2258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class InvalidationControllerAndroid;
2323730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)class InvalidationLogger;
2458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
25a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// This InvalidationService is used to deliver invalidations on Android.  The
26a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Android operating system has its own mechanisms for delivering invalidations.
27a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// This class uses the NotificationService to communicate with a thin wrapper
28a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// around Android's invalidations service.
29a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class InvalidationServiceAndroid
30a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    : public base::NonThreadSafe,
31eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch      public InvalidationService,
32a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      public content::NotificationObserver {
33a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) public:
3458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // Takes ownership of |invalidation_controller|.
3558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  InvalidationServiceAndroid(
3658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      Profile* profile,
3758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)      InvalidationControllerAndroid* invalidation_controller);
38a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual ~InvalidationServiceAndroid();
39a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
40a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // InvalidationService implementation.
41a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  //
42a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Note that this implementation does not properly support Ack-tracking,
43a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // fetching the invalidator state, or querying the client's ID.  Support for
44a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // exposing the client ID should be available soon; see crbug.com/172391.
45a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void RegisterInvalidationHandler(
46a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      syncer::InvalidationHandler* handler) OVERRIDE;
47a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void UpdateRegisteredInvalidationIds(
48a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      syncer::InvalidationHandler* handler,
49a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      const syncer::ObjectIdSet& ids) OVERRIDE;
50a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void UnregisterInvalidationHandler(
51a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      syncer::InvalidationHandler* handler) OVERRIDE;
52a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual syncer::InvalidatorState GetInvalidatorState() const OVERRIDE;
53eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual std::string GetInvalidatorClientId() const OVERRIDE;
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual InvalidationLogger* GetInvalidationLogger() OVERRIDE;
55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void RequestDetailedStatus(
56effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      base::Callback<void(const base::DictionaryValue&)> caller) const
57effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      OVERRIDE;
580529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  virtual IdentityProvider* GetIdentityProvider() OVERRIDE;
59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // content::NotificationObserver implementation.
61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void Observe(int type,
62a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                       const content::NotificationSource& source,
63a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                       const content::NotificationDetails& details) OVERRIDE;
64a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // The InvalidationServiceAndroid always reports that it is enabled.
66a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // This is used only by unit tests.
67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  void TriggerStateChangeForTest(syncer::InvalidatorState state);
68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
69a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) private:
70a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  syncer::InvalidatorRegistrar invalidator_registrar_;
71a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  content::NotificationRegistrar registrar_;
72a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  syncer::InvalidatorState invalidator_state_;
7358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  scoped_ptr<InvalidationControllerAndroid> invalidation_controller_;
74a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
75a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // The invalidation logger object we use to record state changes
76a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // and invalidations.
77a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  InvalidationLogger logger_;
78a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
79a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(InvalidationServiceAndroid);
80a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)};
81a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
82a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}  // namespace invalidation
83a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
84a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#endif  // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_ANDROID_H_
85