[email protected] | 7315c96 | 2014-05-09 23:17:47 | [diff] [blame] | 1 | // Copyright 2014 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] | 7315c96 | 2014-05-09 23:17:47 | [diff] [blame] | 5 | #ifndef COMPONENTS_INVALIDATION_INVALIDATION_SERVICE_H_ |
| 6 | #define COMPONENTS_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] | 51766bf | 2014-07-24 01:13:47 | [diff] [blame] | 9 | #include "components/invalidation/invalidation_util.h" |
| 10 | #include "components/invalidation/invalidator_state.h" |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 11 | |
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame] | 12 | class IdentityProvider; |
| 13 | |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 14 | namespace syncer { |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 15 | class InvalidationHandler; |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 16 | } // namespace syncer |
| 17 | |
[email protected] | e85797c | 2013-05-10 19:26:16 | [diff] [blame] | 18 | namespace invalidation { |
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 19 | class InvalidationLogger; |
[email protected] | e85797c | 2013-05-10 19:26:16 | [diff] [blame] | 20 | |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 21 | // Interface for classes that handle invalidation registrations and send out |
| 22 | // invalidations to register handlers. |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 23 | // |
| 24 | // Invalidation clients should follow the pattern below: |
| 25 | // |
| 26 | // When starting the client: |
| 27 | // |
| 28 | // frontend->RegisterInvalidationHandler(client_handler); |
| 29 | // |
| 30 | // When the set of IDs to register changes for the client during its lifetime |
| 31 | // (i.e., between calls to RegisterInvalidationHandler(client_handler) and |
| 32 | // UnregisterInvalidationHandler(client_handler): |
| 33 | // |
| 34 | // frontend->UpdateRegisteredInvalidationIds(client_handler, client_ids); |
| 35 | // |
[email protected] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 36 | // When shutting down the client for browser shutdown: |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 37 | // |
| 38 | // frontend->UnregisterInvalidationHandler(client_handler); |
| 39 | // |
[email protected] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 40 | // Note that there's no call to UpdateRegisteredIds() -- this is because the |
| 41 | // invalidation API persists registrations across browser restarts. |
| 42 | // |
| 43 | // When permanently shutting down the client, e.g. when disabling the related |
| 44 | // feature: |
| 45 | // |
| 46 | // frontend->UpdateRegisteredInvalidationIds(client_handler, ObjectIdSet()); |
| 47 | // frontend->UnregisterInvalidationHandler(client_handler); |
| 48 | // |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 49 | // If an invalidation handler cares about the invalidator state, it should also |
| 50 | // do the following when starting the client: |
| 51 | // |
| 52 | // invalidator_state = frontend->GetInvalidatorState(); |
| 53 | // |
| 54 | // It can also do the above in OnInvalidatorStateChange(), or it can use the |
| 55 | // argument to OnInvalidatorStateChange(). |
| 56 | // |
[email protected] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 57 | // It is an error to have registered handlers when an |
| 58 | // InvalidationFrontend is shut down; clients must ensure that they |
| 59 | // unregister themselves before then. (Depending on the |
| 60 | // InvalidationFrontend, shutdown may be equivalent to destruction, or |
| 61 | // a separate function call like Shutdown()). |
[email protected] | 4d43281 | 2012-10-05 18:03:14 | [diff] [blame] | 62 | // |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 63 | // NOTE(akalin): Invalidations that come in during browser shutdown may get |
| 64 | // dropped. This won't matter once we have an Acknowledge API, though: see |
| 65 | // http://crbug.com/78462 and http://crbug.com/124149. |
[email protected] | d03d2e1 | 2014-06-12 16:55:35 | [diff] [blame] | 66 | class InvalidationService { |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 67 | public: |
[email protected] | d03d2e1 | 2014-06-12 16:55:35 | [diff] [blame] | 68 | virtual ~InvalidationService() {} |
| 69 | |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 70 | // Starts sending notifications to |handler|. |handler| must not be NULL, |
| 71 | // and it must not already be registered. |
| 72 | // |
| 73 | // Handler registrations are persisted across restarts of sync. |
| 74 | virtual void RegisterInvalidationHandler( |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 75 | syncer::InvalidationHandler* handler) = 0; |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 76 | |
| 77 | // Updates the set of ObjectIds associated with |handler|. |handler| must |
| 78 | // not be NULL, and must already be registered. An ID must be registered for |
| 79 | // at most one handler. |
| 80 | // |
| 81 | // Registered IDs are persisted across restarts of sync. |
| 82 | virtual void UpdateRegisteredInvalidationIds( |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 83 | syncer::InvalidationHandler* handler, |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 84 | const syncer::ObjectIdSet& ids) = 0; |
| 85 | |
| 86 | // Stops sending notifications to |handler|. |handler| must not be NULL, and |
| 87 | // it must already be registered. Note that this doesn't unregister the IDs |
| 88 | // associated with |handler|. |
| 89 | // |
| 90 | // Handler registrations are persisted across restarts of sync. |
| 91 | virtual void UnregisterInvalidationHandler( |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 92 | syncer::InvalidationHandler* handler) = 0; |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 93 | |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 94 | // Returns the current invalidator state. When called from within |
| 95 | // InvalidationHandler::OnInvalidatorStateChange(), this must return |
| 96 | // the updated state. |
| 97 | virtual syncer::InvalidatorState GetInvalidatorState() const = 0; |
| 98 | |
[email protected] | dbbec3a | 2013-06-29 01:45:09 | [diff] [blame] | 99 | // Returns the ID belonging to this invalidation client. Can be used to |
| 100 | // prevent the receipt of notifications of our own changes. |
| 101 | virtual std::string GetInvalidatorClientId() const = 0; |
| 102 | |
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 103 | // Return the logger used to debug invalidations |
| 104 | virtual InvalidationLogger* GetInvalidationLogger() = 0; |
| 105 | |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 106 | // Triggers requests of internal status. |
| 107 | virtual void RequestDetailedStatus( |
[email protected] | 40848a9 | 2014-03-24 22:41:02 | [diff] [blame] | 108 | base::Callback<void(const base::DictionaryValue&)> post_caller) const = 0; |
[email protected] | 5cb5b18 | 2014-03-18 00:32:39 | [diff] [blame] | 109 | |
[email protected] | a263ff5 | 2014-04-23 19:46:53 | [diff] [blame] | 110 | // Returns the identity provider. |
| 111 | virtual IdentityProvider* GetIdentityProvider() = 0; |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 112 | }; |
| 113 | |
[email protected] | e85797c | 2013-05-10 19:26:16 | [diff] [blame] | 114 | } // namespace invalidation |
| 115 | |
[email protected] | 7315c96 | 2014-05-09 23:17:47 | [diff] [blame] | 116 | #endif // COMPONENTS_INVALIDATION_INVALIDATION_SERVICE_H_ |