OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Interface to the sync notifier, which is an object that receives | 5 // Interface to the invalidator, which is an object that receives |
6 // notifications when updates are available for a set of sync types. | 6 // invalidations for registered object IDs. The corresponding |
7 // All the observers are notified when such an event happens. | 7 // InvalidationHandler is notifier when such an event occurs. |
8 | 8 |
9 #ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_H_ | 9 #ifndef SYNC_NOTIFIER_INVALIDATOR_H_ |
10 #define SYNC_NOTIFIER_SYNC_NOTIFIER_H_ | 10 #define SYNC_NOTIFIER_INVALIDATOR_H_ |
11 | 11 |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "sync/internal_api/public/base/model_type.h" | 14 #include "sync/internal_api/public/base/model_type.h" |
15 #include "sync/notifier/invalidation_util.h" | 15 #include "sync/notifier/invalidation_util.h" |
16 | 16 |
17 namespace syncer { | 17 namespace syncer { |
18 class SyncNotifierObserver; | 18 class InvalidationHandler; |
19 | 19 |
20 class SyncNotifier { | 20 class Invalidator { |
21 public: | 21 public: |
22 SyncNotifier() {} | 22 Invalidator() {} |
23 virtual ~SyncNotifier() {} | 23 virtual ~Invalidator() {} |
24 | 24 |
25 // Clients should follow the pattern below: | 25 // Clients should follow the pattern below: |
26 // | 26 // |
27 // When starting the client: | 27 // When starting the client: |
28 // | 28 // |
29 // notifier->RegisterHandler(client_handler); | 29 // invalidator->RegisterHandler(client_handler); |
30 // | 30 // |
31 // When the set of IDs to register changes for the client during its lifetime | 31 // When the set of IDs to register changes for the client during its lifetime |
32 // (i.e., between calls to RegisterHandler(client_handler) and | 32 // (i.e., between calls to RegisterHandler(client_handler) and |
33 // UnregisterHandler(client_handler): | 33 // UnregisterHandler(client_handler): |
34 // | 34 // |
35 // notifier->UpdateRegisteredIds(client_handler, client_ids); | 35 // invalidator->UpdateRegisteredIds(client_handler, client_ids); |
36 // | 36 // |
37 // When shutting down the client for browser shutdown: | 37 // When shutting down the client for profile shutdown: |
38 // | 38 // |
39 // notifier->UnregisterHandler(client_handler); | 39 // invalidator->UnregisterHandler(client_handler); |
40 // | 40 // |
41 // Note that there's no call to UpdateRegisteredIds() -- this is because the | 41 // Note that there's no call to UpdateRegisteredIds() -- this is because the |
42 // invalidation API persists registrations across browser restarts. | 42 // invalidation API persists registrations across browser restarts. |
43 // | 43 // |
44 // When permanently shutting down the client, e.g. when disabling the related | 44 // When permanently shutting down the client, e.g. when disabling the related |
45 // feature: | 45 // feature: |
46 // | 46 // |
47 // notifier->UpdateRegisteredIds(client_handler, ObjectIdSet()); | 47 // invalidator->UpdateRegisteredIds(client_handler, ObjectIdSet()); |
48 // notifier->UnregisterHandler(client_handler); | 48 // invalidator->UnregisterHandler(client_handler); |
49 | 49 |
50 // Starts sending notifications to |handler|. |handler| must not be NULL, | 50 // Starts sending notifications to |handler|. |handler| must not be NULL, |
51 // and it must already be registered. | 51 // and it must already be registered. |
52 virtual void RegisterHandler(SyncNotifierObserver* handler) = 0; | 52 virtual void RegisterHandler(InvalidationHandler* handler) = 0; |
53 | 53 |
54 // Updates the set of ObjectIds associated with |handler|. |handler| must | 54 // Updates the set of ObjectIds associated with |handler|. |handler| must |
55 // not be NULL, and must already be registered. An ID must be registered for | 55 // not be NULL, and must already be registered. An ID must be registered for |
56 // at most one handler. | 56 // at most one handler. |
57 virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, | 57 virtual void UpdateRegisteredIds(InvalidationHandler* handler, |
58 const ObjectIdSet& ids) = 0; | 58 const ObjectIdSet& ids) = 0; |
59 | 59 |
60 // Stops sending notifications to |handler|. |handler| must not be NULL, and | 60 // Stops sending notifications to |handler|. |handler| must not be NULL, and |
61 // it must already be registered. Note that this doesn't unregister the IDs | 61 // it must already be registered. Note that this doesn't unregister the IDs |
62 // associated with |handler|. | 62 // associated with |handler|. |
63 virtual void UnregisterHandler(SyncNotifierObserver* handler) = 0; | 63 virtual void UnregisterHandler(InvalidationHandler* handler) = 0; |
64 | 64 |
65 // SetUniqueId must be called once, before any call to | 65 // SetUniqueId must be called once, before any call to |
66 // UpdateCredentials. |unique_id| should be a non-empty globally | 66 // UpdateCredentials. |unique_id| should be a non-empty globally |
67 // unique string. | 67 // unique string. |
68 virtual void SetUniqueId(const std::string& unique_id) = 0; | 68 virtual void SetUniqueId(const std::string& unique_id) = 0; |
69 | 69 |
70 // SetState must be called once, before any call to | 70 // SetState must be called once, before any call to |
71 // UpdateCredentials. |state| may be empty. | 71 // UpdateCredentials. |state| may be empty. |
72 // Deprecated in favour of InvalidationStateTracker persistence. | 72 // Deprecated in favour of InvalidationStateTracker persistence. |
73 virtual void SetStateDeprecated(const std::string& state) = 0; | 73 virtual void SetStateDeprecated(const std::string& state) = 0; |
74 | 74 |
75 // The observers won't be notified of any notifications until | 75 // The observers won't be notified of any notifications until |
76 // UpdateCredentials is called at least once. It can be called more than | 76 // UpdateCredentials is called at least once. It can be called more than |
77 // once. | 77 // once. |
78 virtual void UpdateCredentials( | 78 virtual void UpdateCredentials( |
79 const std::string& email, const std::string& token) = 0; | 79 const std::string& email, const std::string& token) = 0; |
80 | 80 |
81 // This is here only to support the old p2p notification implementation, | 81 // This is here only to support the old p2p notification implementation, |
82 // which is still used by sync integration tests. | 82 // which is still used by sync integration tests. |
83 // TODO(akalin): Remove this once we move the integration tests off p2p | 83 // TODO(akalin): Remove this once we move the integration tests off p2p |
84 // notifications. | 84 // notifications. |
85 virtual void SendNotification(ModelTypeSet changed_types) = 0; | 85 virtual void SendNotification(ModelTypeSet changed_types) = 0; |
86 }; | 86 }; |
87 } // namespace syncer | 87 } // namespace syncer |
88 | 88 |
89 #endif // SYNC_NOTIFIER_SYNC_NOTIFIER_H_ | 89 #endif // SYNC_NOTIFIER_INVALIDATOR_H_ |
OLD | NEW |