blob: d964f79a151dbc574ba66d1f2cd2d7ef65937e97 [file] [log] [blame]
[email protected]dbbec3a2013-06-29 01:45:091// Copyright 2013 The Chromium Authors. All rights reserved.
[email protected]47b896562012-08-22 23:55:152// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]dbbec3a2013-06-29 01:45:095#ifndef CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_H_
6#define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_H_
[email protected]47b896562012-08-22 23:55:157
[email protected]5cb5b182014-03-18 00:32:398#include "base/callback_forward.h"
[email protected]95003d522014-03-13 20:22:319#include "components/keyed_service/core/keyed_service.h"
[email protected]47b896562012-08-22 23:55:1510#include "sync/notifier/invalidation_util.h"
[email protected]e85797c2013-05-10 19:26:1611#include "sync/notifier/invalidator_state.h"
[email protected]47b896562012-08-22 23:55:1512
[email protected]a263ff52014-04-23 19:46:5313class IdentityProvider;
14
[email protected]47b896562012-08-22 23:55:1515namespace syncer {
[email protected]a329cb82012-08-28 03:17:5816class InvalidationHandler;
[email protected]47b896562012-08-22 23:55:1517} // namespace syncer
18
[email protected]e85797c2013-05-10 19:26:1619namespace invalidation {
[email protected]b7600272014-02-11 18:55:5520class InvalidationLogger;
[email protected]e85797c2013-05-10 19:26:1621
[email protected]47b896562012-08-22 23:55:1522// Interface for classes that handle invalidation registrations and send out
23// invalidations to register handlers.
[email protected]08a6f9992012-09-07 19:19:1624//
25// Invalidation clients should follow the pattern below:
26//
27// When starting the client:
28//
29// frontend->RegisterInvalidationHandler(client_handler);
30//
31// When the set of IDs to register changes for the client during its lifetime
32// (i.e., between calls to RegisterInvalidationHandler(client_handler) and
33// UnregisterInvalidationHandler(client_handler):
34//
35// frontend->UpdateRegisteredInvalidationIds(client_handler, client_ids);
36//
[email protected]dbbec3a2013-06-29 01:45:0937// When shutting down the client for browser shutdown:
[email protected]08a6f9992012-09-07 19:19:1638//
39// frontend->UnregisterInvalidationHandler(client_handler);
40//
[email protected]dbbec3a2013-06-29 01:45:0941// Note that there's no call to UpdateRegisteredIds() -- this is because the
42// invalidation API persists registrations across browser restarts.
43//
44// When permanently shutting down the client, e.g. when disabling the related
45// feature:
46//
47// frontend->UpdateRegisteredInvalidationIds(client_handler, ObjectIdSet());
48// frontend->UnregisterInvalidationHandler(client_handler);
49//
[email protected]08a6f9992012-09-07 19:19:1650// If an invalidation handler cares about the invalidator state, it should also
51// do the following when starting the client:
52//
53// invalidator_state = frontend->GetInvalidatorState();
54//
55// It can also do the above in OnInvalidatorStateChange(), or it can use the
56// argument to OnInvalidatorStateChange().
57//
[email protected]dbbec3a2013-06-29 01:45:0958// It is an error to have registered handlers when an
59// InvalidationFrontend is shut down; clients must ensure that they
60// unregister themselves before then. (Depending on the
61// InvalidationFrontend, shutdown may be equivalent to destruction, or
62// a separate function call like Shutdown()).
[email protected]4d432812012-10-05 18:03:1463//
[email protected]08a6f9992012-09-07 19:19:1664// NOTE(akalin): Invalidations that come in during browser shutdown may get
65// dropped. This won't matter once we have an Acknowledge API, though: see
66// http://crbug.com/78462 and http://crbug.com/124149.
[email protected]dbbec3a2013-06-29 01:45:0967//
68// This class inherits from ProfileKeyedService to make it possible to correctly
69// cast from various InvalidationService implementations to ProfileKeyedService
70// in InvalidationServiceFactory.
[email protected]95003d522014-03-13 20:22:3171class InvalidationService : public KeyedService {
[email protected]47b896562012-08-22 23:55:1572 public:
73 // Starts sending notifications to |handler|. |handler| must not be NULL,
74 // and it must not already be registered.
75 //
76 // Handler registrations are persisted across restarts of sync.
77 virtual void RegisterInvalidationHandler(
[email protected]a329cb82012-08-28 03:17:5878 syncer::InvalidationHandler* handler) = 0;
[email protected]47b896562012-08-22 23:55:1579
80 // Updates the set of ObjectIds associated with |handler|. |handler| must
81 // not be NULL, and must already be registered. An ID must be registered for
82 // at most one handler.
83 //
84 // Registered IDs are persisted across restarts of sync.
85 virtual void UpdateRegisteredInvalidationIds(
[email protected]a329cb82012-08-28 03:17:5886 syncer::InvalidationHandler* handler,
[email protected]47b896562012-08-22 23:55:1587 const syncer::ObjectIdSet& ids) = 0;
88
89 // Stops sending notifications to |handler|. |handler| must not be NULL, and
90 // it must already be registered. Note that this doesn't unregister the IDs
91 // associated with |handler|.
92 //
93 // Handler registrations are persisted across restarts of sync.
94 virtual void UnregisterInvalidationHandler(
[email protected]a329cb82012-08-28 03:17:5895 syncer::InvalidationHandler* handler) = 0;
[email protected]47b896562012-08-22 23:55:1596
[email protected]08a6f9992012-09-07 19:19:1697 // Returns the current invalidator state. When called from within
98 // InvalidationHandler::OnInvalidatorStateChange(), this must return
99 // the updated state.
100 virtual syncer::InvalidatorState GetInvalidatorState() const = 0;
101
[email protected]dbbec3a2013-06-29 01:45:09102 // Returns the ID belonging to this invalidation client. Can be used to
103 // prevent the receipt of notifications of our own changes.
104 virtual std::string GetInvalidatorClientId() const = 0;
105
[email protected]b7600272014-02-11 18:55:55106 // Return the logger used to debug invalidations
107 virtual InvalidationLogger* GetInvalidationLogger() = 0;
108
[email protected]5cb5b182014-03-18 00:32:39109 // Triggers requests of internal status.
110 virtual void RequestDetailedStatus(
[email protected]40848a92014-03-24 22:41:02111 base::Callback<void(const base::DictionaryValue&)> post_caller) const = 0;
[email protected]5cb5b182014-03-18 00:32:39112
[email protected]a263ff52014-04-23 19:46:53113 // Returns the identity provider.
114 virtual IdentityProvider* GetIdentityProvider() = 0;
[email protected]dd5e3922014-03-21 17:46:36115
[email protected]47b896562012-08-22 23:55:15116 protected:
[email protected]dbbec3a2013-06-29 01:45:09117 virtual ~InvalidationService() { }
[email protected]47b896562012-08-22 23:55:15118};
119
[email protected]e85797c2013-05-10 19:26:16120} // namespace invalidation
121
[email protected]dbbec3a2013-06-29 01:45:09122#endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_H_