Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / sync / sessions / directory_type_debug_info_emitter.h
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 SYNC_SESSIONS_DIRECTORY_TYPE_DEBUG_INFO_EMITTER_H_
6 #define SYNC_SESSIONS_DIRECTORY_TYPE_DEBUG_INFO_EMITTER_H_
7
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"
16
17 namespace syncer {
18
19 class DirectoryCommitContributor;
20 class TypeDebugInfoObserver;
21
22 // Supports various kinds of debugging requests for a certain directory type.
23 //
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
26 // lives elsewhere.
27 //
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.
31 //
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 {
37  public:
38   // Standard constructor for non-tests.
39   //
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
42   // object.
43   DirectoryTypeDebugInfoEmitter(
44       syncable::Directory* directory,
45       syncer::ModelType type,
46       ObserverList<TypeDebugInfoObserver>* observers);
47
48   // A simple constructor for tests.  Should not be used in real code.
49   DirectoryTypeDebugInfoEmitter();
50
51   virtual ~DirectoryTypeDebugInfoEmitter();
52
53   // Returns a ListValue representation of all known nodes of this type.
54   scoped_ptr<base::ListValue> GetAllNodes();
55
56   // Returns a reference to the current commit counters.
57   const CommitCounters& GetCommitCounters() const;
58
59   // Allows others to mutate the commit counters.
60   CommitCounters* GetMutableCommitCounters();
61
62   // Triggerss a commit counters update to registered observers.
63   void EmitCommitCountersUpdate();
64
65   // Returns a reference to the current update counters.
66   const UpdateCounters& GetUpdateCounters() const;
67
68   // Allows others to mutate the update counters.
69   UpdateCounters* GetMutableUpdateCounters();
70
71   // Triggers an update counters update to registered observers.
72   void EmitUpdateCountersUpdate();
73
74   // Triggers a status counters update to registered observers.
75   void EmitStatusCountersUpdate();
76
77  private:
78   syncable::Directory* directory_;
79
80   const ModelType type_;
81
82   CommitCounters commit_counters_;
83   UpdateCounters update_counters_;
84
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_;
90
91   DISALLOW_COPY_AND_ASSIGN(DirectoryTypeDebugInfoEmitter);
92 };
93
94 }  // namespace syncer
95
96 #endif  // SYNC_SESSIONS_DIRECTORY_TYPE_DEBUG_INFO_EMITTER_H_