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

Side by Side Diff: sync/engine/all_status.cc

Issue 10454105: sync: Refactor per-datatype throttling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « sync/engine/all_status.h ('k') | sync/engine/get_commit_ids_command.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/all_status.h" 5 #include "sync/engine/all_status.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/port.h" 10 #include "base/port.h"
11 #include "sync/engine/net/server_connection_manager.h" 11 #include "sync/engine/net/server_connection_manager.h"
12 #include "sync/internal_api/public/syncable/model_type.h" 12 #include "sync/internal_api/public/syncable/model_type.h"
13 #include "sync/sessions/session_state.h" 13 #include "sync/sessions/session_state.h"
14 14
15 namespace browser_sync { 15 namespace browser_sync {
16 16
17 AllStatus::AllStatus() { 17 AllStatus::AllStatus() {
18 status_.initial_sync_ended = true; 18 status_.initial_sync_ended = true;
19 status_.notifications_enabled = false; 19 status_.notifications_enabled = false;
20 status_.cryptographer_ready = false; 20 status_.cryptographer_ready = false;
21 status_.crypto_has_pending_keys = false; 21 status_.crypto_has_pending_keys = false;
22 } 22 }
23 23
24 AllStatus::~AllStatus() { 24 AllStatus::~AllStatus() {
25 } 25 }
26 26
27 sync_api::SyncManager::Status AllStatus::CreateBlankStatus() const { 27 sync_api::SyncStatus AllStatus::CreateBlankStatus() const {
28 // Status is initialized with the previous status value. Variables 28 // Status is initialized with the previous status value. Variables
29 // whose values accumulate (e.g. lifetime counters like updates_received) 29 // whose values accumulate (e.g. lifetime counters like updates_received)
30 // are not to be cleared here. 30 // are not to be cleared here.
31 sync_api::SyncManager::Status status = status_; 31 sync_api::SyncStatus status = status_;
32 status.encryption_conflicts = 0; 32 status.encryption_conflicts = 0;
33 status.hierarchy_conflicts = 0; 33 status.hierarchy_conflicts = 0;
34 status.simple_conflicts = 0; 34 status.simple_conflicts = 0;
35 status.server_conflicts = 0; 35 status.server_conflicts = 0;
36 status.committed_count = 0; 36 status.committed_count = 0;
37 status.initial_sync_ended = false; 37 status.initial_sync_ended = false;
38 status.updates_available = 0; 38 status.updates_available = 0;
39 return status; 39 return status;
40 } 40 }
41 41
42 sync_api::SyncManager::Status AllStatus::CalcSyncing( 42 sync_api::SyncStatus AllStatus::CalcSyncing(
43 const SyncEngineEvent &event) const { 43 const SyncEngineEvent &event) const {
44 sync_api::SyncManager::Status status = CreateBlankStatus(); 44 sync_api::SyncStatus status = CreateBlankStatus();
45 const sessions::SyncSessionSnapshot& snapshot = event.snapshot; 45 const sessions::SyncSessionSnapshot& snapshot = event.snapshot;
46 status.encryption_conflicts = snapshot.num_encryption_conflicts(); 46 status.encryption_conflicts = snapshot.num_encryption_conflicts();
47 status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts(); 47 status.hierarchy_conflicts = snapshot.num_hierarchy_conflicts();
48 status.simple_conflicts = snapshot.num_simple_conflicts(); 48 status.simple_conflicts = snapshot.num_simple_conflicts();
49 status.server_conflicts = snapshot.num_server_conflicts(); 49 status.server_conflicts = snapshot.num_server_conflicts();
50 status.committed_count = snapshot.syncer_status().num_successful_commits; 50 status.committed_count = snapshot.syncer_status().num_successful_commits;
51 51
52 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) { 52 if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_BEGIN) {
53 status.syncing = true; 53 status.syncing = true;
54 } else if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) { 54 } else if (event.what_happened == SyncEngineEvent::SYNC_CYCLE_ENDED) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 case SyncEngineEvent::ACTIONABLE_ERROR: 112 case SyncEngineEvent::ACTIONABLE_ERROR:
113 status_ = CreateBlankStatus(); 113 status_ = CreateBlankStatus();
114 status_.sync_protocol_error = event.snapshot.errors().sync_protocol_error; 114 status_.sync_protocol_error = event.snapshot.errors().sync_protocol_error;
115 break; 115 break;
116 default: 116 default:
117 LOG(ERROR) << "Unrecognized Syncer Event: " << event.what_happened; 117 LOG(ERROR) << "Unrecognized Syncer Event: " << event.what_happened;
118 break; 118 break;
119 } 119 }
120 } 120 }
121 121
122 sync_api::SyncManager::Status AllStatus::status() const { 122 sync_api::SyncStatus AllStatus::status() const {
123 base::AutoLock lock(mutex_); 123 base::AutoLock lock(mutex_);
124 return status_; 124 return status_;
125 } 125 }
126 126
127 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) { 127 void AllStatus::SetNotificationsEnabled(bool notifications_enabled) {
128 ScopedStatusLock lock(this); 128 ScopedStatusLock lock(this);
129 status_.notifications_enabled = notifications_enabled; 129 status_.notifications_enabled = notifications_enabled;
130 } 130 }
131 131
132 void AllStatus::IncrementNotificationsReceived() { 132 void AllStatus::IncrementNotificationsReceived() {
133 ScopedStatusLock lock(this); 133 ScopedStatusLock lock(this);
134 ++status_.notifications_received; 134 ++status_.notifications_received;
135 } 135 }
136 136
137 void AllStatus::SetEncryptedTypes(syncable::ModelTypeSet types) { 137 void AllStatus::SetEncryptedTypes(syncable::ModelTypeSet types) {
138 ScopedStatusLock lock(this); 138 ScopedStatusLock lock(this);
139 status_.encrypted_types = types; 139 status_.encrypted_types = types;
140 } 140 }
141 141
142 void AllStatus::SetThrottledTypes(const syncable::ModelTypeSet& types) {
143 ScopedStatusLock lock(this);
144 status_.throttled_types = types;
145 }
146
142 void AllStatus::SetCryptographerReady(bool ready) { 147 void AllStatus::SetCryptographerReady(bool ready) {
143 ScopedStatusLock lock(this); 148 ScopedStatusLock lock(this);
144 status_.cryptographer_ready = ready; 149 status_.cryptographer_ready = ready;
145 } 150 }
146 151
147 void AllStatus::SetCryptoHasPendingKeys(bool has_pending_keys) { 152 void AllStatus::SetCryptoHasPendingKeys(bool has_pending_keys) {
148 ScopedStatusLock lock(this); 153 ScopedStatusLock lock(this);
149 status_.crypto_has_pending_keys = has_pending_keys; 154 status_.crypto_has_pending_keys = has_pending_keys;
150 } 155 }
151 156
152 void AllStatus::SetUniqueId(const std::string& guid) { 157 void AllStatus::SetUniqueId(const std::string& guid) {
153 ScopedStatusLock lock(this); 158 ScopedStatusLock lock(this);
154 status_.unique_id = guid; 159 status_.unique_id = guid;
155 } 160 }
156 161
157 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus) 162 ScopedStatusLock::ScopedStatusLock(AllStatus* allstatus)
158 : allstatus_(allstatus) { 163 : allstatus_(allstatus) {
159 allstatus->mutex_.Acquire(); 164 allstatus->mutex_.Acquire();
160 } 165 }
161 166
162 ScopedStatusLock::~ScopedStatusLock() { 167 ScopedStatusLock::~ScopedStatusLock() {
163 allstatus_->mutex_.Release(); 168 allstatus_->mutex_.Release();
164 } 169 }
165 170
166 } // namespace browser_sync 171 } // namespace browser_sync
OLDNEW
« no previous file with comments | « sync/engine/all_status.h ('k') | sync/engine/get_commit_ids_command.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698