blob: 7a4d67ceb062549cb3733a6c9fb269a265faec77 [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
5#ifndef CHROME_BROWSER_INVALIDATION_INVALIDATION_LOGGER_H_
6#define CHROME_BROWSER_INVALIDATION_INVALIDATION_LOGGER_H_
7
[email protected]9b0d66b2014-02-20 13:16:018#include <map>
[email protected]b7600272014-02-11 18:55:559#include "base/memory/scoped_ptr.h"
10#include "base/observer_list.h"
[email protected]9b0d66b2014-02-20 13:16:0111#include "sync/notifier/invalidation_util.h"
[email protected]b7600272014-02-11 18:55:5512#include "sync/notifier/invalidator_state.h"
13
14namespace base {
15class DictionaryValue;
16} // namespace base
17
18namespace syncer {
[email protected]9b0d66b2014-02-20 13:16:0119class InvalidationHandler;
[email protected]b7600272014-02-11 18:55:5520class ObjectIdInvalidationMap;
[email protected]9b0d66b2014-02-20 13:16:0121} // namespace syncer
[email protected]b7600272014-02-11 18:55:5522
23namespace invalidation {
[email protected]9b0d66b2014-02-20 13:16:0124
[email protected]b7600272014-02-11 18:55:5525class InvalidationLoggerObserver;
26
[email protected]9b0d66b2014-02-20 13:16:0127// 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]b7600272014-02-11 18:55:5539class InvalidationLogger {
[email protected]9b0d66b2014-02-20 13:16:0140
[email protected]b7600272014-02-11 18:55:5541 public:
[email protected]9b0d66b2014-02-20 13:16:0142 InvalidationLogger();
43 ~InvalidationLogger();
44
[email protected]b7600272014-02-11 18:55:5545 // 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]9b0d66b2014-02-20 13:16:0149 void OnStateChange(const syncer::InvalidatorState& new_state);
50 void OnUpdateIds(std::map<std::string, syncer::ObjectIdSet> updated_ids);
[email protected]b7600272014-02-11 18:55:5551 void OnDebugMessage(const base::DictionaryValue& details);
52 void OnInvalidation(const syncer::ObjectIdInvalidationMap& details);
53
[email protected]9b0d66b2014-02-20 13:16:0154 // Triggers messages to be sent to the Observers to provide them with
55 // the current state of the logging.
[email protected]b7600272014-02-11 18:55:5556 void EmitContent();
57
[email protected]9b0d66b2014-02-20 13:16:0158 // 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]b7600272014-02-11 18:55:5562
63 private:
[email protected]9b0d66b2014-02-20 13:16:0164 // Send to every Observer a OnStateChange event with the latest state.
[email protected]b7600272014-02-11 18:55:5565 void EmitState();
[email protected]9b0d66b2014-02-20 13:16:0166
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]b7600272014-02-11 18:55:5571 // The list of every observer currently listening for notifications.
72 ObserverList<InvalidationLoggerObserver> observer_list_;
[email protected]9b0d66b2014-02-20 13:16:0173
[email protected]b7600272014-02-11 18:55:5574 // The last InvalidatorState updated by the InvalidatorService.
75 syncer::InvalidatorState last_invalidator_state_;
[email protected]9b0d66b2014-02-20 13:16:0176
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]b7600272014-02-11 18:55:5582};
83
84} // namespace invalidation
[email protected]9b0d66b2014-02-20 13:16:0185
[email protected]b7600272014-02-11 18:55:5586#endif // CHROME_BROWSER_INVALIDATION_INVALIDATION_LOGGER_H_