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.
5 #ifndef SYNC_SESSIONS_DIRECTORY_TYPE_DEBUG_INFO_EMITTER_H_
6 #define SYNC_SESSIONS_DIRECTORY_TYPE_DEBUG_INFO_EMITTER_H_
8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/observer_list.h"
11 #include "base/values.h"
12 #include "sync/base/sync_export.h"
13 #include "sync/internal_api/public/sessions/commit_counters.h"
14 #include "sync/internal_api/public/sessions/update_counters.h"
15 #include "sync/syncable/directory.h"
19 class DirectoryCommitContributor;
20 class TypeDebugInfoObserver;
22 // Supports various kinds of debugging requests for a certain directory type.
24 // The GetAllNodes() function is used to help export a snapshot of all current
25 // nodes to its caller. The complexity required to manage the request mostly
28 // The Emit*() functions send updates to registered TypeDebugInfoObservers.
29 // The DirectoryTypeDebugInfoEmitter does not directly own that list; it is
30 // managed by the ModelTypeRegistry.
32 // For Update and Commit counters, the job of keeping the counters up to date
33 // is delegated to the UpdateHandler and CommitContributors. For the Stats
34 // counters, the emitter will use its type_ and directory_ members to fetch all
35 // the required information on demand.
36 class SYNC_EXPORT_PRIVATE DirectoryTypeDebugInfoEmitter {
38 // Standard constructor for non-tests.
40 // The |directory| and |observers| arguments are not owned. Both may be
41 // modified outside of this object and both are expected to outlive this
43 DirectoryTypeDebugInfoEmitter(
44 syncable::Directory* directory,
45 syncer::ModelType type,
46 ObserverList<TypeDebugInfoObserver>* observers);
48 // A simple constructor for tests. Should not be used in real code.
49 DirectoryTypeDebugInfoEmitter();
51 virtual ~DirectoryTypeDebugInfoEmitter();
53 // Returns a ListValue representation of all known nodes of this type.
54 scoped_ptr<base::ListValue> GetAllNodes();
56 // Returns a reference to the current commit counters.
57 const CommitCounters& GetCommitCounters() const;
59 // Allows others to mutate the commit counters.
60 CommitCounters* GetMutableCommitCounters();
62 // Triggerss a commit counters update to registered observers.
63 void EmitCommitCountersUpdate();
65 // Returns a reference to the current update counters.
66 const UpdateCounters& GetUpdateCounters() const;
68 // Allows others to mutate the update counters.
69 UpdateCounters* GetMutableUpdateCounters();
71 // Triggers an update counters update to registered observers.
72 void EmitUpdateCountersUpdate();
74 // Triggers a status counters update to registered observers.
75 void EmitStatusCountersUpdate();
78 syncable::Directory* directory_;
80 const ModelType type_;
82 CommitCounters commit_counters_;
83 UpdateCounters update_counters_;
85 // Because there are so many emitters that come into and out of existence, it
86 // doesn't make sense to have them manage their own observer list. They all
87 // share one observer list that is provided by their owner and which is
88 // guaranteed to outlive them.
89 ObserverList<TypeDebugInfoObserver>* type_debug_info_observers_;
91 DISALLOW_COPY_AND_ASSIGN(DirectoryTypeDebugInfoEmitter);
96 #endif // SYNC_SESSIONS_DIRECTORY_TYPE_DEBUG_INFO_EMITTER_H_