| OLD | NEW |
| 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/core/processor_entity_tracker.h" | 5 #include "components/sync/core/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 "components/sync/base/time.h" | 12 #include "components/sync/base/time.h" |
| 13 #include "components/sync/core/non_blocking_sync_common.h" | 13 #include "components/sync/core/non_blocking_sync_common.h" |
| 14 #include "components/sync/syncable/syncable_util.h" | 14 #include "components/sync/syncable/syncable_util.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 DCHECK_GT(specifics.ByteSize(), 0); | 22 DCHECK_GT(specifics.ByteSize(), 0); |
| 23 base::Base64Encode(base::SHA1HashString(specifics.SerializeAsString()), hash); | 23 base::Base64Encode(base::SHA1HashString(specifics.SerializeAsString()), hash); |
| 24 } | 24 } |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 std::unique_ptr<ProcessorEntityTracker> ProcessorEntityTracker::CreateNew( | 28 std::unique_ptr<ProcessorEntityTracker> ProcessorEntityTracker::CreateNew( |
| 29 const std::string& client_tag, | 29 const std::string& storage_key, |
| 30 const std::string& client_tag_hash, | 30 const std::string& client_tag_hash, |
| 31 const std::string& id, | 31 const std::string& id, |
| 32 base::Time creation_time) { | 32 base::Time creation_time) { |
| 33 // Initialize metadata | 33 // Initialize metadata |
| 34 sync_pb::EntityMetadata metadata; | 34 sync_pb::EntityMetadata metadata; |
| 35 metadata.set_client_tag_hash(client_tag_hash); | 35 metadata.set_client_tag_hash(client_tag_hash); |
| 36 if (!id.empty()) | 36 if (!id.empty()) |
| 37 metadata.set_server_id(id); | 37 metadata.set_server_id(id); |
| 38 metadata.set_sequence_number(0); | 38 metadata.set_sequence_number(0); |
| 39 metadata.set_acked_sequence_number(0); | 39 metadata.set_acked_sequence_number(0); |
| 40 metadata.set_server_version(kUncommittedVersion); | 40 metadata.set_server_version(kUncommittedVersion); |
| 41 metadata.set_creation_time(syncer::TimeToProtoTime(creation_time)); | 41 metadata.set_creation_time(syncer::TimeToProtoTime(creation_time)); |
| 42 | 42 |
| 43 return std::unique_ptr<ProcessorEntityTracker>( | 43 return std::unique_ptr<ProcessorEntityTracker>( |
| 44 new ProcessorEntityTracker(client_tag, &metadata)); | 44 new ProcessorEntityTracker(storage_key, &metadata)); |
| 45 } | 45 } |
| 46 | 46 |
| 47 std::unique_ptr<ProcessorEntityTracker> | 47 std::unique_ptr<ProcessorEntityTracker> |
| 48 ProcessorEntityTracker::CreateFromMetadata(const std::string& client_tag, | 48 ProcessorEntityTracker::CreateFromMetadata(const std::string& storage_key, |
| 49 sync_pb::EntityMetadata* metadata) { | 49 sync_pb::EntityMetadata* metadata) { |
| 50 return std::unique_ptr<ProcessorEntityTracker>( | 50 return std::unique_ptr<ProcessorEntityTracker>( |
| 51 new ProcessorEntityTracker(client_tag, metadata)); | 51 new ProcessorEntityTracker(storage_key, metadata)); |
| 52 } | 52 } |
| 53 | 53 |
| 54 ProcessorEntityTracker::ProcessorEntityTracker( | 54 ProcessorEntityTracker::ProcessorEntityTracker( |
| 55 const std::string& client_tag, | 55 const std::string& storage_key, |
| 56 sync_pb::EntityMetadata* metadata) | 56 sync_pb::EntityMetadata* metadata) |
| 57 : client_tag_(client_tag), | 57 : storage_key_(storage_key), |
| 58 commit_requested_sequence_number_(metadata->acked_sequence_number()) { | 58 commit_requested_sequence_number_(metadata->acked_sequence_number()) { |
| 59 DCHECK(metadata->has_client_tag_hash()); | 59 DCHECK(metadata->has_client_tag_hash()); |
| 60 DCHECK(metadata->has_creation_time()); | 60 DCHECK(metadata->has_creation_time()); |
| 61 metadata_.Swap(metadata); | 61 metadata_.Swap(metadata); |
| 62 } | 62 } |
| 63 | 63 |
| 64 ProcessorEntityTracker::~ProcessorEntityTracker() {} | 64 ProcessorEntityTracker::~ProcessorEntityTracker() {} |
| 65 | 65 |
| 66 void ProcessorEntityTracker::CacheCommitData(EntityData* data) { | 66 void ProcessorEntityTracker::CacheCommitData(EntityData* data) { |
| 67 DCHECK(data); | 67 DCHECK(data); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 void ProcessorEntityTracker::UpdateSpecificsHash( | 246 void ProcessorEntityTracker::UpdateSpecificsHash( |
| 247 const sync_pb::EntitySpecifics& specifics) { | 247 const sync_pb::EntitySpecifics& specifics) { |
| 248 if (specifics.ByteSize() > 0) { | 248 if (specifics.ByteSize() > 0) { |
| 249 HashSpecifics(specifics, metadata_.mutable_specifics_hash()); | 249 HashSpecifics(specifics, metadata_.mutable_specifics_hash()); |
| 250 } else { | 250 } else { |
| 251 metadata_.clear_specifics_hash(); | 251 metadata_.clear_specifics_hash(); |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 | 254 |
| 255 } // namespace syncer_v2 | 255 } // namespace syncer_v2 |
| OLD | NEW |