| OLD | NEW |
| (Empty) |
| 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 COMPONENTS_INVALIDATION_INVALIDATION_LOGGER_H_ | |
| 6 #define COMPONENTS_INVALIDATION_INVALIDATION_LOGGER_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/observer_list.h" | |
| 13 #include "components/invalidation/invalidation_util.h" | |
| 14 #include "components/invalidation/invalidator_state.h" | |
| 15 | |
| 16 namespace base { | |
| 17 class DictionaryValue; | |
| 18 } // namespace base | |
| 19 | |
| 20 namespace syncer { | |
| 21 class InvalidationHandler; | |
| 22 class ObjectIdInvalidationMap; | |
| 23 } // namespace syncer | |
| 24 | |
| 25 namespace invalidation { | |
| 26 | |
| 27 class InvalidationLoggerObserver; | |
| 28 | |
| 29 // This class is in charge of logging invalidation-related information. | |
| 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 receive. | |
| 40 | |
| 41 class InvalidationLogger { | |
| 42 | |
| 43 public: | |
| 44 InvalidationLogger(); | |
| 45 ~InvalidationLogger(); | |
| 46 | |
| 47 // Pass through to any registered InvalidationLoggerObservers. | |
| 48 // We will do local logging here too. | |
| 49 void OnRegistration(const std::string& details); | |
| 50 void OnUnregistration(const std::string& details); | |
| 51 void OnStateChange(const syncer::InvalidatorState& new_state); | |
| 52 void OnUpdateIds(std::map<std::string, syncer::ObjectIdSet> updated_ids); | |
| 53 void OnDebugMessage(const base::DictionaryValue& details); | |
| 54 void OnInvalidation(const syncer::ObjectIdInvalidationMap& details); | |
| 55 | |
| 56 // Triggers messages to be sent to the Observers to provide them with | |
| 57 // the current state of the logging. | |
| 58 void EmitContent(); | |
| 59 | |
| 60 // Add and remove observers listening for messages. | |
| 61 void RegisterObserver(InvalidationLoggerObserver* debug_observer); | |
| 62 void UnregisterObserver(InvalidationLoggerObserver* debug_observer); | |
| 63 bool IsObserverRegistered( | |
| 64 const InvalidationLoggerObserver* debug_observer) const; | |
| 65 | |
| 66 private: | |
| 67 // Send to every Observer a OnStateChange event with the latest state. | |
| 68 void EmitState(); | |
| 69 | |
| 70 // Send to every Observer many OnUpdateIds events, each with one registrar | |
| 71 // and every objectId it currently has registered. | |
| 72 void EmitUpdatedIds(); | |
| 73 | |
| 74 // Send to every Observer a vector with the all the current registered | |
| 75 // handlers. | |
| 76 void EmitRegisteredHandlers(); | |
| 77 | |
| 78 // The list of every observer currently listening for notifications. | |
| 79 base::ObserverList<InvalidationLoggerObserver> observer_list_; | |
| 80 | |
| 81 // The last InvalidatorState updated by the InvalidatorService. | |
| 82 syncer::InvalidatorState last_invalidator_state_; | |
| 83 base::Time last_invalidator_state_timestamp_; | |
| 84 | |
| 85 // The map that contains every object id that is currently registered | |
| 86 // and its owner. | |
| 87 std::map<std::string, syncer::ObjectIdSet> latest_ids_; | |
| 88 | |
| 89 // The map that counts how many invalidations per objectId there has been. | |
| 90 syncer::ObjectIdCountMap invalidation_count_; | |
| 91 | |
| 92 // The name of all invalidatorHandler registered (note that this is not | |
| 93 // necessarily the same as the keys of latest_ids_, because they might | |
| 94 // have not registered any object id). | |
| 95 std::multiset<std::string> registered_handlers_; | |
| 96 | |
| 97 DISALLOW_COPY_AND_ASSIGN(InvalidationLogger); | |
| 98 }; | |
| 99 | |
| 100 } // namespace invalidation | |
| 101 | |
| 102 #endif // COMPONENTS_INVALIDATION_INVALIDATION_LOGGER_H_ | |
| OLD | NEW |