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

Unified Diff: components/sync/engine_impl/uss_migrator.cc

Issue 2442583003: [Sync] Start implementation of migration for USS. (Closed)
Patch Set: Fix other tests. 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
Index: components/sync/engine_impl/uss_migrator.cc
diff --git a/components/sync/engine_impl/uss_migrator.cc b/components/sync/engine_impl/uss_migrator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..048720fac18b705baa5b0505ccf17d1526b717f8
--- /dev/null
+++ b/components/sync/engine_impl/uss_migrator.cc
@@ -0,0 +1,101 @@
+// 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/engine_impl/uss_migrator.h"
+
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "base/memory/ptr_util.h"
+#include "components/sync/base/time.h"
+#include "components/sync/engine_impl/model_type_worker.h"
+#include "components/sync/protocol/sync.pb.h"
+#include "components/sync/syncable/directory.h"
+#include "components/sync/syncable/entry.h"
+#include "components/sync/syncable/read_node.h"
+#include "components/sync/syncable/read_transaction.h"
+#include "components/sync/syncable/user_share.h"
+
+namespace syncer {
+
+namespace {
+
+bool ExtractSyncEntity(ReadTransaction* trans,
skym 2016/10/21 15:34:20 Should this be a const ref?
maxbogue 2016/10/24 19:02:18 ReadNode takes a non-const transaction pointer, so
+ int64_t id,
+ sync_pb::SyncEntity* entity) {
+ ReadNode read_node(trans);
+ if (read_node.InitByIdLookup(id) != BaseNode::INIT_OK)
skym 2016/10/21 15:34:20 So why could this fail? How does this handle tombs
maxbogue 2016/10/24 19:02:18 This line is just a failure to look up data. The r
skym 2016/10/25 15:48:12 I guess what I was suggesting, poorly, was lets lo
+ return false;
+
+ const syncable::Entry& entry = *read_node.GetEntry();
+
+ entity->set_id_string(entry.GetId().GetServerId());
+ entity->set_version(entry.GetServerVersion());
+ entity->set_mtime(TimeToProtoTime(entry.GetServerMtime()));
+ entity->set_ctime(TimeToProtoTime(entry.GetServerCtime()));
+ entity->set_name(entry.GetServerNonUniqueName());
+ entity->set_deleted(entry.GetServerIsDel());
+ entity->set_client_defined_unique_tag(entry.GetUniqueClientTag());
skym 2016/10/21 15:34:20 There's a lot of fields in Entry and/or SyncEntity
maxbogue 2016/10/24 19:02:18 Done.
+
+ // It looks like there are fancy other ways to get e.g. passwords specifics
+ // out of Entry. Do we need to special-case them when we ship those types?
skym 2016/10/21 15:34:20 DCHECK not passwords?
maxbogue 2016/10/24 19:02:19 Done in the main function.
+ entity->mutable_specifics()->CopyFrom(entry.GetSpecifics());
skym 2016/10/21 15:34:20 Can you add a comment for why not ServerSpecifics
maxbogue 2016/10/24 19:02:18 Mmm... I think I mean to do server specifics here,
+ return true;
+}
+
+} // namespace
+
+bool MigrateDirectoryData(ModelType type,
+ UserShare* user_share,
+ ModelTypeWorker* worker,
+ int batch_size) {
+ std::string type_name = ModelTypeToString(type);
+ ReadTransaction trans(FROM_HERE, user_share);
skym 2016/10/21 15:34:20 So what's the difference between syncer::syncable:
maxbogue 2016/10/24 19:02:18 ¯\_(ツ)_/¯ I also do not quite get it. It might jus
+
+ ReadNode root(&trans);
+ if (root.InitTypeRoot(type) != BaseNode::INIT_OK) {
+ LOG(ERROR) << "Missing root node for " << type_name << ".";
skym 2016/10/21 15:34:20 I would drop the trailing period, don't need corre
maxbogue 2016/10/24 19:02:18 Done.
+ return false;
+ }
+
+ // Get the progress marker and context from the directory.
+ sync_pb::DataTypeProgressMarker progress;
+ sync_pb::DataTypeContext context;
+ user_share->directory->GetDownloadProgress(type, &progress);
skym 2016/10/21 15:34:20 These can't fail? How does ScopdKernelLock interac
maxbogue 2016/10/24 19:02:18 They don't seem to fail, no. It seems to interact
+ user_share->directory->GetDataTypeContext(trans.GetWrappedTrans(), type,
+ &context);
+
+ std::vector<int64_t> child_ids;
+ root.GetChildIds(&child_ids);
skym 2016/10/21 15:34:20 DCHECK not bookmarks? Does look like this is handl
maxbogue 2016/10/24 19:02:18 Done.
+
+ size_t i = 0;
+ while (i < child_ids.size()) {
+ // Vector to own the temporary entities.
+ std::vector<std::unique_ptr<sync_pb::SyncEntity>> entities;
+ // Vector of raw pointers for passing to ProcessGetUpdatesResponse().
+ SyncEntityList entity_ptrs;
+
+ // Process |batch_size| entities at a time to reduce memory usage.
skym 2016/10/21 15:34:20 I think this is the wrong place for this comment.
maxbogue 2016/10/24 19:02:18 Moved above the loop... hopefully that's better?
+ const size_t batch_limit = i + batch_size;
+ while (i < batch_limit && i < child_ids.size()) {
skym 2016/10/21 15:34:20 Can you use 'for' here? I think it'd make it more
maxbogue 2016/10/24 19:02:18 Done. Also I just did the min to set batch_limit :
+ auto entity = base::MakeUnique<sync_pb::SyncEntity>();
+ if (!ExtractSyncEntity(&trans, child_ids[i], entity.get())) {
+ LOG(ERROR) << "Failed to fetch child node for " << type_name << ".";
+ return false;
skym 2016/10/21 15:34:20 Can you comment about why you don't need to strip
maxbogue 2016/10/24 19:02:18 I've added an AbortMigration method to the worker
+ }
+ entity_ptrs.push_back(entity.get());
+ entities.push_back(std::move(entity));
+ i++;
+ }
+
+ worker->ProcessGetUpdatesResponse(progress, context, entity_ptrs, nullptr);
skym 2016/10/21 15:34:20 It is kind of odd that we update progress/context
maxbogue 2016/10/24 19:02:18 Sure is... I don't really feel comfortable changin
skym 2016/10/25 15:48:12 That's reasonable.
maxbogue 2016/10/26 23:26:15 Acknowledged.
+ }
+
+ worker->PassiveApplyUpdates(nullptr);
skym 2016/10/21 15:34:20 I'm worried about all the different places respons
maxbogue 2016/10/24 19:02:18 All the places? There's just this place and the no
skym 2016/10/25 15:48:12 And on migration failure in the worker.
maxbogue 2016/10/26 23:26:15 Ah right, we nudge there. That's a different probl
+ return true;
+}
+
+} // namespace syncer

Powered by Google App Engine
This is Rietveld 408576698