[email protected] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_H_ |
| 6 | #define CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_H_ |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 7 | |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 8 | #include "base/callback_forward.h" |
[email protected] | 95003d52 | 2014-03-13 20:22:31 | [diff] [blame] | 9 | #include "components/keyed_service/core/keyed_service.h" |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 10 | #include "sync/notifier/invalidation_util.h" |
[email protected] | e85797c | 2013-05-10 19:26:16 | [diff] [blame] | 11 | #include "sync/notifier/invalidator_state.h" |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 12 | |
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame^] | 13 | class IdentityProvider; |
| 14 | |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 15 | namespace syncer { |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 16 | class InvalidationHandler; |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 17 | } // namespace syncer |
| 18 | |
[email protected] | e85797c | 2013-05-10 19:26:16 | [diff] [blame] | 19 | namespace invalidation { |
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 20 | class InvalidationLogger; |
[email protected] | e85797c | 2013-05-10 19:26:16 | [diff] [blame] | 21 | |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 22 | // Interface for classes that handle invalidation registrations and send out |
| 23 | // invalidations to register handlers. |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 24 | // |
| 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] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 37 | // When shutting down the client for browser shutdown: |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 38 | // |
| 39 | // frontend->UnregisterInvalidationHandler(client_handler); |
| 40 | // |
[email protected] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 41 | // 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] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 50 | // 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] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 58 | // 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] | 4d43281 | 2012-10-05 18:03:14 | [diff] [blame] | 63 | // |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 64 | // 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] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 67 | // |
| 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] | 95003d52 | 2014-03-13 20:22:31 | [diff] [blame] | 71 | class InvalidationService : public KeyedService { |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 72 | 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] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 78 | syncer::InvalidationHandler* handler) = 0; |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 79 | |
| 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] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 86 | syncer::InvalidationHandler* handler, |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 87 | 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] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 95 | syncer::InvalidationHandler* handler) = 0; |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 96 | |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 97 | // 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] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 102 | // 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] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 106 | // Return the logger used to debug invalidations |
| 107 | virtual InvalidationLogger* GetInvalidationLogger() = 0; |
| 108 | |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 109 | // Triggers requests of internal status. |
| 110 | virtual void RequestDetailedStatus( |
[email protected] | 40848a9 | 2014-03-24 22:41:02 | [diff] [blame] | 111 | base::Callback<void(const base::DictionaryValue&)> post_caller) const = 0; |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 112 | |
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame^] | 113 | // Returns the identity provider. |
| 114 | virtual IdentityProvider* GetIdentityProvider() = 0; |
[email protected] | dd5e392 | 2014-03-21 17:46:36 | [diff] [blame] | 115 | |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 116 | protected: |
[email protected] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 117 | virtual ~InvalidationService() { } |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 118 | }; |
| 119 | |
[email protected] | e85797c | 2013-05-10 19:26:16 | [diff] [blame] | 120 | } // namespace invalidation |
| 121 | |
[email protected] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 122 | #endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_SERVICE_H_ |