blob: e19ff07da7309d8049a8d67944dbc2b99400b3c1 [file] [log] [blame]
[email protected]b7600272014-02-11 18:55:551// 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
[email protected]7315c962014-05-09 23:17:475#ifndef COMPONENTS_INVALIDATION_INVALIDATION_LOGGER_H_
6#define COMPONENTS_INVALIDATION_INVALIDATION_LOGGER_H_
[email protected]b7600272014-02-11 18:55:557
[email protected]9b0d66b2014-02-20 13:16:018#include <map>
[email protected]063cbbb32014-02-27 01:46:209#include <set>
10
[email protected]b7600272014-02-11 18:55:5511#include "base/memory/scoped_ptr.h"
12#include "base/observer_list.h"
[email protected]51766bf2014-07-24 01:13:4713#include "components/invalidation/invalidation_util.h"
14#include "components/invalidation/invalidator_state.h"
[email protected]b7600272014-02-11 18:55:5515
16namespace base {
17class DictionaryValue;
18} // namespace base
19
20namespace syncer {
[email protected]9b0d66b2014-02-20 13:16:0121class InvalidationHandler;
[email protected]b7600272014-02-11 18:55:5522class ObjectIdInvalidationMap;
[email protected]9b0d66b2014-02-20 13:16:0123} // namespace syncer
[email protected]b7600272014-02-11 18:55:5524
25namespace invalidation {
[email protected]9b0d66b2014-02-20 13:16:0126
[email protected]b7600272014-02-11 18:55:5527class InvalidationLoggerObserver;
28
[email protected]9b0d66b2014-02-20 13:16:0129// 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
[email protected]dd2cd942014-05-06 00:58:0739// they receive.
[email protected]9b0d66b2014-02-20 13:16:0140
[email protected]b7600272014-02-11 18:55:5541class InvalidationLogger {
[email protected]9b0d66b2014-02-20 13:16:0142
[email protected]b7600272014-02-11 18:55:5543 public:
[email protected]9b0d66b2014-02-20 13:16:0144 InvalidationLogger();
45 ~InvalidationLogger();
46
[email protected]b7600272014-02-11 18:55:5547 // Pass through to any registered InvalidationLoggerObservers.
48 // We will do local logging here too.
[email protected]063cbbb32014-02-27 01:46:2049 void OnRegistration(const std::string& details);
50 void OnUnregistration(const std::string& details);
[email protected]9b0d66b2014-02-20 13:16:0151 void OnStateChange(const syncer::InvalidatorState& new_state);
52 void OnUpdateIds(std::map<std::string, syncer::ObjectIdSet> updated_ids);
[email protected]b7600272014-02-11 18:55:5553 void OnDebugMessage(const base::DictionaryValue& details);
54 void OnInvalidation(const syncer::ObjectIdInvalidationMap& details);
55
[email protected]9b0d66b2014-02-20 13:16:0156 // Triggers messages to be sent to the Observers to provide them with
57 // the current state of the logging.
[email protected]b7600272014-02-11 18:55:5558 void EmitContent();
59
[email protected]9b0d66b2014-02-20 13:16:0160 // Add and remove observers listening for messages.
61 void RegisterObserver(InvalidationLoggerObserver* debug_observer);
62 void UnregisterObserver(InvalidationLoggerObserver* debug_observer);
mgiuca64ccf2362014-11-10 06:44:2363 bool IsObserverRegistered(
64 const InvalidationLoggerObserver* debug_observer) const;
[email protected]b7600272014-02-11 18:55:5565
66 private:
[email protected]9b0d66b2014-02-20 13:16:0167 // Send to every Observer a OnStateChange event with the latest state.
[email protected]b7600272014-02-11 18:55:5568 void EmitState();
[email protected]9b0d66b2014-02-20 13:16:0169
70 // Send to every Observer many OnUpdateIds events, each with one registrar
71 // and every objectId it currently has registered.
72 void EmitUpdatedIds();
73
[email protected]063cbbb32014-02-27 01:46:2074 // Send to every Observer a vector with the all the current registered
[email protected]5cb5b182014-03-18 00:32:3975 // handlers.
[email protected]063cbbb32014-02-27 01:46:2076 void EmitRegisteredHandlers();
77
[email protected]b7600272014-02-11 18:55:5578 // The list of every observer currently listening for notifications.
79 ObserverList<InvalidationLoggerObserver> observer_list_;
[email protected]9b0d66b2014-02-20 13:16:0180
[email protected]b7600272014-02-11 18:55:5581 // The last InvalidatorState updated by the InvalidatorService.
82 syncer::InvalidatorState last_invalidator_state_;
[email protected]46109c52014-04-08 22:58:3483 base::Time last_invalidator_state_timestamp_;
[email protected]9b0d66b2014-02-20 13:16:0184
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
[email protected]9364154f2014-03-31 17:39:2489 // The map that counts how many invalidations per objectId there has been.
90 syncer::ObjectIdCountMap invalidation_count_;
91
[email protected]063cbbb32014-02-27 01:46:2092 // The name of all invalidatorHandler registered (note that this is not
93 // necessarily the same as the keys of latest_ids_, because they might
[email protected]5cb5b182014-03-18 00:32:3994 // have not registered any object id).
[email protected]063cbbb32014-02-27 01:46:2095 std::multiset<std::string> registered_handlers_;
96
[email protected]9b0d66b2014-02-20 13:16:0197 DISALLOW_COPY_AND_ASSIGN(InvalidationLogger);
[email protected]b7600272014-02-11 18:55:5598};
99
100} // namespace invalidation
[email protected]9b0d66b2014-02-20 13:16:01101
[email protected]7315c962014-05-09 23:17:47102#endif // COMPONENTS_INVALIDATION_INVALIDATION_LOGGER_H_