[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 1 | // Copyright (c) 2012 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_SYNC_INVALIDATION_FRONTEND_H_ |
| 6 | #define CHROME_BROWSER_SYNC_INVALIDATION_FRONTEND_H_ |
| 7 | |
| 8 | #include "sync/notifier/invalidation_util.h" |
| 9 | |
| 10 | namespace syncer { |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 11 | class InvalidationHandler; |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 12 | } // namespace syncer |
| 13 | |
| 14 | // Interface for classes that handle invalidation registrations and send out |
| 15 | // invalidations to register handlers. |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 16 | // |
| 17 | // Invalidation clients should follow the pattern below: |
| 18 | // |
| 19 | // When starting the client: |
| 20 | // |
| 21 | // frontend->RegisterInvalidationHandler(client_handler); |
| 22 | // |
| 23 | // When the set of IDs to register changes for the client during its lifetime |
| 24 | // (i.e., between calls to RegisterInvalidationHandler(client_handler) and |
| 25 | // UnregisterInvalidationHandler(client_handler): |
| 26 | // |
| 27 | // frontend->UpdateRegisteredInvalidationIds(client_handler, client_ids); |
| 28 | // |
| 29 | // When shutting down the client for browser shutdown: |
| 30 | // |
| 31 | // frontend->UnregisterInvalidationHandler(client_handler); |
| 32 | // |
| 33 | // Note that there's no call to UpdateRegisteredIds() -- this is because the |
| 34 | // invalidation API persists registrations across browser restarts. |
| 35 | // |
| 36 | // When permanently shutting down the client, e.g. when disabling the related |
| 37 | // feature: |
| 38 | // |
| 39 | // frontend->UpdateRegisteredInvalidationIds(client_handler, ObjectIdSet()); |
| 40 | // frontend->UnregisterInvalidationHandler(client_handler); |
| 41 | // |
| 42 | // If an invalidation handler cares about the invalidator state, it should also |
| 43 | // do the following when starting the client: |
| 44 | // |
| 45 | // invalidator_state = frontend->GetInvalidatorState(); |
| 46 | // |
| 47 | // It can also do the above in OnInvalidatorStateChange(), or it can use the |
| 48 | // argument to OnInvalidatorStateChange(). |
| 49 | // |
[email protected] | 4d43281 | 2012-10-05 18:03:14 | [diff] [blame^] | 50 | // It is an error to have registered handlers when an |
| 51 | // InvalidationFrontend is shut down; clients must ensure that they |
| 52 | // unregister themselves before then. (Depending on the |
| 53 | // InvalidationFrontend, shutdown may be equivalent to destruction, or |
| 54 | // a separate function call like Shutdown()). |
| 55 | // |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 56 | // NOTE(akalin): Invalidations that come in during browser shutdown may get |
| 57 | // dropped. This won't matter once we have an Acknowledge API, though: see |
| 58 | // http://crbug.com/78462 and http://crbug.com/124149. |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 59 | class InvalidationFrontend { |
| 60 | public: |
| 61 | // Starts sending notifications to |handler|. |handler| must not be NULL, |
| 62 | // and it must not already be registered. |
| 63 | // |
| 64 | // Handler registrations are persisted across restarts of sync. |
| 65 | virtual void RegisterInvalidationHandler( |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 66 | syncer::InvalidationHandler* handler) = 0; |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 67 | |
| 68 | // Updates the set of ObjectIds associated with |handler|. |handler| must |
| 69 | // not be NULL, and must already be registered. An ID must be registered for |
| 70 | // at most one handler. |
| 71 | // |
| 72 | // Registered IDs are persisted across restarts of sync. |
| 73 | virtual void UpdateRegisteredInvalidationIds( |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 74 | syncer::InvalidationHandler* handler, |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 75 | const syncer::ObjectIdSet& ids) = 0; |
| 76 | |
| 77 | // Stops sending notifications to |handler|. |handler| must not be NULL, and |
| 78 | // it must already be registered. Note that this doesn't unregister the IDs |
| 79 | // associated with |handler|. |
| 80 | // |
| 81 | // Handler registrations are persisted across restarts of sync. |
| 82 | virtual void UnregisterInvalidationHandler( |
[email protected] | a329cb8 | 2012-08-28 03:17:58 | [diff] [blame] | 83 | syncer::InvalidationHandler* handler) = 0; |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 84 | |
[email protected] | 08a6f999 | 2012-09-07 19:19:16 | [diff] [blame] | 85 | // Returns the current invalidator state. When called from within |
| 86 | // InvalidationHandler::OnInvalidatorStateChange(), this must return |
| 87 | // the updated state. |
| 88 | virtual syncer::InvalidatorState GetInvalidatorState() const = 0; |
| 89 | |
[email protected] | 47b89656 | 2012-08-22 23:55:15 | [diff] [blame] | 90 | protected: |
| 91 | virtual ~InvalidationFrontend() { } |
| 92 | }; |
| 93 | |
| 94 | #endif // CHROME_BROWSER_SYNC_INVALIDATION_FRONTEND_H_ |