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

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

Issue 2781863004: [Sync] Implement EstimateMemoryUsage for SharedModelTypeProcessor and ModelTypeWorker (Closed)
Patch Set: Address comments Created 3 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 "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 "components/sync/base/time.h" 10 #include "components/sync/base/time.h"
10 #include "components/sync/engine/non_blocking_sync_common.h" 11 #include "components/sync/engine/non_blocking_sync_common.h"
12 #include "components/sync/protocol/proto_memory_estimations.h"
11 13
12 namespace syncer { 14 namespace syncer {
13 15
14 namespace { 16 namespace {
15 17
16 void HashSpecifics(const sync_pb::EntitySpecifics& specifics, 18 void HashSpecifics(const sync_pb::EntitySpecifics& specifics,
17 std::string* hash) { 19 std::string* hash) {
18 DCHECK_GT(specifics.ByteSize(), 0); 20 DCHECK_GT(specifics.ByteSize(), 0);
19 base::Base64Encode(base::SHA1HashString(specifics.SerializeAsString()), hash); 21 base::Base64Encode(base::SHA1HashString(specifics.SerializeAsString()), hash);
20 } 22 }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 234
233 void ProcessorEntityTracker::IncrementSequenceNumber() { 235 void ProcessorEntityTracker::IncrementSequenceNumber() {
234 DCHECK(metadata_.has_sequence_number()); 236 DCHECK(metadata_.has_sequence_number());
235 if (!IsUnsynced()) { 237 if (!IsUnsynced()) {
236 // Update the base specifics hash if this entity wasn't already out of sync. 238 // Update the base specifics hash if this entity wasn't already out of sync.
237 metadata_.set_base_specifics_hash(metadata_.specifics_hash()); 239 metadata_.set_base_specifics_hash(metadata_.specifics_hash());
238 } 240 }
239 metadata_.set_sequence_number(metadata_.sequence_number() + 1); 241 metadata_.set_sequence_number(metadata_.sequence_number() + 1);
240 } 242 }
241 243
244 size_t ProcessorEntityTracker::EstimateMemoryUsage() const {
245 using base::trace_event::EstimateMemoryUsage;
246 size_t memory_usage = 0;
247 memory_usage += EstimateMemoryUsage(storage_key_);
248 memory_usage += EstimateMemoryUsage(metadata_);
249 memory_usage += EstimateMemoryUsage(commit_data_);
250 return memory_usage;
251 }
252
242 bool ProcessorEntityTracker::MatchesSpecificsHash( 253 bool ProcessorEntityTracker::MatchesSpecificsHash(
243 const sync_pb::EntitySpecifics& specifics) const { 254 const sync_pb::EntitySpecifics& specifics) const {
244 DCHECK(!metadata_.is_deleted()); 255 DCHECK(!metadata_.is_deleted());
245 std::string hash; 256 std::string hash;
246 HashSpecifics(specifics, &hash); 257 HashSpecifics(specifics, &hash);
247 return hash == metadata_.specifics_hash(); 258 return hash == metadata_.specifics_hash();
248 } 259 }
249 260
250 void ProcessorEntityTracker::UpdateSpecificsHash( 261 void ProcessorEntityTracker::UpdateSpecificsHash(
251 const sync_pb::EntitySpecifics& specifics) { 262 const sync_pb::EntitySpecifics& specifics) {
252 if (specifics.ByteSize() > 0) { 263 if (specifics.ByteSize() > 0) {
253 HashSpecifics(specifics, metadata_.mutable_specifics_hash()); 264 HashSpecifics(specifics, metadata_.mutable_specifics_hash());
254 } else { 265 } else {
255 metadata_.clear_specifics_hash(); 266 metadata_.clear_specifics_hash();
256 } 267 }
257 } 268 }
258 269
259 } // namespace syncer 270 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/model_impl/processor_entity_tracker.h ('k') | components/sync/model_impl/shared_model_type_processor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698