File: invalidation_logger.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (101 lines) | stat: -rw-r--r-- 3,671 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_INVALIDATION_IMPL_INVALIDATION_LOGGER_H_
#define COMPONENTS_INVALIDATION_IMPL_INVALIDATION_LOGGER_H_

#include <map>
#include <set>

#include "base/macros.h"
#include "base/observer_list.h"
#include "components/invalidation/public/invalidation_util.h"
#include "components/invalidation/public/invalidator_state.h"

namespace base {
class DictionaryValue;
}  // namespace base

namespace syncer {
class ObjectIdInvalidationMap;
}  // namespace syncer

namespace invalidation {

class InvalidationLoggerObserver;

// This class is in charge of logging invalidation-related information.
// It is used store the state of the InvalidatorService that owns this object
// and then rebroadcast it to observers than can display it accordingly
// (like a debugging page). This class only stores lightweight state, as in
// which services are registered and listening for certain objects, and the
// status of the InvalidatorService (in order not to increase unnecesary
// memory usage).
//
// Observers can be registered and will be called to be notified of any
// status change immediatly. They can log there the history of what messages
// they receive.

class InvalidationLogger {

 public:
  InvalidationLogger();
  ~InvalidationLogger();

  // Pass through to any registered InvalidationLoggerObservers.
  // We will do local logging here too.
  void OnRegistration(const std::string& details);
  void OnUnregistration(const std::string& details);
  void OnStateChange(const syncer::InvalidatorState& new_state);
  void OnUpdateIds(std::map<std::string, syncer::ObjectIdSet> updated_ids);
  void OnDebugMessage(const base::DictionaryValue& details);
  void OnInvalidation(const syncer::ObjectIdInvalidationMap& details);

  // Triggers messages to be sent to the Observers to provide them with
  // the current state of the logging.
  void EmitContent();

  // Add and remove observers listening for messages.
  void RegisterObserver(InvalidationLoggerObserver* debug_observer);
  void UnregisterObserver(InvalidationLoggerObserver* debug_observer);
  bool IsObserverRegistered(
      const InvalidationLoggerObserver* debug_observer) const;

 private:
  // Send to every Observer a OnStateChange event with the latest state.
  void EmitState();

  // Send to every Observer many OnUpdateIds events, each with one registrar
  // and every objectId it currently has registered.
  void EmitUpdatedIds();

  // Send to every Observer a vector with the all the current registered
  // handlers.
  void EmitRegisteredHandlers();

  // The list of every observer currently listening for notifications.
  base::ObserverList<InvalidationLoggerObserver> observer_list_;

  // The last InvalidatorState updated by the InvalidatorService.
  syncer::InvalidatorState last_invalidator_state_;
  base::Time last_invalidator_state_timestamp_;

  // The map that contains every object id that is currently registered
  // and its owner.
  std::map<std::string, syncer::ObjectIdSet> latest_ids_;

  // The map that counts how many invalidations per objectId there has been.
  syncer::ObjectIdCountMap invalidation_count_;

  // The name of all invalidatorHandler registered (note that this is not
  // necessarily the same as the keys of latest_ids_, because they might
  // have not registered any object id).
  std::multiset<std::string> registered_handlers_;

  DISALLOW_COPY_AND_ASSIGN(InvalidationLogger);
};

}  // namespace invalidation

#endif  // COMPONENTS_INVALIDATION_IMPL_INVALIDATION_LOGGER_H_