| OLD | NEW |
| (Empty) |
| 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 { | |
| 11 class InvalidationHandler; | |
| 12 } // namespace syncer | |
| 13 | |
| 14 // Interface for classes that handle invalidation registrations and send out | |
| 15 // invalidations to register handlers. | |
| 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 // | |
| 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 // | |
| 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. | |
| 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( | |
| 66 syncer::InvalidationHandler* handler) = 0; | |
| 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( | |
| 74 syncer::InvalidationHandler* handler, | |
| 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( | |
| 83 syncer::InvalidationHandler* handler) = 0; | |
| 84 | |
| 85 // Sends an acknowledgement that an invalidation for |id| was successfully | |
| 86 // handled. | |
| 87 virtual void AcknowledgeInvalidation(const invalidation::ObjectId& id, | |
| 88 const syncer::AckHandle& ack_handle) = 0; | |
| 89 | |
| 90 // Returns the current invalidator state. When called from within | |
| 91 // InvalidationHandler::OnInvalidatorStateChange(), this must return | |
| 92 // the updated state. | |
| 93 virtual syncer::InvalidatorState GetInvalidatorState() const = 0; | |
| 94 | |
| 95 protected: | |
| 96 virtual ~InvalidationFrontend() { } | |
| 97 }; | |
| 98 | |
| 99 #endif // CHROME_BROWSER_SYNC_INVALIDATION_FRONTEND_H_ | |
| OLD | NEW |