Commit 85949830 authored by gangwu's avatar gangwu Committed by Commit bot

[USS] Implement SharedModelTypeProcessor::GetAllNodes for USS

mplement SharedModelTypeProcessor::GetAllNodes for USS, so
"Sync Node Browser" tab in chrome://sync-internals/ will show
USS data.
BTW, modelTypeWorker already ignore the root folder from
server.

BUG=645303

Review-Url: https://codereview.chromium.org/2319973003
Cr-Commit-Position: refs/heads/master@{#418735}
parent 2917c5ca
...@@ -7,9 +7,23 @@ ...@@ -7,9 +7,23 @@
#include <algorithm> #include <algorithm>
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "components/sync/base/time.h"
#include "components/sync/base/unique_position.h"
#include "components/sync/protocol/proto_value_conversions.h"
namespace syncer_v2 { namespace syncer_v2 {
namespace {
std::string UniquePositionToString(
const sync_pb::UniquePosition& unique_position) {
return syncer::UniquePosition::FromProto(unique_position).ToDebugString();
}
} // namespace
EntityData::EntityData() {} EntityData::EntityData() {}
EntityData::~EntityData() {} EntityData::~EntityData() {}
...@@ -33,6 +47,24 @@ EntityDataPtr EntityData::PassToPtr() { ...@@ -33,6 +47,24 @@ EntityDataPtr EntityData::PassToPtr() {
return target; return target;
} }
#define ADD_TO_DICT(dict, value, transform) \
dict->SetString(base::ToUpperASCII(#value), transform(value));
std::unique_ptr<base::DictionaryValue> EntityData::ToDictionaryValue() {
std::unique_ptr<base::DictionaryValue> dict =
syncer::EntitySpecificsToValue(specifics);
ADD_TO_DICT(dict, id, );
ADD_TO_DICT(dict, client_tag_hash, );
ADD_TO_DICT(dict, non_unique_name, );
ADD_TO_DICT(dict, parent_id, );
ADD_TO_DICT(dict, creation_time, syncer::GetTimeDebugString);
ADD_TO_DICT(dict, modification_time, syncer::GetTimeDebugString);
ADD_TO_DICT(dict, unique_position, UniquePositionToString);
return dict;
}
#undef ADD_TO_DICT
void EntityDataTraits::SwapValue(EntityData* dest, EntityData* src) { void EntityDataTraits::SwapValue(EntityData* dest, EntityData* src) {
dest->Swap(src); dest->Swap(src);
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/values.h"
#include "components/sync/base/proto_value_ptr.h" #include "components/sync/base/proto_value_ptr.h"
#include "components/sync/protocol/sync.pb.h" #include "components/sync/protocol/sync.pb.h"
...@@ -74,6 +75,9 @@ struct EntityData { ...@@ -74,6 +75,9 @@ struct EntityData {
// The return value must be assigned into another EntityDataPtr. // The return value must be assigned into another EntityDataPtr.
EntityDataPtr PassToPtr() WARN_UNUSED_RESULT; EntityDataPtr PassToPtr() WARN_UNUSED_RESULT;
// Dumps all info into a DictionaryValue and returns it.
std::unique_ptr<base::DictionaryValue> ToDictionaryValue();
private: private:
friend struct EntityDataTraits; friend struct EntityDataTraits;
// Used to transfer the data without copying. // Used to transfer the data without copying.
......
...@@ -120,11 +120,11 @@ class ModelTypeService : public base::SupportsWeakPtr<ModelTypeService> { ...@@ -120,11 +120,11 @@ class ModelTypeService : public base::SupportsWeakPtr<ModelTypeService> {
// TODO(crbug.com/584365): This needs to be called from DataTypeController. // TODO(crbug.com/584365): This needs to be called from DataTypeController.
void DisableSync(); void DisableSync();
ModelTypeChangeProcessor* change_processor() const;
protected: protected:
void CreateChangeProcessor(); void CreateChangeProcessor();
ModelTypeChangeProcessor* change_processor() const;
void clear_change_processor(); void clear_change_processor();
private: private:
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "components/sync/core/activation_context.h" #include "components/sync/core/activation_context.h"
#include "components/sync/core/processor_entity_tracker.h" #include "components/sync/core/processor_entity_tracker.h"
#include "components/sync/engine/commit_queue.h" #include "components/sync/engine/commit_queue.h"
#include "components/sync/protocol/proto_value_conversions.h"
#include "components/sync/syncable/syncable_util.h" #include "components/sync/syncable/syncable_util.h"
namespace syncer_v2 { namespace syncer_v2 {
...@@ -191,6 +192,16 @@ bool SharedModelTypeProcessor::IsConnected() const { ...@@ -191,6 +192,16 @@ bool SharedModelTypeProcessor::IsConnected() const {
return !!worker_; 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() { void SharedModelTypeProcessor::DisableSync() {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
std::unique_ptr<MetadataChangeList> change_list = std::unique_ptr<MetadataChangeList> change_list =
...@@ -704,4 +715,47 @@ ProcessorEntityTracker* SharedModelTypeProcessor::CreateEntity( ...@@ -704,4 +715,47 @@ ProcessorEntityTracker* SharedModelTypeProcessor::CreateEntity(
return CreateEntity(service_->GetStorageKey(data), data); 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 =
base::MakeUnique<base::ListValue>();
std::string type_string = ModelTypeToString(type_);
while (batch->HasNext()) {
KeyAndData data = batch->Next();
std::unique_ptr<base::DictionaryValue> node =
data.second->ToDictionaryValue();
ProcessorEntityTracker* entity = GetEntityForStorageKey(data.first);
// Entity could be null if there are some unapplied changes.
if (entity != nullptr) {
node->Set("metadata", syncer::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));
task_runner->PostTask(FROM_HERE,
base::Bind(callback, type_, base::Passed(&all_nodes)));
}
} // namespace syncer_v2 } // namespace syncer_v2
...@@ -51,6 +51,15 @@ class SharedModelTypeProcessor : public ModelTypeProcessor, ...@@ -51,6 +51,15 @@ class SharedModelTypeProcessor : public ModelTypeProcessor,
// Returns true if the handshake with sync thread is complete. // Returns true if the handshake with sync thread is complete.
bool IsConnected() const; bool IsConnected() const;
// Returns a ListValue representing all nodes for data type |type| through
// |callback| on this thread.
// Used for populating nodes in Sync Node Browser of chrome://sync-internals.
// TODO(gangwu): GetAllNodes could be in a helper class.
void GetAllNodes(
const scoped_refptr<base::TaskRunner>& task_runner,
const base::Callback<void(const syncer::ModelType type,
std::unique_ptr<base::ListValue>)>& callback);
// ModelTypeChangeProcessor implementation. // ModelTypeChangeProcessor implementation.
void Put(const std::string& storage_key, void Put(const std::string& storage_key,
std::unique_ptr<EntityData> entity_data, std::unique_ptr<EntityData> entity_data,
...@@ -143,6 +152,15 @@ class SharedModelTypeProcessor : public ModelTypeProcessor, ...@@ -143,6 +152,15 @@ class SharedModelTypeProcessor : public ModelTypeProcessor,
// Version of the above that generates a tag for |data|. // Version of the above that generates a tag for |data|.
ProcessorEntityTracker* CreateEntity(const EntityData& data); ProcessorEntityTracker* CreateEntity(const EntityData& data);
// This is callback function for ModelTypeService::GetAllData. This function
// will merge real data |batch| with metadata, then pass to |callback|.
void 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);
const syncer::ModelType type_; const syncer::ModelType type_;
sync_pb::DataTypeState data_type_state_; sync_pb::DataTypeState data_type_state_;
......
...@@ -79,7 +79,16 @@ void NonBlockingDataTypeController::LoadModels( ...@@ -79,7 +79,16 @@ void NonBlockingDataTypeController::LoadModels(
void NonBlockingDataTypeController::GetAllNodes( void NonBlockingDataTypeController::GetAllNodes(
const AllNodesCallback& callback) { const AllNodesCallback& callback) {
callback.Run(type(), base::WrapUnique(new base::ListValue())); base::WeakPtr<syncer_v2::ModelTypeService> service =
sync_client_->GetModelTypeServiceForType(type());
// TODO(gangwu): Casting should happen "near" where the processor factory has
// code that instantiates a new processor.
syncer_v2::SharedModelTypeProcessor* processor =
(syncer_v2::SharedModelTypeProcessor*)service->change_processor();
RunOnModelThread(FROM_HERE,
base::Bind(&syncer_v2::SharedModelTypeProcessor::GetAllNodes,
base::Unretained(processor),
base::ThreadTaskRunnerHandle::Get(), callback));
} }
void NonBlockingDataTypeController::LoadModelsDone( void NonBlockingDataTypeController::LoadModelsDone(
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "components/sync/protocol/bookmark_specifics.pb.h" #include "components/sync/protocol/bookmark_specifics.pb.h"
#include "components/sync/protocol/dictionary_specifics.pb.h" #include "components/sync/protocol/dictionary_specifics.pb.h"
#include "components/sync/protocol/encryption.pb.h" #include "components/sync/protocol/encryption.pb.h"
#include "components/sync/protocol/entity_metadata.pb.h"
#include "components/sync/protocol/experiments_specifics.pb.h" #include "components/sync/protocol/experiments_specifics.pb.h"
#include "components/sync/protocol/extension_setting_specifics.pb.h" #include "components/sync/protocol/extension_setting_specifics.pb.h"
#include "components/sync/protocol/extension_specifics.pb.h" #include "components/sync/protocol/extension_specifics.pb.h"
...@@ -1118,6 +1119,22 @@ std::unique_ptr<base::DictionaryValue> AttachmentIdProtoToValue( ...@@ -1118,6 +1119,22 @@ std::unique_ptr<base::DictionaryValue> AttachmentIdProtoToValue(
return value; return value;
} }
std::unique_ptr<base::DictionaryValue> EntityMetadataToValue(
const sync_pb::EntityMetadata& proto) {
std::unique_ptr<base::DictionaryValue> value(new base::DictionaryValue());
SET_STR(client_tag_hash);
SET_STR(server_id);
SET_BOOL(is_deleted);
SET_INT64(sequence_number);
SET_INT64(acked_sequence_number);
SET_INT64(server_version);
SET_INT64(creation_time);
SET_INT64(modification_time);
SET_STR(specifics_hash);
SET_STR(base_specifics_hash);
return value;
}
#undef SET_TYPE #undef SET_TYPE
#undef SET #undef SET
#undef SET_REP #undef SET_REP
......
...@@ -37,6 +37,7 @@ class DeviceInfoSpecifics; ...@@ -37,6 +37,7 @@ class DeviceInfoSpecifics;
class DeviceInformation; class DeviceInformation;
class DictionarySpecifics; class DictionarySpecifics;
class EncryptedData; class EncryptedData;
class EntityMetadata;
class EntitySpecifics; class EntitySpecifics;
class EverythingDirective; class EverythingDirective;
class ExperimentsSpecifics; class ExperimentsSpecifics;
...@@ -310,6 +311,9 @@ std::unique_ptr<base::DictionaryValue> ClientConfigParamsToValue( ...@@ -310,6 +311,9 @@ std::unique_ptr<base::DictionaryValue> ClientConfigParamsToValue(
std::unique_ptr<base::DictionaryValue> AttachmentIdProtoToValue( std::unique_ptr<base::DictionaryValue> AttachmentIdProtoToValue(
const sync_pb::AttachmentIdProto& proto); const sync_pb::AttachmentIdProto& proto);
std::unique_ptr<base::DictionaryValue> EntityMetadataToValue(
const sync_pb::EntityMetadata& metadata);
} // namespace syncer } // namespace syncer
#endif // COMPONENTS_SYNC_PROTOCOL_PROTO_VALUE_CONVERSIONS_H_ #endif // COMPONENTS_SYNC_PROTOCOL_PROTO_VALUE_CONVERSIONS_H_
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