Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Unified Diff: components/sync/model/model_type_debug_info.cc

Issue 2412193002: [Sync] Move SharedModelTypeProcessor to model_impl/. (Closed)
Patch Set: Address comment from Sky. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/sync/model/model_type_debug_info.h ('k') | components/sync/model_impl/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/model/model_type_debug_info.cc
diff --git a/components/sync/model/model_type_debug_info.cc b/components/sync/model/model_type_debug_info.cc
new file mode 100644
index 0000000000000000000000000000000000000000..92d514a68c0a07131dea4f3942eeb4a652c1da43
--- /dev/null
+++ b/components/sync/model/model_type_debug_info.cc
@@ -0,0 +1,110 @@
+// Copyright 2016 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.
+
+#include "components/sync/model/model_type_debug_info.h"
+
+#include "base/bind.h"
+#include "base/memory/ptr_util.h"
+#include "components/sync/model_impl/processor_entity_tracker.h"
+#include "components/sync/protocol/proto_value_conversions.h"
+
+namespace syncer {
+
+namespace {
+
+SharedModelTypeProcessor* GetProcessorFromService(
+ const base::WeakPtr<ModelTypeService>& service) {
+ if (!service.get()) {
+ LOG(WARNING)
+ << "ModelTypeService destroyed before debug info was retrieved.";
+ return nullptr;
+ }
+ SharedModelTypeProcessor* processor =
+ static_cast<SharedModelTypeProcessor*>(service->change_processor());
+ if (!processor) {
+ LOG(WARNING) << "SharedModelTypeProcessor destroyed before debug info was "
+ "retrieved.";
+ return nullptr;
+ }
+ return processor;
+}
+
+} // namespace
+
+// static
+void ModelTypeDebugInfo::GetAllNodes(
+ const base::WeakPtr<ModelTypeService>& service,
+ const base::Callback<void(const ModelType,
+ std::unique_ptr<base::ListValue>)>& callback) {
+ SharedModelTypeProcessor* processor = GetProcessorFromService(service);
+ if (processor) {
+ service->GetAllData(base::Bind(&ModelTypeDebugInfo::MergeDataWithMetadata,
+ base::Unretained(processor), callback));
+ }
+}
+
+// static
+void ModelTypeDebugInfo::GetStatusCounters(
+ const base::WeakPtr<ModelTypeService>& service,
+ const base::Callback<void(ModelType, const StatusCounters&)>& callback) {
+ SharedModelTypeProcessor* processor = GetProcessorFromService(service);
+ if (processor) {
+ syncer::StatusCounters counters;
+ counters.num_entries_and_tombstones = processor->entities_.size();
+ for (const auto& kv : processor->entities_) {
+ if (!kv.second->metadata().is_deleted()) {
+ ++counters.num_entries;
+ }
+ }
+ callback.Run(processor->type_, counters);
+ }
+}
+
+ModelTypeDebugInfo::ModelTypeDebugInfo() {}
+
+// static
+void ModelTypeDebugInfo::MergeDataWithMetadata(
+ SharedModelTypeProcessor* processor,
+ const base::Callback<void(const ModelType,
+ std::unique_ptr<base::ListValue>)>& callback,
+ SyncError error,
+ std::unique_ptr<DataBatch> batch) {
+ std::unique_ptr<base::ListValue> all_nodes =
+ base::MakeUnique<base::ListValue>();
+ std::string type_string = ModelTypeToString(processor->type_);
+
+ while (batch->HasNext()) {
+ KeyAndData data = batch->Next();
+ std::unique_ptr<base::DictionaryValue> node =
+ data.second->ToDictionaryValue();
+ ProcessorEntityTracker* entity =
+ processor->GetEntityForStorageKey(data.first);
+ // Entity could be null if there are some unapplied changes.
+ if (entity != nullptr) {
+ node->Set("metadata", EntityMetadataToValue(entity->metadata()));
+ }
+ node->SetString("modelType", type_string);
+ all_nodes->Append(std::move(node));
+ }
+
+ // Create a permanent folder for this data type. Since sync server no longer
+ // create root folders, and USS won't migrate root folders from directory, we
+ // create root folders for each data type here.
+ std::unique_ptr<base::DictionaryValue> rootnode =
+ base::MakeUnique<base::DictionaryValue>();
+ // Function isTypeRootNode in sync_node_browser.js use PARENT_ID and
+ // UNIQUE_SERVER_TAG to check if the node is root node. isChildOf in
+ // sync_node_browser.js uses modelType to check if root node is parent of real
+ // data node. NON_UNIQUE_NAME will be the name of node to display.
+ rootnode->SetString("PARENT_ID", "r");
+ rootnode->SetString("UNIQUE_SERVER_TAG", type_string);
+ rootnode->SetBoolean("IS_DIR", true);
+ rootnode->SetString("modelType", type_string);
+ rootnode->SetString("NON_UNIQUE_NAME", type_string);
+ all_nodes->Append(std::move(rootnode));
+
+ callback.Run(processor->type_, std::move(all_nodes));
+}
+
+} // namespace syncer
« no previous file with comments | « components/sync/model/model_type_debug_info.h ('k') | components/sync/model_impl/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698