Add tests to verify accelerators properly work on constrained window.
[chromium-blink-merge.git] / sync / notifier / invalidator_registrar.h
blobce227dbdd8a979962b72ab086f2a81b803189bf6
1 // Copyright 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.
5 #ifndef SYNC_NOTIFIER_INVALIDATOR_REGISTRAR_H_
6 #define SYNC_NOTIFIER_INVALIDATOR_REGISTRAR_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/observer_list.h"
12 #include "base/threading/thread_checker.h"
13 #include "sync/base/sync_export.h"
14 #include "sync/notifier/invalidation_handler.h"
15 #include "sync/notifier/invalidation_util.h"
16 #include "sync/notifier/object_id_invalidation_map.h"
18 namespace invalidation {
19 class ObjectId;
20 } // namespace invalidation
22 namespace syncer {
24 // A helper class for implementations of the Invalidator interface. It helps
25 // keep track of registered handlers and which object ID registrations are
26 // associated with which handlers, so implementors can just reuse the logic
27 // here to dispatch invalidations and other interesting notifications.
28 class SYNC_EXPORT InvalidatorRegistrar {
29 public:
30 InvalidatorRegistrar();
32 // It is an error to have registered handlers on destruction.
33 ~InvalidatorRegistrar();
35 // Starts sending notifications to |handler|. |handler| must not be NULL,
36 // and it must already be registered.
37 void RegisterHandler(InvalidationHandler* handler);
39 // Updates the set of ObjectIds associated with |handler|. |handler| must
40 // not be NULL, and must already be registered. An ID must be registered for
41 // at most one handler.
42 void UpdateRegisteredIds(InvalidationHandler* handler,
43 const ObjectIdSet& ids);
45 // Stops sending notifications to |handler|. |handler| must not be NULL, and
46 // it must already be registered. Note that this doesn't unregister the IDs
47 // associated with |handler|.
48 void UnregisterHandler(InvalidationHandler* handler);
50 ObjectIdSet GetRegisteredIds(InvalidationHandler* handler) const;
52 // Returns the set of all IDs that are registered to some handler (even
53 // handlers that have been unregistered).
54 ObjectIdSet GetAllRegisteredIds() const;
56 // Sorts incoming invalidations into a bucket for each handler and then
57 // dispatches the batched invalidations to the corresponding handler.
58 // Invalidations for IDs with no corresponding handler are dropped, as are
59 // invalidations for handlers that are not added.
60 void DispatchInvalidationsToHandlers(
61 const ObjectIdInvalidationMap& invalidation_map,
62 IncomingInvalidationSource source);
64 // Updates the invalidator state to the given one and then notifies
65 // all handlers. Note that the order is important; handlers that
66 // call GetInvalidatorState() when notified will see the new state.
67 void UpdateInvalidatorState(InvalidatorState state);
69 // Returns the current invalidator state. When called from within
70 // InvalidationHandler::OnInvalidatorStateChange(), this returns the
71 // updated state.
72 InvalidatorState GetInvalidatorState() const;
74 bool IsHandlerRegisteredForTest(InvalidationHandler* handler) const;
76 // Needed for death tests.
77 void DetachFromThreadForTest();
79 private:
80 typedef std::map<invalidation::ObjectId, InvalidationHandler*,
81 ObjectIdLessThan>
82 IdHandlerMap;
84 InvalidationHandler* ObjectIdToHandler(const invalidation::ObjectId& id);
86 base::ThreadChecker thread_checker_;
87 ObserverList<InvalidationHandler> handlers_;
88 IdHandlerMap id_to_handler_map_;
89 InvalidatorState state_;
91 DISALLOW_COPY_AND_ASSIGN(InvalidatorRegistrar);
94 } // namespace syncer
96 #endif // SYNC_NOTIFIER_INVALIDATOR_REGISTRAR_H_