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

Side by Side Diff: components/sync/engine_impl/model_type_worker.cc

Issue 2781863004: [Sync] Implement EstimateMemoryUsage for SharedModelTypeProcessor and ModelTypeWorker (Closed)
Patch Set: Fix lint errors 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/engine_impl/model_type_worker.h" 5 #include "components/sync/engine_impl/model_type_worker.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/format_macros.h" 13 #include "base/format_macros.h"
14 #include "base/guid.h" 14 #include "base/guid.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/trace_event/memory_usage_estimator.h"
19 #include "components/sync/base/time.h" 20 #include "components/sync/base/time.h"
20 #include "components/sync/engine/model_type_processor.h" 21 #include "components/sync/engine/model_type_processor.h"
21 #include "components/sync/engine_impl/commit_contribution.h" 22 #include "components/sync/engine_impl/commit_contribution.h"
22 #include "components/sync/engine_impl/non_blocking_type_commit_contribution.h" 23 #include "components/sync/engine_impl/non_blocking_type_commit_contribution.h"
23 #include "components/sync/engine_impl/worker_entity_tracker.h" 24 #include "components/sync/engine_impl/worker_entity_tracker.h"
25 #include "components/sync/protocol/proto_memory_estimations.h"
24 #include "components/sync/syncable/syncable_util.h" 26 #include "components/sync/syncable/syncable_util.h"
25 27
26 namespace syncer { 28 namespace syncer {
27 29
28 ModelTypeWorker::ModelTypeWorker( 30 ModelTypeWorker::ModelTypeWorker(
29 ModelType type, 31 ModelType type,
30 const sync_pb::ModelTypeState& initial_state, 32 const sync_pb::ModelTypeState& initial_state,
31 bool trigger_initial_sync, 33 bool trigger_initial_sync,
32 std::unique_ptr<Cryptographer> cryptographer, 34 std::unique_ptr<Cryptographer> cryptographer,
33 NudgeHandler* nudge_handler, 35 NudgeHandler* nudge_handler,
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 325
324 void ModelTypeWorker::AbortMigration() { 326 void ModelTypeWorker::AbortMigration() {
325 DCHECK(!model_type_state_.initial_sync_done()); 327 DCHECK(!model_type_state_.initial_sync_done());
326 model_type_state_ = sync_pb::ModelTypeState(); 328 model_type_state_ = sync_pb::ModelTypeState();
327 entities_.clear(); 329 entities_.clear();
328 pending_updates_.clear(); 330 pending_updates_.clear();
329 has_encrypted_updates_ = false; 331 has_encrypted_updates_ = false;
330 nudge_handler_->NudgeForInitialDownload(type_); 332 nudge_handler_->NudgeForInitialDownload(type_);
331 } 333 }
332 334
335 size_t ModelTypeWorker::EstimateMemoryUsage() const {
336 using base::trace_event::EstimateMemoryUsage;
337 size_t memory_usage = 0;
Patrick Noland 2017/03/29 19:42:54 Should cryptographer be included, since the worker
pavely 2017/03/30 01:07:25 I Included fields that can grow arbitrarily large
338 memory_usage += EstimateMemoryUsage(model_type_state_);
339 memory_usage += EstimateMemoryUsage(entities_);
340 memory_usage += EstimateMemoryUsage(pending_updates_);
341 return memory_usage;
342 }
343
333 base::WeakPtr<ModelTypeWorker> ModelTypeWorker::AsWeakPtr() { 344 base::WeakPtr<ModelTypeWorker> ModelTypeWorker::AsWeakPtr() {
334 return weak_ptr_factory_.GetWeakPtr(); 345 return weak_ptr_factory_.GetWeakPtr();
335 } 346 }
336 347
337 bool ModelTypeWorker::IsTypeInitialized() const { 348 bool ModelTypeWorker::IsTypeInitialized() const {
338 return model_type_state_.initial_sync_done() && 349 return model_type_state_.initial_sync_done() &&
339 !model_type_state_.progress_marker().token().empty(); 350 !model_type_state_.progress_marker().token().empty();
340 } 351 }
341 352
342 bool ModelTypeWorker::CanCommitItems() const { 353 bool ModelTypeWorker::CanCommitItems() const {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 return entity_ptr; 488 return entity_ptr;
478 } 489 }
479 490
480 WorkerEntityTracker* ModelTypeWorker::GetOrCreateEntityTracker( 491 WorkerEntityTracker* ModelTypeWorker::GetOrCreateEntityTracker(
481 const EntityData& data) { 492 const EntityData& data) {
482 WorkerEntityTracker* entity = GetEntityTracker(data.client_tag_hash); 493 WorkerEntityTracker* entity = GetEntityTracker(data.client_tag_hash);
483 return entity ? entity : CreateEntityTracker(data); 494 return entity ? entity : CreateEntityTracker(data);
484 } 495 }
485 496
486 } // namespace syncer 497 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698