OLD | NEW |
| (Empty) |
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 #include "sync/sessions/directory_type_debug_info_emitter.h" | |
6 | |
7 #include <stdint.h> | |
8 | |
9 #include <vector> | |
10 | |
11 #include "sync/internal_api/public/sessions/status_counters.h" | |
12 #include "sync/internal_api/public/sessions/type_debug_info_observer.h" | |
13 #include "sync/syncable/entry.h" | |
14 #include "sync/syncable/syncable_read_transaction.h" | |
15 | |
16 namespace syncer { | |
17 | |
18 DirectoryTypeDebugInfoEmitter::DirectoryTypeDebugInfoEmitter( | |
19 syncable::Directory* directory, | |
20 syncer::ModelType type, | |
21 base::ObserverList<TypeDebugInfoObserver>* observers) | |
22 : directory_(directory), | |
23 type_(type), | |
24 type_debug_info_observers_(observers) { | |
25 } | |
26 | |
27 DirectoryTypeDebugInfoEmitter::DirectoryTypeDebugInfoEmitter( | |
28 ModelType type, | |
29 base::ObserverList<TypeDebugInfoObserver>* observers) | |
30 : directory_(NULL), type_(type), type_debug_info_observers_(observers) { | |
31 } | |
32 | |
33 DirectoryTypeDebugInfoEmitter::~DirectoryTypeDebugInfoEmitter() {} | |
34 | |
35 std::unique_ptr<base::ListValue> DirectoryTypeDebugInfoEmitter::GetAllNodes() { | |
36 syncable::ReadTransaction trans(FROM_HERE, directory_); | |
37 std::unique_ptr<base::ListValue> nodes( | |
38 directory_->GetNodeDetailsForType(&trans, type_)); | |
39 return nodes; | |
40 } | |
41 | |
42 const CommitCounters& DirectoryTypeDebugInfoEmitter::GetCommitCounters() const { | |
43 return commit_counters_; | |
44 } | |
45 | |
46 CommitCounters* DirectoryTypeDebugInfoEmitter::GetMutableCommitCounters() { | |
47 return &commit_counters_; | |
48 } | |
49 | |
50 void DirectoryTypeDebugInfoEmitter::EmitCommitCountersUpdate() { | |
51 FOR_EACH_OBSERVER(TypeDebugInfoObserver, (*type_debug_info_observers_), | |
52 OnCommitCountersUpdated(type_, commit_counters_)); | |
53 } | |
54 | |
55 const UpdateCounters& DirectoryTypeDebugInfoEmitter::GetUpdateCounters() const { | |
56 return update_counters_; | |
57 } | |
58 | |
59 UpdateCounters* DirectoryTypeDebugInfoEmitter::GetMutableUpdateCounters() { | |
60 return &update_counters_; | |
61 } | |
62 | |
63 void DirectoryTypeDebugInfoEmitter::EmitUpdateCountersUpdate() { | |
64 FOR_EACH_OBSERVER(TypeDebugInfoObserver, (*type_debug_info_observers_), | |
65 OnUpdateCountersUpdated(type_, update_counters_)); | |
66 } | |
67 | |
68 void DirectoryTypeDebugInfoEmitter::EmitStatusCountersUpdate() { | |
69 // This is expensive. Avoid running this code unless about:sync is open. | |
70 if (!type_debug_info_observers_->might_have_observers()) | |
71 return; | |
72 | |
73 syncable::ReadTransaction trans(FROM_HERE, directory_); | |
74 std::vector<int64_t> result; | |
75 directory_->GetMetaHandlesOfType(&trans, type_, &result); | |
76 | |
77 StatusCounters counters; | |
78 counters.num_entries_and_tombstones = result.size(); | |
79 | |
80 for (std::vector<int64_t>::const_iterator it = result.begin(); | |
81 it != result.end(); ++it) { | |
82 syncable::Entry e(&trans, syncable::GET_BY_HANDLE, *it); | |
83 if (!e.GetIsDel()) { | |
84 counters.num_entries++; | |
85 } | |
86 } | |
87 | |
88 FOR_EACH_OBSERVER(TypeDebugInfoObserver, (*type_debug_info_observers_), | |
89 OnStatusCountersUpdated(type_, counters)); | |
90 } | |
91 | |
92 } // namespace syncer | |
OLD | NEW |