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

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

Issue 1835953002: [Sync] USS: Filter out redundant changes in SMTP. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use data var. 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 {
19
20 void HashSpecifics(const sync_pb::EntitySpecifics& specifics,
21 std::string* hash) {
22 std::string hash_input;
23 specifics.AppendToString(&hash_input);
skym 2016/03/28 22:35:38 Why not use SerializeAsString() inline?
maxbogue 2016/03/29 00:32:09 Because I was just copying from UpdateSpecificsHas
24 base::Base64Encode(base::SHA1HashString(hash_input), hash);
25 }
26
27 } // namespace
28
18 scoped_ptr<ProcessorEntityTracker> ProcessorEntityTracker::CreateNew( 29 scoped_ptr<ProcessorEntityTracker> ProcessorEntityTracker::CreateNew(
19 const std::string& client_tag, 30 const std::string& client_tag,
20 const std::string& client_tag_hash, 31 const std::string& client_tag_hash,
21 const std::string& id, 32 const std::string& id,
22 base::Time creation_time) { 33 base::Time creation_time) {
23 // Initialize metadata 34 // Initialize metadata
24 sync_pb::EntityMetadata metadata; 35 sync_pb::EntityMetadata metadata;
25 metadata.set_client_tag_hash(client_tag_hash); 36 metadata.set_client_tag_hash(client_tag_hash);
26 if (!id.empty()) 37 if (!id.empty())
27 metadata.set_server_id(id); 38 metadata.set_server_id(id);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 data->client_tag_hash = metadata_.client_tag_hash(); 70 data->client_tag_hash = metadata_.client_tag_hash();
60 } 71 }
61 commit_data_ = data->PassToPtr(); 72 commit_data_ = data->PassToPtr();
62 DCHECK(HasCommitData()); 73 DCHECK(HasCommitData());
63 } 74 }
64 75
65 bool ProcessorEntityTracker::HasCommitData() const { 76 bool ProcessorEntityTracker::HasCommitData() const {
66 return !commit_data_->client_tag_hash.empty(); 77 return !commit_data_->client_tag_hash.empty();
67 } 78 }
68 79
80 bool ProcessorEntityTracker::MatchesSpecificsHash(
81 const sync_pb::EntitySpecifics& specifics) const {
82 if (specifics.ByteSize() > 0) {
83 std::string hash;
84 HashSpecifics(specifics, &hash);
85 return hash == metadata_.specifics_hash();
86 } else {
87 return !metadata_.has_specifics_hash();
skym 2016/03/28 22:35:38 What's the reason for this special logic? We don't
maxbogue 2016/03/29 00:32:09 Hmm... doesn't seem very important. It should be f
maxbogue 2016/03/29 01:02:05 Update: not below, apparently the logic doesn't re
88 }
89 }
90
69 bool ProcessorEntityTracker::IsUnsynced() const { 91 bool ProcessorEntityTracker::IsUnsynced() const {
70 return metadata_.sequence_number() > metadata_.acked_sequence_number(); 92 return metadata_.sequence_number() > metadata_.acked_sequence_number();
71 } 93 }
72 94
73 bool ProcessorEntityTracker::RequiresCommitRequest() const { 95 bool ProcessorEntityTracker::RequiresCommitRequest() const {
74 return metadata_.sequence_number() > commit_requested_sequence_number_; 96 return metadata_.sequence_number() > commit_requested_sequence_number_;
75 } 97 }
76 98
77 bool ProcessorEntityTracker::RequiresCommitData() const { 99 bool ProcessorEntityTracker::RequiresCommitData() const {
78 return RequiresCommitRequest() && !HasCommitData() && !metadata_.is_deleted(); 100 return RequiresCommitRequest() && !HasCommitData() && !metadata_.is_deleted();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 218
197 void ProcessorEntityTracker::IncrementSequenceNumber() { 219 void ProcessorEntityTracker::IncrementSequenceNumber() {
198 DCHECK(metadata_.has_sequence_number()); 220 DCHECK(metadata_.has_sequence_number());
199 metadata_.set_sequence_number(metadata_.sequence_number() + 1); 221 metadata_.set_sequence_number(metadata_.sequence_number() + 1);
200 } 222 }
201 223
202 // Update hash string for EntitySpecifics. 224 // Update hash string for EntitySpecifics.
203 void ProcessorEntityTracker::UpdateSpecificsHash( 225 void ProcessorEntityTracker::UpdateSpecificsHash(
204 const sync_pb::EntitySpecifics& specifics) { 226 const sync_pb::EntitySpecifics& specifics) {
205 if (specifics.ByteSize() > 0) { 227 if (specifics.ByteSize() > 0) {
206 std::string hash_input; 228 HashSpecifics(specifics, metadata_.mutable_specifics_hash());
207 specifics.AppendToString(&hash_input);
208 base::Base64Encode(base::SHA1HashString(hash_input),
209 metadata_.mutable_specifics_hash());
210 } else { 229 } else {
211 metadata_.clear_specifics_hash(); 230 metadata_.clear_specifics_hash();
212 } 231 }
213 } 232 }
214 233
215 } // namespace syncer_v2 234 } // namespace syncer_v2
OLDNEW
« no previous file with comments | « no previous file | sync/internal_api/public/processor_entity_tracker.h » ('j') | sync/internal_api/shared_model_type_processor.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698