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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 1128012: Rewrite DTM to support dynamic data type configuration (Closed)
Patch Set: Address review comments and fix a leak. Created 10 years, 9 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 (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <set>
8
7 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
8 #include "base/callback.h" 10 #include "base/callback.h"
9 #include "base/command_line.h" 11 #include "base/command_line.h"
10 #include "base/file_path.h" 12 #include "base/file_path.h"
11 #include "base/file_util.h" 13 #include "base/file_util.h"
12 #include "base/histogram.h" 14 #include "base/histogram.h"
13 #include "base/stl_util-inl.h" 15 #include "base/stl_util-inl.h"
14 #include "base/string_util.h" 16 #include "base/string_util.h"
15 #include "base/task.h" 17 #include "base/task.h"
16 #include "chrome/browser/history/history_types.h" 18 #include "chrome/browser/history/history_types.h"
17 #include "chrome/browser/pref_service.h" 19 #include "chrome/browser/pref_service.h"
18 #include "chrome/browser/sync/engine/syncapi.h" 20 #include "chrome/browser/sync/engine/syncapi.h"
19 #include "chrome/browser/sync/glue/change_processor.h" 21 #include "chrome/browser/sync/glue/change_processor.h"
20 #include "chrome/browser/sync/glue/data_type_controller.h" 22 #include "chrome/browser/sync/glue/data_type_controller.h"
21 #include "chrome/browser/sync/glue/data_type_manager.h" 23 #include "chrome/browser/sync/glue/data_type_manager.h"
22 #include "chrome/browser/sync/profile_sync_factory.h" 24 #include "chrome/browser/sync/profile_sync_factory.h"
23 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/notification_details.h"
27 #include "chrome/common/notification_service.h"
28 #include "chrome/common/notification_source.h"
29 #include "chrome/common/notification_type.h"
24 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
25 #include "chrome/common/time_format.h" 31 #include "chrome/common/time_format.h"
26 #include "grit/generated_resources.h" 32 #include "grit/generated_resources.h"
27 #include "net/base/cookie_monster.h" 33 #include "net/base/cookie_monster.h"
28 #include "views/window/window.h" 34 #include "views/window/window.h"
29 35
30 using browser_sync::ChangeProcessor; 36 using browser_sync::ChangeProcessor;
31 using browser_sync::DataTypeController; 37 using browser_sync::DataTypeController;
32 using browser_sync::DataTypeManager; 38 using browser_sync::DataTypeManager;
33 using browser_sync::SyncBackendHost; 39 using browser_sync::SyncBackendHost;
34 40
35 typedef GoogleServiceAuthError AuthError; 41 typedef GoogleServiceAuthError AuthError;
36 42
37 // Default sync server URL. 43 // Default sync server URL.
38 static const char kSyncServerUrl[] = "https://clients4.google.com/chrome-sync"; 44 static const char kSyncServerUrl[] = "https://clients4.google.com/chrome-sync";
39 45
40 ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, 46 ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory,
41 Profile* profile, 47 Profile* profile,
42 bool bootstrap_sync_authentication) 48 bool bootstrap_sync_authentication)
43 : last_auth_error_(AuthError::None()), 49 : last_auth_error_(AuthError::None()),
44 factory_(factory), 50 factory_(factory),
45 profile_(profile), 51 profile_(profile),
46 bootstrap_sync_authentication_(bootstrap_sync_authentication), 52 bootstrap_sync_authentication_(bootstrap_sync_authentication),
47 sync_service_url_(kSyncServerUrl), 53 sync_service_url_(kSyncServerUrl),
48 backend_initialized_(false), 54 backend_initialized_(false),
49 expecting_first_run_auth_needed_event_(false), 55 expecting_first_run_auth_needed_event_(false),
50 is_auth_in_progress_(false), 56 is_auth_in_progress_(false),
51 ALLOW_THIS_IN_INITIALIZER_LIST(wizard_(this)), 57 ALLOW_THIS_IN_INITIALIZER_LIST(wizard_(this)),
52 unrecoverable_error_detected_(false), 58 unrecoverable_error_detected_(false),
53 startup_had_first_time_(false),
54 notification_method_(browser_sync::kDefaultNotificationMethod) { 59 notification_method_(browser_sync::kDefaultNotificationMethod) {
60 registrar_.Add(this,
61 NotificationType::SYNC_CONFIGURE_START,
62 NotificationService::AllSources());
63 registrar_.Add(this,
64 NotificationType::SYNC_CONFIGURE_DONE,
65 NotificationService::AllSources());
55 } 66 }
56 67
57 ProfileSyncService::~ProfileSyncService() { 68 ProfileSyncService::~ProfileSyncService() {
58 Shutdown(false); 69 Shutdown(false);
59 } 70 }
60 71
61 void ProfileSyncService::Initialize() { 72 void ProfileSyncService::Initialize() {
62 InitSettings(); 73 InitSettings();
63 RegisterPreferences(); 74 RegisterPreferences();
64 75
(...skipping 10 matching lines...) Expand all
75 StartUp(); 86 StartUp();
76 profile()->GetPrefs()->SetBoolean(prefs::kSyncBootstrappedAuth, true); 87 profile()->GetPrefs()->SetBoolean(prefs::kSyncBootstrappedAuth, true);
77 } 88 }
78 } else { 89 } else {
79 StartUp(); 90 StartUp();
80 } 91 }
81 } 92 }
82 93
83 void ProfileSyncService::RegisterDataTypeController( 94 void ProfileSyncService::RegisterDataTypeController(
84 DataTypeController* data_type_controller) { 95 DataTypeController* data_type_controller) {
85 DCHECK(data_type_controllers_.count(data_type_controller->type()) == 0); 96 DCHECK_EQ(data_type_controllers_.count(data_type_controller->type()), 0U);
86 data_type_controllers_[data_type_controller->type()] = 97 data_type_controllers_[data_type_controller->type()] =
87 data_type_controller; 98 data_type_controller;
88 } 99 }
89 100
90 void ProfileSyncService::InitSettings() { 101 void ProfileSyncService::InitSettings() {
91 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 102 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
92 103
93 // Override the sync server URL from the command-line, if sync server 104 // Override the sync server URL from the command-line, if sync server
94 // command-line argument exists. 105 // command-line argument exists.
95 if (command_line.HasSwitch(switches::kSyncServiceURL)) { 106 if (command_line.HasSwitch(switches::kSyncServiceURL)) {
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // A sync dialog was aborted before authentication or merge acceptance. 407 // A sync dialog was aborted before authentication or merge acceptance.
397 // Rollback. 408 // Rollback.
398 DisableForUser(); 409 DisableForUser();
399 } 410 }
400 411
401 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); 412 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
402 } 413 }
403 414
404 void ProfileSyncService::StartProcessingChangesIfReady() { 415 void ProfileSyncService::StartProcessingChangesIfReady() {
405 DCHECK(backend_initialized_); 416 DCHECK(backend_initialized_);
406 startup_had_first_time_ = false;
407 417
408 // If we're running inside Chromium OS, always allow merges and 418 // If we're running inside Chromium OS, always allow merges and
409 // consider the sync setup complete. 419 // consider the sync setup complete.
410 if (bootstrap_sync_authentication_) { 420 if (bootstrap_sync_authentication_) {
411 SetSyncSetupCompleted(); 421 SetSyncSetupCompleted();
412 } 422 }
413 423
424 std::set<syncable::ModelType> types;
425 for (DataTypeController::TypeMap::const_iterator it =
426 data_type_controllers_.begin();
427 it != data_type_controllers_.end(); ++it) {
428 types.insert((*it).first);
429 }
430
414 data_type_manager_.reset( 431 data_type_manager_.reset(
415 factory_->CreateDataTypeManager(backend_.get(), data_type_controllers_)); 432 factory_->CreateDataTypeManager(backend_.get(), data_type_controllers_));
416 data_type_manager_->Start( 433 data_type_manager_->Configure(types);
417 NewCallback(this, &ProfileSyncService::DataTypeManagerStartCallback));
418 }
419
420 void ProfileSyncService::DataTypeManagerStartCallback(
421 DataTypeManager::StartResult result) {
422 if (result != DataTypeManager::OK) {
423 OnUnrecoverableError();
424 return;
425 }
426
427 wizard_.Step(SyncSetupWizard::DONE);
428 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
429 } 434 }
430 435
431 void ProfileSyncService::ActivateDataType( 436 void ProfileSyncService::ActivateDataType(
432 DataTypeController* data_type_controller, 437 DataTypeController* data_type_controller,
433 ChangeProcessor* change_processor) { 438 ChangeProcessor* change_processor) {
434 change_processor->Start(profile(), backend_->GetUserShareHandle()); 439 change_processor->Start(profile(), backend_->GetUserShareHandle());
435 backend_->ActivateDataType(data_type_controller, change_processor); 440 backend_->ActivateDataType(data_type_controller, change_processor);
436 } 441 }
437 442
438 void ProfileSyncService::DeactivateDataType( 443 void ProfileSyncService::DeactivateDataType(
439 DataTypeController* data_type_controller, 444 DataTypeController* data_type_controller,
440 ChangeProcessor* change_processor) { 445 ChangeProcessor* change_processor) {
441 change_processor->Stop(); 446 change_processor->Stop();
442 backend_->DeactivateDataType(data_type_controller, change_processor); 447 backend_->DeactivateDataType(data_type_controller, change_processor);
443 } 448 }
444 449
450 void ProfileSyncService::Observe(NotificationType type,
451 const NotificationSource& source,
452 const NotificationDetails& details) {
453 switch (type.value) {
454 case NotificationType::SYNC_CONFIGURE_START: {
455 // TODO(sync): Maybe toast?
456 break;
457 }
458 case NotificationType::SYNC_CONFIGURE_DONE: {
459 DataTypeManager::ConfigureResult result =
460 *(Details<DataTypeManager::ConfigureResult>(details).ptr());
461 if (result != DataTypeManager::OK) {
462 OnUnrecoverableError();
463 return;
464 }
465
466 // TODO(sync): Less wizard, more toast.
467 wizard_.Step(SyncSetupWizard::DONE);
468 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
469 break;
470 }
471 default: {
472 NOTREACHED();
473 }
474 }
475 }
476
445 void ProfileSyncService::AddObserver(Observer* observer) { 477 void ProfileSyncService::AddObserver(Observer* observer) {
446 observers_.AddObserver(observer); 478 observers_.AddObserver(observer);
447 } 479 }
448 480
449 void ProfileSyncService::RemoveObserver(Observer* observer) { 481 void ProfileSyncService::RemoveObserver(Observer* observer) {
450 observers_.RemoveObserver(observer); 482 observers_.RemoveObserver(observer);
451 } 483 }
452 484
453 void ProfileSyncService::SyncEvent(SyncEventCodes code) { 485 void ProfileSyncService::SyncEvent(SyncEventCodes code) {
454 UMA_HISTOGRAM_ENUMERATION("Sync.EventCodes", code, MAX_SYNC_EVENT_CODE); 486 UMA_HISTOGRAM_ENUMERATION("Sync.EventCodes", code, MAX_SYNC_EVENT_CODE);
455 } 487 }
456 488
457 bool ProfileSyncService::IsSyncEnabled() { 489 bool ProfileSyncService::IsSyncEnabled() {
458 // We have switches::kEnableSync just in case we need to change back to 490 // We have switches::kEnableSync just in case we need to change back to
459 // sync-disabled-by-default on a platform. 491 // sync-disabled-by-default on a platform.
460 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync); 492 return !CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableSync);
461 } 493 }
462 494
463 bool ProfileSyncService::ShouldPushChanges() { 495 bool ProfileSyncService::ShouldPushChanges() {
464 // True only after all bootstrapping has succeeded: the sync backend 496 // True only after all bootstrapping has succeeded: the sync backend
465 // is initialized, all enabled data types are consistent with one 497 // is initialized, all enabled data types are consistent with one
466 // another, and no unrecoverable error has transpired. 498 // another, and no unrecoverable error has transpired.
467 if (unrecoverable_error_detected_) 499 if (unrecoverable_error_detected_)
468 return false; 500 return false;
469 501
470 if (!data_type_manager_.get()) 502 if (!data_type_manager_.get())
471 return false; 503 return false;
472 504
473 return data_type_manager_->state() == DataTypeManager::STARTED; 505 return data_type_manager_->state() == DataTypeManager::CONFIGURED;
474 } 506 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_startup_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698