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

Side by Side Diff: sync/internal_api/processor_entity_tracker.cc

Issue 1866243002: Convert //sync from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 "sync/internal_api/public/processor_entity_tracker.h" 5 #include "sync/internal_api/public/processor_entity_tracker.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/sha1.h" 10 #include "base/sha1.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "sync/internal_api/public/non_blocking_sync_common.h" 12 #include "sync/internal_api/public/non_blocking_sync_common.h"
13 #include "sync/syncable/syncable_util.h" 13 #include "sync/syncable/syncable_util.h"
14 #include "sync/util/time.h" 14 #include "sync/util/time.h"
15 15
16 namespace syncer_v2 { 16 namespace syncer_v2 {
17 17
18 namespace { 18 namespace {
19 19
20 void HashSpecifics(const sync_pb::EntitySpecifics& specifics, 20 void HashSpecifics(const sync_pb::EntitySpecifics& specifics,
21 std::string* hash) { 21 std::string* hash) {
22 base::Base64Encode(base::SHA1HashString(specifics.SerializeAsString()), hash); 22 base::Base64Encode(base::SHA1HashString(specifics.SerializeAsString()), hash);
23 } 23 }
24 24
25 } // namespace 25 } // namespace
26 26
27 scoped_ptr<ProcessorEntityTracker> ProcessorEntityTracker::CreateNew( 27 std::unique_ptr<ProcessorEntityTracker> ProcessorEntityTracker::CreateNew(
28 const std::string& client_tag, 28 const std::string& client_tag,
29 const std::string& client_tag_hash, 29 const std::string& client_tag_hash,
30 const std::string& id, 30 const std::string& id,
31 base::Time creation_time) { 31 base::Time creation_time) {
32 // Initialize metadata 32 // Initialize metadata
33 sync_pb::EntityMetadata metadata; 33 sync_pb::EntityMetadata metadata;
34 metadata.set_client_tag_hash(client_tag_hash); 34 metadata.set_client_tag_hash(client_tag_hash);
35 if (!id.empty()) 35 if (!id.empty())
36 metadata.set_server_id(id); 36 metadata.set_server_id(id);
37 metadata.set_sequence_number(0); 37 metadata.set_sequence_number(0);
38 metadata.set_acked_sequence_number(0); 38 metadata.set_acked_sequence_number(0);
39 metadata.set_server_version(kUncommittedVersion); 39 metadata.set_server_version(kUncommittedVersion);
40 metadata.set_creation_time(syncer::TimeToProtoTime(creation_time)); 40 metadata.set_creation_time(syncer::TimeToProtoTime(creation_time));
41 41
42 return scoped_ptr<ProcessorEntityTracker>( 42 return std::unique_ptr<ProcessorEntityTracker>(
43 new ProcessorEntityTracker(client_tag, &metadata)); 43 new ProcessorEntityTracker(client_tag, &metadata));
44 } 44 }
45 45
46 scoped_ptr<ProcessorEntityTracker> ProcessorEntityTracker::CreateFromMetadata( 46 std::unique_ptr<ProcessorEntityTracker>
47 const std::string& client_tag, 47 ProcessorEntityTracker::CreateFromMetadata(const std::string& client_tag,
48 sync_pb::EntityMetadata* metadata) { 48 sync_pb::EntityMetadata* metadata) {
49 return scoped_ptr<ProcessorEntityTracker>( 49 return std::unique_ptr<ProcessorEntityTracker>(
50 new ProcessorEntityTracker(client_tag, metadata)); 50 new ProcessorEntityTracker(client_tag, metadata));
51 } 51 }
52 52
53 ProcessorEntityTracker::ProcessorEntityTracker( 53 ProcessorEntityTracker::ProcessorEntityTracker(
54 const std::string& client_tag, 54 const std::string& client_tag,
55 sync_pb::EntityMetadata* metadata) 55 sync_pb::EntityMetadata* metadata)
56 : client_tag_(client_tag), 56 : client_tag_(client_tag),
57 commit_requested_sequence_number_(metadata->acked_sequence_number()) { 57 commit_requested_sequence_number_(metadata->acked_sequence_number()) {
58 DCHECK(metadata->has_client_tag_hash()); 58 DCHECK(metadata->has_client_tag_hash());
59 DCHECK(metadata->has_creation_time()); 59 DCHECK(metadata->has_creation_time());
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 void ProcessorEntityTracker::RecordForcedUpdate( 132 void ProcessorEntityTracker::RecordForcedUpdate(
133 const UpdateResponseData& update) { 133 const UpdateResponseData& update) {
134 DCHECK(IsUnsynced()); 134 DCHECK(IsUnsynced());
135 // There was a conflict and the server just won it. Explicitly ack all 135 // There was a conflict and the server just won it. Explicitly ack all
136 // pending commits so they are never enqueued again. 136 // pending commits so they are never enqueued again.
137 metadata_.set_acked_sequence_number(metadata_.sequence_number()); 137 metadata_.set_acked_sequence_number(metadata_.sequence_number());
138 commit_data_.reset(); 138 commit_data_.reset();
139 RecordAcceptedUpdate(update); 139 RecordAcceptedUpdate(update);
140 } 140 }
141 141
142 void ProcessorEntityTracker::MakeLocalChange(scoped_ptr<EntityData> data) { 142 void ProcessorEntityTracker::MakeLocalChange(std::unique_ptr<EntityData> data) {
143 DCHECK(!metadata_.client_tag_hash().empty()); 143 DCHECK(!metadata_.client_tag_hash().empty());
144 DCHECK_EQ(metadata_.client_tag_hash(), data->client_tag_hash); 144 DCHECK_EQ(metadata_.client_tag_hash(), data->client_tag_hash);
145 145
146 if (data->modification_time.is_null()) { 146 if (data->modification_time.is_null()) {
147 data->modification_time = base::Time::Now(); 147 data->modification_time = base::Time::Now();
148 } 148 }
149 149
150 metadata_.set_modification_time( 150 metadata_.set_modification_time(
151 syncer::TimeToProtoTime(data->modification_time)); 151 syncer::TimeToProtoTime(data->modification_time));
152 metadata_.set_is_deleted(false); 152 metadata_.set_is_deleted(false);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 void ProcessorEntityTracker::UpdateSpecificsHash( 234 void ProcessorEntityTracker::UpdateSpecificsHash(
235 const sync_pb::EntitySpecifics& specifics) { 235 const sync_pb::EntitySpecifics& specifics) {
236 if (specifics.ByteSize() > 0) { 236 if (specifics.ByteSize() > 0) {
237 HashSpecifics(specifics, metadata_.mutable_specifics_hash()); 237 HashSpecifics(specifics, metadata_.mutable_specifics_hash());
238 } else { 238 } else {
239 metadata_.clear_specifics_hash(); 239 metadata_.clear_specifics_hash();
240 } 240 }
241 } 241 }
242 242
243 } // namespace syncer_v2 243 } // namespace syncer_v2
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698