sync: Populate entity counts in about:sync tab

Populates the count of entities per type in about:sync.

Includes C++ code to count and emit the set of deleted and non-deleted
counts, though for space reasons only the non-deleted count is displayed
on the about:sync page.

This calculation is somewhat expensive.  It could be made cheaper by
having an index in the Directory to keep track of which entities belong
to which type, but that doesn't exist at the moment.  For now, we just
avoid calculating these counts unless the about:sync page is open.

BUG=349301

Review URL: https://codereview.chromium.org/302283007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274563 0039d316-1c4b-4281-b951-d872f2087c98
parent 972c5657
...@@ -158,6 +158,7 @@ void DirectoryCommitContribution::CleanUp() { ...@@ -158,6 +158,7 @@ void DirectoryCommitContribution::CleanUp() {
DCHECK(syncing_bits_set_); DCHECK(syncing_bits_set_);
UnsetSyncingBits(); UnsetSyncingBits();
debug_info_emitter_->EmitCommitCountersUpdate(); debug_info_emitter_->EmitCommitCountersUpdate();
debug_info_emitter_->EmitStatusCountersUpdate();
} }
size_t DirectoryCommitContribution::GetNumEntries() const { size_t DirectoryCommitContribution::GetNumEntries() const {
......
...@@ -90,6 +90,7 @@ void DirectoryUpdateHandler::ApplyUpdates(sessions::StatusController* status) { ...@@ -90,6 +90,7 @@ void DirectoryUpdateHandler::ApplyUpdates(sessions::StatusController* status) {
worker_->DoWorkAndWaitUntilDone(c); worker_->DoWorkAndWaitUntilDone(c);
debug_info_emitter_->EmitUpdateCountersUpdate(); debug_info_emitter_->EmitUpdateCountersUpdate();
debug_info_emitter_->EmitStatusCountersUpdate();
} }
void DirectoryUpdateHandler::PassiveApplyUpdates( void DirectoryUpdateHandler::PassiveApplyUpdates(
...@@ -102,6 +103,7 @@ void DirectoryUpdateHandler::PassiveApplyUpdates( ...@@ -102,6 +103,7 @@ void DirectoryUpdateHandler::PassiveApplyUpdates(
ApplyUpdatesImpl(status); ApplyUpdatesImpl(status);
debug_info_emitter_->EmitUpdateCountersUpdate(); debug_info_emitter_->EmitUpdateCountersUpdate();
debug_info_emitter_->EmitStatusCountersUpdate();
} }
SyncerError DirectoryUpdateHandler::ApplyUpdatesImpl( SyncerError DirectoryUpdateHandler::ApplyUpdatesImpl(
......
...@@ -10,13 +10,15 @@ ...@@ -10,13 +10,15 @@
namespace syncer { namespace syncer {
StatusCounters::StatusCounters() StatusCounters::StatusCounters()
: num_entries(0) {} : num_entries(0),
num_entries_and_tombstones(0) {}
StatusCounters::~StatusCounters() {} StatusCounters::~StatusCounters() {}
scoped_ptr<base::DictionaryValue> StatusCounters::ToValue() const { scoped_ptr<base::DictionaryValue> StatusCounters::ToValue() const {
scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue());
value->SetInteger("numEntries", num_entries); value->SetInteger("numEntries", num_entries);
value->SetInteger("numEntriesAndTombstones", num_entries_and_tombstones);
return value.Pass(); return value.Pass();
} }
......
...@@ -20,6 +20,7 @@ struct SYNC_EXPORT_PRIVATE StatusCounters { ...@@ -20,6 +20,7 @@ struct SYNC_EXPORT_PRIVATE StatusCounters {
std::string ToString() const; std::string ToString() const;
size_t num_entries; size_t num_entries;
size_t num_entries_and_tombstones;
}; };
} // namespace syncer } // namespace syncer
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "sync/internal_api/public/sessions/status_counters.h" #include "sync/internal_api/public/sessions/status_counters.h"
#include "sync/internal_api/public/sessions/type_debug_info_observer.h" #include "sync/internal_api/public/sessions/type_debug_info_observer.h"
#include "sync/syncable/entry.h"
#include "sync/syncable/syncable_read_transaction.h" #include "sync/syncable/syncable_read_transaction.h"
namespace syncer { namespace syncer {
...@@ -61,7 +62,27 @@ void DirectoryTypeDebugInfoEmitter::EmitUpdateCountersUpdate() { ...@@ -61,7 +62,27 @@ void DirectoryTypeDebugInfoEmitter::EmitUpdateCountersUpdate() {
} }
void DirectoryTypeDebugInfoEmitter::EmitStatusCountersUpdate() { void DirectoryTypeDebugInfoEmitter::EmitStatusCountersUpdate() {
// TODO(rlarocque): Implement this. Part of crbug.com/328606. // This is expensive. Avoid running this code unless about:sync is open.
if (!type_debug_info_observers_->might_have_observers())
return;
syncable::ReadTransaction trans(FROM_HERE, directory_);
std::vector<int64> result;
directory_->GetMetaHandlesOfType(&trans, type_, &result);
StatusCounters counters;
counters.num_entries_and_tombstones = result.size();
for (std::vector<int64>::const_iterator it = result.begin();
it != result.end(); ++it) {
syncable::Entry e(&trans, syncable::GET_BY_HANDLE, *it);
if (!e.GetIsDel()) {
counters.num_entries++;
}
}
FOR_EACH_OBSERVER(TypeDebugInfoObserver, (*type_debug_info_observers_),
OnStatusCountersUpdated(type_, counters));
} }
} // namespace syncer } // namespace syncer
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment