[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 1 | // Copyright 2014 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_INVALIDATION_INVALIDATION_LOGGER_H_ | ||||
6 | #define CHROME_BROWSER_INVALIDATION_INVALIDATION_LOGGER_H_ | ||||
7 | |||||
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 8 | #include <map> |
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 9 | #include "base/memory/scoped_ptr.h" |
10 | #include "base/observer_list.h" | ||||
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 11 | #include "sync/notifier/invalidation_util.h" |
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 12 | #include "sync/notifier/invalidator_state.h" |
13 | |||||
14 | namespace base { | ||||
15 | class DictionaryValue; | ||||
16 | } // namespace base | ||||
17 | |||||
18 | namespace syncer { | ||||
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 19 | class InvalidationHandler; |
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 20 | class ObjectIdInvalidationMap; |
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 21 | } // namespace syncer |
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 22 | |
23 | namespace invalidation { | ||||
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 24 | |
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 25 | class InvalidationLoggerObserver; |
26 | |||||
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 27 | // This class is in charge of logging invalidation-related information. |
28 | // It is used store the state of the InvalidatorService that owns this object | ||||
29 | // and then rebroadcast it to observers than can display it accordingly | ||||
30 | // (like a debugging page). This class only stores lightweight state, as in | ||||
31 | // which services are registered and listening for certain objects, and the | ||||
32 | // status of the InvalidatorService (in order not to increase unnecesary | ||||
33 | // memory usage). | ||||
34 | // | ||||
35 | // Observers can be registered and will be called to be notified of any | ||||
36 | // status change immediatly. They can log there the history of what messages | ||||
37 | // they recieve. | ||||
38 | |||||
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 39 | class InvalidationLogger { |
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 40 | |
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 41 | public: |
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 42 | InvalidationLogger(); |
43 | ~InvalidationLogger(); | ||||
44 | |||||
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 45 | // Pass through to any registered InvalidationLoggerObservers. |
46 | // We will do local logging here too. | ||||
47 | void OnRegistration(const base::DictionaryValue& details); | ||||
48 | void OnUnregistration(const base::DictionaryValue& details); | ||||
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 49 | void OnStateChange(const syncer::InvalidatorState& new_state); |
50 | void OnUpdateIds(std::map<std::string, syncer::ObjectIdSet> updated_ids); | ||||
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 51 | void OnDebugMessage(const base::DictionaryValue& details); |
52 | void OnInvalidation(const syncer::ObjectIdInvalidationMap& details); | ||||
53 | |||||
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 54 | // Triggers messages to be sent to the Observers to provide them with |
55 | // the current state of the logging. | ||||
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 56 | void EmitContent(); |
57 | |||||
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 58 | // Add and remove observers listening for messages. |
59 | void RegisterObserver(InvalidationLoggerObserver* debug_observer); | ||||
60 | void UnregisterObserver(InvalidationLoggerObserver* debug_observer); | ||||
61 | bool IsObserverRegistered(InvalidationLoggerObserver* debug_observer); | ||||
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 62 | |
63 | private: | ||||
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 64 | // Send to every Observer a OnStateChange event with the latest state. |
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 65 | void EmitState(); |
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 66 | |
67 | // Send to every Observer many OnUpdateIds events, each with one registrar | ||||
68 | // and every objectId it currently has registered. | ||||
69 | void EmitUpdatedIds(); | ||||
70 | |||||
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 71 | // The list of every observer currently listening for notifications. |
72 | ObserverList<InvalidationLoggerObserver> observer_list_; | ||||
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 73 | |
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 74 | // The last InvalidatorState updated by the InvalidatorService. |
75 | syncer::InvalidatorState last_invalidator_state_; | ||||
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 76 | |
77 | // The map that contains every object id that is currently registered | ||||
78 | // and its owner. | ||||
79 | std::map<std::string, syncer::ObjectIdSet> latest_ids_; | ||||
80 | |||||
81 | DISALLOW_COPY_AND_ASSIGN(InvalidationLogger); | ||||
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 82 | }; |
83 | |||||
84 | } // namespace invalidation | ||||
[email protected] | 9b0d66b | 2014-02-20 13:16:01 | [diff] [blame^] | 85 | |
[email protected] | b760027 | 2014-02-11 18:55:55 | [diff] [blame] | 86 | #endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_LOGGER_H_ |