Index: components/sync/core/shared_model_type_processor.cc |
diff --git a/components/sync/core/shared_model_type_processor.cc b/components/sync/core/shared_model_type_processor.cc |
index 14ca2b6e9825f7b3be65115448e95f92fa4b38eb..65b9df6eb5b411f9ff2c94132c84599409d384dd 100644 |
--- a/components/sync/core/shared_model_type_processor.cc |
+++ b/components/sync/core/shared_model_type_processor.cc |
@@ -15,6 +15,7 @@ |
#include "components/sync/core/activation_context.h" |
#include "components/sync/core/processor_entity_tracker.h" |
#include "components/sync/engine/commit_queue.h" |
+#include "components/sync/protocol/proto_value_conversions.h" |
#include "components/sync/syncable/syncable_util.h" |
namespace syncer_v2 { |
@@ -191,6 +192,16 @@ bool SharedModelTypeProcessor::IsConnected() const { |
return !!worker_; |
} |
+void SharedModelTypeProcessor::GetAllNodes( |
+ const scoped_refptr<base::TaskRunner>& task_runner, |
+ const base::Callback<void(const syncer::ModelType, |
+ std::unique_ptr<base::ListValue>)>& callback) { |
+ DCHECK(service_); |
+ service_->GetAllData( |
+ base::Bind(&SharedModelTypeProcessor::MergeDataWithMetadata, |
+ base::Unretained(this), task_runner, callback)); |
+} |
+ |
void SharedModelTypeProcessor::DisableSync() { |
DCHECK(CalledOnValidThread()); |
std::unique_ptr<MetadataChangeList> change_list = |
@@ -704,4 +715,39 @@ ProcessorEntityTracker* SharedModelTypeProcessor::CreateEntity( |
return CreateEntity(service_->GetStorageKey(data), data); |
} |
+void SharedModelTypeProcessor::MergeDataWithMetadata( |
+ const scoped_refptr<base::TaskRunner>& task_runner, |
+ const base::Callback<void(const syncer::ModelType, |
+ std::unique_ptr<base::ListValue>)>& callback, |
+ syncer::SyncError error, |
+ std::unique_ptr<DataBatch> batch) { |
+ std::unique_ptr<base::ListValue> all_nodes(new base::ListValue()); |
+ |
+ while (batch->HasNext()) { |
+ KeyAndData data = batch->Next(); |
+ std::unique_ptr<base::DictionaryValue> node = |
+ EntityData::ToValue(*data.second); |
+ ProcessorEntityTracker* entity = GetEntityForStorageKey(data.first); |
+ // entity could be null if there are some unapplied changes. |
skym
2016/09/12 16:40:39
Capitalize first letter
Gang Wu
2016/09/12 22:38:03
Done.
|
+ if (entity != nullptr) { |
+ std::unique_ptr<base::DictionaryValue> metadata = |
+ syncer::EntityMetadataToValue(entity->metadata()); |
+ node->MergeDictionary(metadata.get()); |
skym
2016/09/12 16:40:38
1) Why do we merge these two? Why not use a single
Gang Wu
2016/09/12 22:38:03
|node| is real data, |metadata| is metadata, so me
skym
2016/09/13 16:45:17
Really? Looking at EntityData::ToDictionaryValue()
Gang Wu
2016/09/13 18:45:02
Thanks for point that out!
But in here, all the ke
|
+ } |
+ node->SetString("modelType", ModelTypeToString(type_)); |
skym
2016/09/12 16:40:39
I know this wasn't you, but its really odd how som
Gang Wu
2016/09/12 22:38:03
We can discuss this in USS meeting, since this wil
|
+ all_nodes->Append(std::move(node)); |
+ } |
+ |
+ // Create a permanent folder for this data type |
skym
2016/09/12 16:40:39
Comment sentence should have a period at the end.
Gang Wu
2016/09/12 22:38:03
yes, that is correct.
Comments added.
|
+ std::unique_ptr<base::DictionaryValue> rootnode(new base::DictionaryValue()); |
skym
2016/09/12 16:40:39
MakeUnique?
Gang Wu
2016/09/12 22:38:03
any different?
skym
2016/09/13 16:45:17
https://groups.google.com/a/chromium.org/forum/#!t
Gang Wu
2016/09/13 18:45:02
Done.
|
+ rootnode->SetString("PARENT_ID", "r"); |
skym
2016/09/12 16:40:39
r?
Gang Wu
2016/09/12 22:38:03
I guess "r" means root, isTypeRootNode in sync_nod
|
+ rootnode->SetBoolean("IS_DIR", true); |
+ rootnode->SetString("modelType", ModelTypeToString(type_)); |
+ rootnode->SetString("NON_UNIQUE_NAME", ModelTypeToString(type_)); |
skym
2016/09/12 16:40:38
You call ModelTypeToString a lot in this function.
Gang Wu
2016/09/12 22:38:03
Done.
|
+ all_nodes->Append(std::move(rootnode)); |
+ |
+ task_runner->PostTask(FROM_HERE, |
+ base::Bind(callback, type_, base::Passed(&all_nodes))); |
+} |
+ |
} // namespace syncer_v2 |