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

Side by Side Diff: components/sync/model_impl/processor_entity_tracker.cc

Issue 2915763005: [Sync] Implement support for updating storage key for new entities (Closed)
Patch Set: Rebase. Fix recommit for encryption scenario. Created 3 years, 6 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/sync/model_impl/processor_entity_tracker.h" 5 #include "components/sync/model_impl/processor_entity_tracker.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/sha1.h" 8 #include "base/sha1.h"
9 #include "base/trace_event/memory_usage_estimator.h" 9 #include "base/trace_event/memory_usage_estimator.h"
10 #include "components/sync/base/time.h" 10 #include "components/sync/base/time.h"
(...skipping 27 matching lines...) Expand all
38 metadata.set_server_version(kUncommittedVersion); 38 metadata.set_server_version(kUncommittedVersion);
39 metadata.set_creation_time(TimeToProtoTime(creation_time)); 39 metadata.set_creation_time(TimeToProtoTime(creation_time));
40 40
41 return std::unique_ptr<ProcessorEntityTracker>( 41 return std::unique_ptr<ProcessorEntityTracker>(
42 new ProcessorEntityTracker(storage_key, &metadata)); 42 new ProcessorEntityTracker(storage_key, &metadata));
43 } 43 }
44 44
45 std::unique_ptr<ProcessorEntityTracker> 45 std::unique_ptr<ProcessorEntityTracker>
46 ProcessorEntityTracker::CreateFromMetadata(const std::string& storage_key, 46 ProcessorEntityTracker::CreateFromMetadata(const std::string& storage_key,
47 sync_pb::EntityMetadata* metadata) { 47 sync_pb::EntityMetadata* metadata) {
48 DCHECK(!storage_key.empty());
48 return std::unique_ptr<ProcessorEntityTracker>( 49 return std::unique_ptr<ProcessorEntityTracker>(
49 new ProcessorEntityTracker(storage_key, metadata)); 50 new ProcessorEntityTracker(storage_key, metadata));
50 } 51 }
51 52
52 ProcessorEntityTracker::ProcessorEntityTracker( 53 ProcessorEntityTracker::ProcessorEntityTracker(
53 const std::string& storage_key, 54 const std::string& storage_key,
54 sync_pb::EntityMetadata* metadata) 55 sync_pb::EntityMetadata* metadata)
55 : storage_key_(storage_key), 56 : storage_key_(storage_key),
56 commit_requested_sequence_number_(metadata->acked_sequence_number()) { 57 commit_requested_sequence_number_(metadata->acked_sequence_number()) {
57 DCHECK(metadata->has_client_tag_hash()); 58 DCHECK(metadata->has_client_tag_hash());
58 DCHECK(metadata->has_creation_time()); 59 DCHECK(metadata->has_creation_time());
59 metadata_.Swap(metadata); 60 metadata_.Swap(metadata);
60 } 61 }
61 62
62 ProcessorEntityTracker::~ProcessorEntityTracker() {} 63 ProcessorEntityTracker::~ProcessorEntityTracker() {}
63 64
64 void ProcessorEntityTracker::SetStorageKey(const std::string& new_key) { 65 void ProcessorEntityTracker::SetStorageKey(const std::string& storage_key) {
65 storage_key_ = new_key; 66 DCHECK(storage_key_.empty());
67 DCHECK(!storage_key.empty());
68 storage_key_ = storage_key;
66 } 69 }
67 70
68 void ProcessorEntityTracker::SetCommitData(EntityData* data) { 71 void ProcessorEntityTracker::SetCommitData(EntityData* data) {
69 DCHECK(data); 72 DCHECK(data);
70 // Update data's fields from metadata. 73 // Update data's fields from metadata.
71 data->client_tag_hash = metadata_.client_tag_hash(); 74 data->client_tag_hash = metadata_.client_tag_hash();
72 if (!metadata_.server_id().empty()) 75 if (!metadata_.server_id().empty())
73 data->id = metadata_.server_id(); 76 data->id = metadata_.server_id();
74 data->creation_time = ProtoTimeToTime(metadata_.creation_time()); 77 data->creation_time = ProtoTimeToTime(metadata_.creation_time());
75 data->modification_time = ProtoTimeToTime(metadata_.modification_time()); 78 data->modification_time = ProtoTimeToTime(metadata_.modification_time());
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 void ProcessorEntityTracker::UpdateSpecificsHash( 268 void ProcessorEntityTracker::UpdateSpecificsHash(
266 const sync_pb::EntitySpecifics& specifics) { 269 const sync_pb::EntitySpecifics& specifics) {
267 if (specifics.ByteSize() > 0) { 270 if (specifics.ByteSize() > 0) {
268 HashSpecifics(specifics, metadata_.mutable_specifics_hash()); 271 HashSpecifics(specifics, metadata_.mutable_specifics_hash());
269 } else { 272 } else {
270 metadata_.clear_specifics_hash(); 273 metadata_.clear_specifics_hash();
271 } 274 }
272 } 275 }
273 276
274 } // namespace syncer 277 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/model_impl/processor_entity_tracker.h ('k') | components/sync/model_impl/processor_entity_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698