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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/sync/engine_impl/uss_migrator.h"
6
7 #include <memory>
8 #include <string>
9 #include <utility>
10 #include <vector>
11
12 #include "base/memory/ptr_util.h"
13 #include "components/sync/base/time.h"
14 #include "components/sync/engine_impl/model_type_worker.h"
15 #include "components/sync/protocol/sync.pb.h"
16 #include "components/sync/syncable/directory.h"
17 #include "components/sync/syncable/entry.h"
18 #include "components/sync/syncable/read_node.h"
19 #include "components/sync/syncable/read_transaction.h"
20 #include "components/sync/syncable/user_share.h"
21
22 namespace syncer {
23
24 namespace {
25
26 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
27 int64_t id,
28 sync_pb::SyncEntity* entity) {
29 ReadNode read_node(trans);
30 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
31 return false;
32
33 const syncable::Entry& entry = *read_node.GetEntry();
34
35 entity->set_id_string(entry.GetId().GetServerId());
36 entity->set_version(entry.GetServerVersion());
37 entity->set_mtime(TimeToProtoTime(entry.GetServerMtime()));
38 entity->set_ctime(TimeToProtoTime(entry.GetServerCtime()));
39 entity->set_name(entry.GetServerNonUniqueName());
40 entity->set_deleted(entry.GetServerIsDel());
41 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.
42
43 // It looks like there are fancy other ways to get e.g. passwords specifics
44 // 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.
45 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,
46 return true;
47 }
48
49 } // namespace
50
51 bool MigrateDirectoryData(ModelType type,
52 UserShare* user_share,
53 ModelTypeWorker* worker,
54 int batch_size) {
55 std::string type_name = ModelTypeToString(type);
56 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
57
58 ReadNode root(&trans);
59 if (root.InitTypeRoot(type) != BaseNode::INIT_OK) {
60 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.
61 return false;
62 }
63
64 // Get the progress marker and context from the directory.
65 sync_pb::DataTypeProgressMarker progress;
66 sync_pb::DataTypeContext context;
67 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
68 user_share->directory->GetDataTypeContext(trans.GetWrappedTrans(), type,
69 &context);
70
71 std::vector<int64_t> child_ids;
72 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.
73
74 size_t i = 0;
75 while (i < child_ids.size()) {
76 // Vector to own the temporary entities.
77 std::vector<std::unique_ptr<sync_pb::SyncEntity>> entities;
78 // Vector of raw pointers for passing to ProcessGetUpdatesResponse().
79 SyncEntityList entity_ptrs;
80
81 // 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?
82 const size_t batch_limit = i + batch_size;
83 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 :
84 auto entity = base::MakeUnique<sync_pb::SyncEntity>();
85 if (!ExtractSyncEntity(&trans, child_ids[i], entity.get())) {
86 LOG(ERROR) << "Failed to fetch child node for " << type_name << ".";
87 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
88 }
89 entity_ptrs.push_back(entity.get());
90 entities.push_back(std::move(entity));
91 i++;
92 }
93
94 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.
95 }
96
97 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
98 return true;
99 }
100
101 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698