blob: 6f19b73c0dbd48937b52e018e2d98fdbaa91790c [file] [log] [blame]
[email protected]47b896562012-08-22 23:55:151// 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
10namespace syncer {
[email protected]a329cb82012-08-28 03:17:5811class InvalidationHandler;
[email protected]47b896562012-08-22 23:55:1512} // namespace syncer
13
14// Interface for classes that handle invalidation registrations and send out
15// invalidations to register handlers.
[email protected]08a6f9992012-09-07 19:19:1616//
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]4d432812012-10-05 18:03:1450// 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]08a6f9992012-09-07 19:19:1656// 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]47b896562012-08-22 23:55:1559class 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]a329cb82012-08-28 03:17:5866 syncer::InvalidationHandler* handler) = 0;
[email protected]47b896562012-08-22 23:55:1567
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]a329cb82012-08-28 03:17:5874 syncer::InvalidationHandler* handler,
[email protected]47b896562012-08-22 23:55:1575 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]a329cb82012-08-28 03:17:5883 syncer::InvalidationHandler* handler) = 0;
[email protected]47b896562012-08-22 23:55:1584
[email protected]08a6f9992012-09-07 19:19:1685 // 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]47b896562012-08-22 23:55:1590 protected:
91 virtual ~InvalidationFrontend() { }
92};
93
94#endif // CHROME_BROWSER_SYNC_INVALIDATION_FRONTEND_H_