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