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/engine_impl/worker_entity_tracker.h" | 5 #include "components/sync/engine_impl/worker_entity_tracker.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/trace_event/memory_usage_estimator.h" |
11 #include "components/sync/base/model_type.h" | 12 #include "components/sync/base/model_type.h" |
12 #include "components/sync/base/time.h" | 13 #include "components/sync/base/time.h" |
13 #include "components/sync/syncable/syncable_util.h" | 14 #include "components/sync/syncable/syncable_util.h" |
14 | 15 |
15 namespace syncer { | 16 namespace syncer { |
16 | 17 |
17 WorkerEntityTracker::WorkerEntityTracker(const std::string& client_tag_hash) | 18 WorkerEntityTracker::WorkerEntityTracker(const std::string& client_tag_hash) |
18 : client_tag_hash_(client_tag_hash) { | 19 : client_tag_hash_(client_tag_hash) { |
19 DCHECK(!client_tag_hash_.empty()); | 20 DCHECK(!client_tag_hash_.empty()); |
20 } | 21 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 } | 171 } |
171 | 172 |
172 UpdateResponseData WorkerEntityTracker::GetEncryptedUpdate() const { | 173 UpdateResponseData WorkerEntityTracker::GetEncryptedUpdate() const { |
173 return *encrypted_update_; | 174 return *encrypted_update_; |
174 } | 175 } |
175 | 176 |
176 void WorkerEntityTracker::ClearEncryptedUpdate() { | 177 void WorkerEntityTracker::ClearEncryptedUpdate() { |
177 encrypted_update_.reset(); | 178 encrypted_update_.reset(); |
178 } | 179 } |
179 | 180 |
| 181 size_t WorkerEntityTracker::EstimateMemoryUsage() const { |
| 182 using base::trace_event::EstimateMemoryUsage; |
| 183 size_t memory_usage = 0; |
| 184 memory_usage += EstimateMemoryUsage(client_tag_hash_); |
| 185 memory_usage += EstimateMemoryUsage(id_); |
| 186 memory_usage += sizeof(sequence_number_); |
| 187 memory_usage += sizeof(base_version_); |
| 188 memory_usage += sizeof(highest_commit_response_version_); |
| 189 memory_usage += sizeof(highest_gu_response_version_); |
| 190 memory_usage += EstimateMemoryUsage(pending_commit_); |
| 191 memory_usage += EstimateMemoryUsage(pending_commit_specifics_hash_); |
| 192 memory_usage += EstimateMemoryUsage(encrypted_update_); |
| 193 return memory_usage; |
| 194 } |
| 195 |
180 bool WorkerEntityTracker::IsInConflict() const { | 196 bool WorkerEntityTracker::IsInConflict() const { |
181 if (!HasPendingCommit()) | 197 if (!HasPendingCommit()) |
182 return false; | 198 return false; |
183 | 199 |
184 if (HasEncryptedUpdate()) | 200 if (HasEncryptedUpdate()) |
185 return true; | 201 return true; |
186 | 202 |
187 if (highest_gu_response_version_ <= highest_commit_response_version_) { | 203 if (highest_gu_response_version_ <= highest_commit_response_version_) { |
188 // The most recent server state was created in a commit made by this | 204 // The most recent server state was created in a commit made by this |
189 // client. We're fully up to date, and therefore not in conflict. | 205 // client. We're fully up to date, and therefore not in conflict. |
(...skipping 13 matching lines...) Expand all Loading... |
203 bool WorkerEntityTracker::IsServerKnown() const { | 219 bool WorkerEntityTracker::IsServerKnown() const { |
204 return base_version_ != kUncommittedVersion; | 220 return base_version_ != kUncommittedVersion; |
205 } | 221 } |
206 | 222 |
207 void WorkerEntityTracker::ClearPendingCommit() { | 223 void WorkerEntityTracker::ClearPendingCommit() { |
208 pending_commit_.reset(); | 224 pending_commit_.reset(); |
209 pending_commit_specifics_hash_.clear(); | 225 pending_commit_specifics_hash_.clear(); |
210 } | 226 } |
211 | 227 |
212 } // namespace syncer | 228 } // namespace syncer |
OLD | NEW |