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

Side by Side Diff: sync/internal_api/sync_manager_impl.cc

Issue 451743002: Pass args to SyncManager::Init via a struct. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use scoped_ptr instead of raw pointer. Created 6 years, 4 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/internal_api/sync_manager_impl.h ('k') | sync/internal_api/sync_manager_impl_unittest.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/sync_manager_impl.h" 5 #include "sync/internal_api/sync_manager_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 ConfigurationParams params(GetSourceFromReason(reason), 296 ConfigurationParams params(GetSourceFromReason(reason),
297 to_download, 297 to_download,
298 new_routing_info, 298 new_routing_info,
299 ready_task, 299 ready_task,
300 retry_task); 300 retry_task);
301 301
302 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); 302 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE);
303 scheduler_->ScheduleConfiguration(params); 303 scheduler_->ScheduleConfiguration(params);
304 } 304 }
305 305
306 void SyncManagerImpl::Init( 306 void SyncManagerImpl::Init(InitArgs* args) {
307 const base::FilePath& database_location,
308 const WeakHandle<JsEventHandler>& event_handler,
309 const GURL& service_url,
310 scoped_ptr<HttpPostProviderFactory> post_factory,
311 const std::vector<scoped_refptr<ModelSafeWorker> >& workers,
312 ExtensionsActivity* extensions_activity,
313 SyncManager::ChangeDelegate* change_delegate,
314 const SyncCredentials& credentials,
315 const std::string& invalidator_client_id,
316 const std::string& restored_key_for_bootstrapping,
317 const std::string& restored_keystore_key_for_bootstrapping,
318 InternalComponentsFactory* internal_components_factory,
319 Encryptor* encryptor,
320 scoped_ptr<UnrecoverableErrorHandler> unrecoverable_error_handler,
321 ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
322 CancelationSignal* cancelation_signal) {
323 CHECK(!initialized_); 307 CHECK(!initialized_);
324 DCHECK(thread_checker_.CalledOnValidThread()); 308 DCHECK(thread_checker_.CalledOnValidThread());
325 DCHECK(post_factory.get()); 309 DCHECK(args->post_factory.get());
326 DCHECK(!credentials.email.empty()); 310 DCHECK(!args->credentials.email.empty());
327 DCHECK(!credentials.sync_token.empty()); 311 DCHECK(!args->credentials.sync_token.empty());
328 DCHECK(!credentials.scope_set.empty()); 312 DCHECK(!args->credentials.scope_set.empty());
329 DCHECK(cancelation_signal); 313 DCHECK(args->cancelation_signal);
330 DVLOG(1) << "SyncManager starting Init..."; 314 DVLOG(1) << "SyncManager starting Init...";
331 315
332 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()); 316 weak_handle_this_ = MakeWeakHandle(weak_ptr_factory_.GetWeakPtr());
333 317
334 change_delegate_ = change_delegate; 318 change_delegate_ = args->change_delegate;
335 319
336 AddObserver(&js_sync_manager_observer_); 320 AddObserver(&js_sync_manager_observer_);
337 SetJsEventHandler(event_handler); 321 SetJsEventHandler(args->event_handler);
338 322
339 AddObserver(&debug_info_event_listener_); 323 AddObserver(&debug_info_event_listener_);
340 324
341 database_path_ = database_location.Append( 325 database_path_ = args->database_location.Append(
342 syncable::Directory::kSyncDatabaseFilename); 326 syncable::Directory::kSyncDatabaseFilename);
343 unrecoverable_error_handler_ = unrecoverable_error_handler.Pass(); 327 unrecoverable_error_handler_ = args->unrecoverable_error_handler.Pass();
344 report_unrecoverable_error_function_ = report_unrecoverable_error_function; 328 report_unrecoverable_error_function_ =
329 args->report_unrecoverable_error_function;
345 330
346 allstatus_.SetHasKeystoreKey( 331 allstatus_.SetHasKeystoreKey(
347 !restored_keystore_key_for_bootstrapping.empty()); 332 !args->restored_keystore_key_for_bootstrapping.empty());
348 sync_encryption_handler_.reset(new SyncEncryptionHandlerImpl( 333 sync_encryption_handler_.reset(new SyncEncryptionHandlerImpl(
349 &share_, 334 &share_,
350 encryptor, 335 args->encryptor,
351 restored_key_for_bootstrapping, 336 args->restored_key_for_bootstrapping,
352 restored_keystore_key_for_bootstrapping)); 337 args->restored_keystore_key_for_bootstrapping));
353 sync_encryption_handler_->AddObserver(this); 338 sync_encryption_handler_->AddObserver(this);
354 sync_encryption_handler_->AddObserver(&debug_info_event_listener_); 339 sync_encryption_handler_->AddObserver(&debug_info_event_listener_);
355 sync_encryption_handler_->AddObserver(&js_sync_encryption_handler_observer_); 340 sync_encryption_handler_->AddObserver(&js_sync_encryption_handler_observer_);
356 341
357 base::FilePath absolute_db_path = database_path_; 342 base::FilePath absolute_db_path = database_path_;
358 DCHECK(absolute_db_path.IsAbsolute()); 343 DCHECK(absolute_db_path.IsAbsolute());
359 344
360 scoped_ptr<syncable::DirectoryBackingStore> backing_store = 345 scoped_ptr<syncable::DirectoryBackingStore> backing_store =
361 internal_components_factory->BuildDirectoryBackingStore( 346 args->internal_components_factory->BuildDirectoryBackingStore(
362 credentials.email, absolute_db_path).Pass(); 347 args->credentials.email,
348 absolute_db_path).Pass();
363 349
364 DCHECK(backing_store.get()); 350 DCHECK(backing_store.get());
365 share_.directory.reset( 351 share_.directory.reset(
366 new syncable::Directory( 352 new syncable::Directory(
367 backing_store.release(), 353 backing_store.release(),
368 unrecoverable_error_handler_.get(), 354 unrecoverable_error_handler_.get(),
369 report_unrecoverable_error_function_, 355 report_unrecoverable_error_function_,
370 sync_encryption_handler_.get(), 356 sync_encryption_handler_.get(),
371 sync_encryption_handler_->GetCryptographerUnsafe())); 357 sync_encryption_handler_->GetCryptographerUnsafe()));
372 share_.sync_credentials = credentials; 358 share_.sync_credentials = args->credentials;
373 359
374 // UserShare is accessible to a lot of code that doesn't need access to the 360 // UserShare is accessible to a lot of code that doesn't need access to the
375 // sync token so clear sync_token from the UserShare. 361 // sync token so clear sync_token from the UserShare.
376 share_.sync_credentials.sync_token = ""; 362 share_.sync_credentials.sync_token = "";
377 363
378 const std::string& username = credentials.email; 364 const std::string& username = args->credentials.email;
379 DVLOG(1) << "Username: " << username; 365 DVLOG(1) << "Username: " << username;
380 if (!OpenDirectory(username)) { 366 if (!OpenDirectory(username)) {
381 NotifyInitializationFailure(); 367 NotifyInitializationFailure();
382 LOG(ERROR) << "Sync manager initialization failed!"; 368 LOG(ERROR) << "Sync manager initialization failed!";
383 return; 369 return;
384 } 370 }
385 371
386 connection_manager_.reset(new SyncAPIServerConnectionManager( 372 connection_manager_.reset(new SyncAPIServerConnectionManager(
387 service_url.host() + service_url.path(), 373 args->service_url.host() + args->service_url.path(),
388 service_url.EffectiveIntPort(), 374 args->service_url.EffectiveIntPort(),
389 service_url.SchemeIsSecure(), 375 args->service_url.SchemeIsSecure(),
390 post_factory.release(), 376 args->post_factory.release(),
391 cancelation_signal)); 377 args->cancelation_signal));
392 connection_manager_->set_client_id(directory()->cache_guid()); 378 connection_manager_->set_client_id(directory()->cache_guid());
393 connection_manager_->AddListener(this); 379 connection_manager_->AddListener(this);
394 380
395 std::string sync_id = directory()->cache_guid(); 381 std::string sync_id = directory()->cache_guid();
396 382
397 DVLOG(1) << "Setting sync client ID: " << sync_id; 383 DVLOG(1) << "Setting sync client ID: " << sync_id;
398 allstatus_.SetSyncId(sync_id); 384 allstatus_.SetSyncId(sync_id);
399 DVLOG(1) << "Setting invalidator client ID: " << invalidator_client_id; 385 DVLOG(1) << "Setting invalidator client ID: " << args->invalidator_client_id;
400 allstatus_.SetInvalidatorClientId(invalidator_client_id); 386 allstatus_.SetInvalidatorClientId(args->invalidator_client_id);
401 387
402 model_type_registry_.reset(new ModelTypeRegistry(workers, directory(), this)); 388 model_type_registry_.reset(
389 new ModelTypeRegistry(args->workers, directory(), this));
403 390
404 // Bind the SyncContext WeakPtr to this thread. This helps us crash earlier 391 // Bind the SyncContext WeakPtr to this thread. This helps us crash earlier
405 // if the pointer is misused in debug mode. 392 // if the pointer is misused in debug mode.
406 base::WeakPtr<SyncContext> weak_core = model_type_registry_->AsWeakPtr(); 393 base::WeakPtr<SyncContext> weak_core = model_type_registry_->AsWeakPtr();
407 weak_core.get(); 394 weak_core.get();
408 395
409 sync_context_proxy_.reset( 396 sync_context_proxy_.reset(
410 new SyncContextProxyImpl(base::ThreadTaskRunnerHandle::Get(), weak_core)); 397 new SyncContextProxyImpl(base::ThreadTaskRunnerHandle::Get(), weak_core));
411 398
412 // Build a SyncSessionContext and store the worker in it. 399 // Build a SyncSessionContext and store the worker in it.
413 DVLOG(1) << "Sync is bringing up SyncSessionContext."; 400 DVLOG(1) << "Sync is bringing up SyncSessionContext.";
414 std::vector<SyncEngineEventListener*> listeners; 401 std::vector<SyncEngineEventListener*> listeners;
415 listeners.push_back(&allstatus_); 402 listeners.push_back(&allstatus_);
416 listeners.push_back(this); 403 listeners.push_back(this);
417 session_context_ = internal_components_factory->BuildContext( 404 session_context_ =
418 connection_manager_.get(), 405 args->internal_components_factory->BuildContext(
419 directory(), 406 connection_manager_.get(),
420 extensions_activity, 407 directory(),
421 listeners, 408 args->extensions_activity,
422 &debug_info_event_listener_, 409 listeners,
423 model_type_registry_.get(), 410 &debug_info_event_listener_,
424 invalidator_client_id).Pass(); 411 model_type_registry_.get(),
425 session_context_->set_account_name(credentials.email); 412 args->invalidator_client_id)
426 scheduler_ = internal_components_factory->BuildScheduler( 413 .Pass();
427 name_, session_context_.get(), cancelation_signal).Pass(); 414 session_context_->set_account_name(args->credentials.email);
415 scheduler_ = args->internal_components_factory->BuildScheduler(
416 name_, session_context_.get(), args->cancelation_signal).Pass();
428 417
429 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE); 418 scheduler_->Start(SyncScheduler::CONFIGURATION_MODE);
430 419
431 initialized_ = true; 420 initialized_ = true;
432 421
433 net::NetworkChangeNotifier::AddIPAddressObserver(this); 422 net::NetworkChangeNotifier::AddIPAddressObserver(this);
434 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); 423 net::NetworkChangeNotifier::AddConnectionTypeObserver(this);
435 observing_network_connectivity_changes_ = true; 424 observing_network_connectivity_changes_ = true;
436 425
437 UpdateCredentials(credentials); 426 UpdateCredentials(args->credentials);
438 427
439 NotifyInitializationSuccess(); 428 NotifyInitializationSuccess();
440 } 429 }
441 430
442 void SyncManagerImpl::NotifyInitializationSuccess() { 431 void SyncManagerImpl::NotifyInitializationSuccess() {
443 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, 432 FOR_EACH_OBSERVER(SyncManager::Observer, observers_,
444 OnInitializationComplete( 433 OnInitializationComplete(
445 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), 434 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()),
446 MakeWeakHandle(debug_info_event_listener_.GetWeakPtr()), 435 MakeWeakHandle(debug_info_event_listener_.GetWeakPtr()),
447 true, InitialSyncEndedTypes())); 436 true, InitialSyncEndedTypes()));
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 int SyncManagerImpl::GetDefaultNudgeDelay() { 1139 int SyncManagerImpl::GetDefaultNudgeDelay() {
1151 return kDefaultNudgeDelayMilliseconds; 1140 return kDefaultNudgeDelayMilliseconds;
1152 } 1141 }
1153 1142
1154 // static. 1143 // static.
1155 int SyncManagerImpl::GetPreferencesNudgeDelay() { 1144 int SyncManagerImpl::GetPreferencesNudgeDelay() {
1156 return kPreferencesNudgeDelayMilliseconds; 1145 return kPreferencesNudgeDelayMilliseconds;
1157 } 1146 }
1158 1147
1159 } // namespace syncer 1148 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/sync_manager_impl.h ('k') | sync/internal_api/sync_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698