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

Side by Side Diff: chrome/browser/sync/glue/data_type_manager_impl.cc

Issue 7669073: [Sync] Add support for enabling session sync remotely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DOUBLE R..ebase Created 9 years, 3 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/glue/data_type_manager_impl.h" 5 #include "chrome/browser/sync/glue/data_type_manager_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 return (*order_)[lhs->type()] < (*order_)[rhs->type()]; 57 return (*order_)[lhs->type()] < (*order_)[rhs->type()];
58 } 58 }
59 59
60 private: 60 private:
61 std::map<syncable::ModelType, int>* order_; 61 std::map<syncable::ModelType, int>* order_;
62 }; 62 };
63 63
64 } // namespace 64 } // namespace
65 65
66 DataTypeManagerImpl::DataTypeManagerImpl(SyncBackendHost* backend, 66 DataTypeManagerImpl::DataTypeManagerImpl(SyncBackendHost* backend,
67 const DataTypeController::TypeMap& controllers) 67 const DataTypeController::TypeMap* controllers)
68 : backend_(backend), 68 : backend_(backend),
69 controllers_(controllers), 69 controllers_(controllers),
70 state_(DataTypeManager::STOPPED), 70 state_(DataTypeManager::STOPPED),
71 needs_reconfigure_(false), 71 needs_reconfigure_(false),
72 last_configure_reason_(sync_api::CONFIGURE_REASON_UNKNOWN), 72 last_configure_reason_(sync_api::CONFIGURE_REASON_UNKNOWN),
73 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 73 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
74 DCHECK(backend_); 74 DCHECK(backend_);
75 // Ensure all data type controllers are stopped. 75 // Ensure all data type controllers are stopped.
76 for (DataTypeController::TypeMap::const_iterator it = controllers_.begin(); 76 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin();
77 it != controllers_.end(); ++it) { 77 it != controllers_->end(); ++it) {
78 DCHECK_EQ(DataTypeController::NOT_RUNNING, (*it).second->state()); 78 DCHECK_EQ(DataTypeController::NOT_RUNNING, (*it).second->state());
79 } 79 }
80 80
81 // Build a ModelType -> order map for sorting. 81 // Build a ModelType -> order map for sorting.
82 for (int i = 0; i < static_cast<int>(arraysize(kStartOrder)); i++) 82 for (int i = 0; i < static_cast<int>(arraysize(kStartOrder)); i++)
83 start_order_[kStartOrder[i]] = i; 83 start_order_[kStartOrder[i]] = i;
84 } 84 }
85 85
86 DataTypeManagerImpl::~DataTypeManagerImpl() {} 86 DataTypeManagerImpl::~DataTypeManagerImpl() {}
87 87
88 bool DataTypeManagerImpl::GetControllersNeedingStart( 88 bool DataTypeManagerImpl::GetControllersNeedingStart(
89 std::vector<DataTypeController*>* needs_start) { 89 std::vector<DataTypeController*>* needs_start) {
90 // Add any data type controllers into the needs_start_ list that are 90 // Add any data type controllers into the needs_start_ list that are
91 // currently NOT_RUNNING or STOPPING. 91 // currently NOT_RUNNING or STOPPING.
92 bool found_any = false; 92 bool found_any = false;
93 for (TypeSet::const_iterator it = last_requested_types_.begin(); 93 for (TypeSet::const_iterator it = last_requested_types_.begin();
94 it != last_requested_types_.end(); ++it) { 94 it != last_requested_types_.end(); ++it) {
95 DataTypeController::TypeMap::const_iterator dtc = controllers_.find(*it); 95 DataTypeController::TypeMap::const_iterator dtc = controllers_->find(*it);
96 if (dtc != controllers_.end() && 96 if (dtc != controllers_->end() &&
97 (dtc->second->state() == DataTypeController::NOT_RUNNING || 97 (dtc->second->state() == DataTypeController::NOT_RUNNING ||
98 dtc->second->state() == DataTypeController::STOPPING)) { 98 dtc->second->state() == DataTypeController::STOPPING)) {
99 found_any = true; 99 found_any = true;
100 if (needs_start) 100 if (needs_start)
101 needs_start->push_back(dtc->second.get()); 101 needs_start->push_back(dtc->second.get());
102 } 102 }
103 } 103 }
104 return found_any; 104 return found_any;
105 } 105 }
106 106
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 needs_start_.clear(); 156 needs_start_.clear();
157 GetControllersNeedingStart(&needs_start_); 157 GetControllersNeedingStart(&needs_start_);
158 // Sort these according to kStartOrder. 158 // Sort these according to kStartOrder.
159 std::sort(needs_start_.begin(), 159 std::sort(needs_start_.begin(),
160 needs_start_.end(), 160 needs_start_.end(),
161 SortComparator(&start_order_)); 161 SortComparator(&start_order_));
162 162
163 // Add any data type controllers into that needs_stop_ list that are 163 // Add any data type controllers into that needs_stop_ list that are
164 // currently MODEL_STARTING, ASSOCIATING, or RUNNING. 164 // currently MODEL_STARTING, ASSOCIATING, or RUNNING.
165 needs_stop_.clear(); 165 needs_stop_.clear();
166 for (DataTypeController::TypeMap::const_iterator it = controllers_.begin(); 166 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin();
167 it != controllers_.end(); ++it) { 167 it != controllers_->end(); ++it) {
168 DataTypeController* dtc = (*it).second; 168 DataTypeController* dtc = (*it).second;
169 if (desired_types.count(dtc->type()) == 0 && ( 169 if (desired_types.count(dtc->type()) == 0 && (
170 dtc->state() == DataTypeController::MODEL_STARTING || 170 dtc->state() == DataTypeController::MODEL_STARTING ||
171 dtc->state() == DataTypeController::ASSOCIATING || 171 dtc->state() == DataTypeController::ASSOCIATING ||
172 dtc->state() == DataTypeController::RUNNING)) { 172 dtc->state() == DataTypeController::RUNNING)) {
173 needs_stop_.push_back(dtc); 173 needs_stop_.push_back(dtc);
174 VLOG(1) << "Will stop " << dtc->name(); 174 VLOG(1) << "Will stop " << dtc->name();
175 } 175 }
176 } 176 }
177 // Sort these according to kStartOrder. 177 // Sort these according to kStartOrder.
(...skipping 29 matching lines...) Expand all
207 needs_stop_.clear(); 207 needs_stop_.clear();
208 208
209 // Tell the backend about the new set of data types we wish to sync. 209 // Tell the backend about the new set of data types we wish to sync.
210 // The task will be invoked when updates are downloaded. 210 // The task will be invoked when updates are downloaded.
211 state_ = DOWNLOAD_PENDING; 211 state_ = DOWNLOAD_PENDING;
212 // Hopefully http://crbug.com/79970 will make this less verbose. 212 // Hopefully http://crbug.com/79970 will make this less verbose.
213 syncable::ModelTypeSet all_types; 213 syncable::ModelTypeSet all_types;
214 const syncable::ModelTypeSet& types_to_add = last_requested_types_; 214 const syncable::ModelTypeSet& types_to_add = last_requested_types_;
215 syncable::ModelTypeSet types_to_remove; 215 syncable::ModelTypeSet types_to_remove;
216 for (DataTypeController::TypeMap::const_iterator it = 216 for (DataTypeController::TypeMap::const_iterator it =
217 controllers_.begin(); it != controllers_.end(); ++it) { 217 controllers_->begin(); it != controllers_->end(); ++it) {
218 all_types.insert(it->first); 218 all_types.insert(it->first);
219 } 219 }
220 // Check that types_to_add \subseteq all_types. 220 // Check that types_to_add \subseteq all_types.
221 DCHECK(std::includes(all_types.begin(), all_types.end(), 221 DCHECK(std::includes(all_types.begin(), all_types.end(),
222 types_to_add.begin(), types_to_add.end())); 222 types_to_add.begin(), types_to_add.end()));
223 // Set types_to_remove to all_types \setminus types_to_add. 223 // Set types_to_remove to all_types \setminus types_to_add.
224 ignore_result( 224 ignore_result(
225 std::set_difference( 225 std::set_difference(
226 all_types.begin(), all_types.end(), 226 all_types.begin(), all_types.end(),
227 types_to_add.begin(), types_to_add.end(), 227 types_to_add.begin(), types_to_add.end(),
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 return; 399 return;
400 } 400 }
401 401
402 FinishStop(); 402 FinishStop();
403 } 403 }
404 404
405 void DataTypeManagerImpl::FinishStop() { 405 void DataTypeManagerImpl::FinishStop() {
406 DCHECK(state_== CONFIGURING || state_ == STOPPING || state_ == BLOCKED || 406 DCHECK(state_== CONFIGURING || state_ == STOPPING || state_ == BLOCKED ||
407 state_ == DOWNLOAD_PENDING); 407 state_ == DOWNLOAD_PENDING);
408 // Simply call the Stop() method on all running data types. 408 // Simply call the Stop() method on all running data types.
409 for (DataTypeController::TypeMap::const_iterator it = controllers_.begin(); 409 for (DataTypeController::TypeMap::const_iterator it = controllers_->begin();
410 it != controllers_.end(); ++it) { 410 it != controllers_->end(); ++it) {
411 DataTypeController* dtc = (*it).second; 411 DataTypeController* dtc = (*it).second;
412 if (dtc->state() != DataTypeController::NOT_RUNNING && 412 if (dtc->state() != DataTypeController::NOT_RUNNING &&
413 dtc->state() != DataTypeController::STOPPING) { 413 dtc->state() != DataTypeController::STOPPING) {
414 dtc->Stop(); 414 dtc->Stop();
415 VLOG(1) << "Stopped " << dtc->name(); 415 VLOG(1) << "Stopped " << dtc->name();
416 } 416 }
417 } 417 }
418 state_ = STOPPED; 418 state_ = STOPPED;
419 } 419 }
420 420
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 default: 470 default:
471 NOTREACHED(); 471 NOTREACHED();
472 break; 472 break;
473 } 473 }
474 NotificationService::current()->Notify( 474 NotificationService::current()->Notify(
475 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, 475 chrome::NOTIFICATION_SYNC_CONFIGURE_DONE,
476 Source<DataTypeManager>(this), 476 Source<DataTypeManager>(this),
477 Details<const ConfigureResult>(&result)); 477 Details<const ConfigureResult>(&result));
478 } 478 }
479 479
480 const DataTypeController::TypeMap& DataTypeManagerImpl::controllers() {
481 return controllers_;
482 }
483
484 DataTypeManager::State DataTypeManagerImpl::state() { 480 DataTypeManager::State DataTypeManagerImpl::state() {
485 return state_; 481 return state_;
486 } 482 }
487 483
488 void DataTypeManagerImpl::SetBlockedAndNotify() { 484 void DataTypeManagerImpl::SetBlockedAndNotify() {
489 state_ = BLOCKED; 485 state_ = BLOCKED;
490 AddToConfigureTime(); 486 AddToConfigureTime();
491 VLOG(1) << "Accumulated spent configuring: " 487 VLOG(1) << "Accumulated spent configuring: "
492 << configure_time_delta_.InSecondsF() << "s"; 488 << configure_time_delta_.InSecondsF() << "s";
493 NotificationService::current()->Notify( 489 NotificationService::current()->Notify(
494 chrome::NOTIFICATION_SYNC_CONFIGURE_BLOCKED, 490 chrome::NOTIFICATION_SYNC_CONFIGURE_BLOCKED,
495 Source<DataTypeManager>(this), 491 Source<DataTypeManager>(this),
496 NotificationService::NoDetails()); 492 NotificationService::NoDetails());
497 } 493 }
498 494
499 void DataTypeManagerImpl::AddToConfigureTime() { 495 void DataTypeManagerImpl::AddToConfigureTime() {
500 DCHECK(!last_restart_time_.is_null()); 496 DCHECK(!last_restart_time_.is_null());
501 configure_time_delta_ += (base::Time::Now() - last_restart_time_); 497 configure_time_delta_ += (base::Time::Now() - last_restart_time_);
502 } 498 }
503 499
504 } // namespace browser_sync 500 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/data_type_manager_impl.h ('k') | chrome/browser/sync/glue/data_type_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698