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

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

Issue 7669073: [Sync] Add support for enabling session sync remotely. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 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
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/file_util.h" 13 #include "base/file_util.h"
14 #include "base/task.h" 14 #include "base/task.h"
15 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
16 #include "base/tracked.h" 16 #include "base/tracked.h"
17 #include "base/utf_string_conversions.h" 17 #include "base/utf_string_conversions.h"
18 #include "chrome/browser/about_flags.h"
19 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/net/gaia/token_service.h" 20 #include "chrome/browser/net/gaia/token_service.h"
19 #include "chrome/browser/prefs/pref_service.h" 21 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/sync/glue/autofill_model_associator.h" 23 #include "chrome/browser/sync/glue/autofill_model_associator.h"
22 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h" 24 #include "chrome/browser/sync/glue/autofill_profile_model_associator.h"
23 #include "chrome/browser/sync/glue/change_processor.h" 25 #include "chrome/browser/sync/glue/change_processor.h"
24 #include "chrome/browser/sync/glue/database_model_worker.h" 26 #include "chrome/browser/sync/glue/database_model_worker.h"
25 #include "chrome/browser/sync/glue/history_model_worker.h" 27 #include "chrome/browser/sync/glue/history_model_worker.h"
26 #include "chrome/browser/sync/glue/http_bridge.h" 28 #include "chrome/browser/sync/glue/http_bridge.h"
27 #include "chrome/browser/sync/glue/password_model_worker.h" 29 #include "chrome/browser/sync/glue/password_model_worker.h"
30 #include "chrome/browser/sync/glue/session_data_type_controller.h"
28 #include "chrome/browser/sync/glue/sync_backend_host.h" 31 #include "chrome/browser/sync/glue/sync_backend_host.h"
29 #include "chrome/browser/sync/internal_api/base_transaction.h" 32 #include "chrome/browser/sync/internal_api/base_transaction.h"
30 #include "chrome/browser/sync/internal_api/sync_manager.h" 33 #include "chrome/browser/sync/internal_api/sync_manager.h"
31 #include "chrome/browser/sync/js/js_arg_list.h" 34 #include "chrome/browser/sync/js/js_arg_list.h"
32 #include "chrome/browser/sync/js/js_event_details.h" 35 #include "chrome/browser/sync/js/js_event_details.h"
33 #include "chrome/browser/sync/js/js_event_handler.h" 36 #include "chrome/browser/sync/js/js_event_handler.h"
34 #include "chrome/browser/sync/notifier/sync_notifier.h" 37 #include "chrome/browser/sync/notifier/sync_notifier.h"
35 #include "chrome/browser/sync/sessions/session_state.h" 38 #include "chrome/browser/sync/sessions/session_state.h"
36 // TODO(tim): Remove this! We should have a syncapi pass-thru instead. 39 // TODO(tim): Remove this! We should have a syncapi pass-thru instead.
37 #include "chrome/browser/sync/syncable/directory_manager.h" // Cryptographer. 40 #include "chrome/browser/sync/syncable/directory_manager.h" // Cryptographer.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 last_auth_error_(AuthError::None()) { 90 last_auth_error_(AuthError::None()) {
88 } 91 }
89 92
90 SyncBackendHost::~SyncBackendHost() { 93 SyncBackendHost::~SyncBackendHost() {
91 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; 94 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor.";
92 DCHECK(registrar_.workers.empty()); 95 DCHECK(registrar_.workers.empty());
93 } 96 }
94 97
95 void SyncBackendHost::Initialize( 98 void SyncBackendHost::Initialize(
96 SyncFrontend* frontend, 99 SyncFrontend* frontend,
100 ProfileSyncFactory* factory,
97 const WeakHandle<JsEventHandler>& event_handler, 101 const WeakHandle<JsEventHandler>& event_handler,
98 const GURL& sync_service_url, 102 const GURL& sync_service_url,
99 const syncable::ModelTypeSet& initial_types, 103 const syncable::ModelTypeSet& initial_types,
100 const SyncCredentials& credentials, 104 const SyncCredentials& credentials,
101 bool delete_sync_data_folder) { 105 bool delete_sync_data_folder) {
102 if (!sync_thread_.Start()) 106 if (!sync_thread_.Start())
103 return; 107 return;
104 108
105 frontend_ = frontend; 109 frontend_ = frontend;
110 profile_sync_factory_ = factory;
106 DCHECK(frontend); 111 DCHECK(frontend);
107 112
108 registrar_.workers[GROUP_DB] = new DatabaseModelWorker(); 113 registrar_.workers[GROUP_DB] = new DatabaseModelWorker();
109 registrar_.workers[GROUP_UI] = new UIModelWorker(); 114 registrar_.workers[GROUP_UI] = new UIModelWorker();
110 registrar_.workers[GROUP_PASSIVE] = new ModelSafeWorker(); 115 registrar_.workers[GROUP_PASSIVE] = new ModelSafeWorker();
111 HistoryService* history_service = profile_->GetHistoryService( 116 HistoryService* history_service = profile_->GetHistoryService(
112 Profile::IMPLICIT_ACCESS); 117 Profile::IMPLICIT_ACCESS);
113 if (history_service) { 118 if (history_service) {
114 registrar_.workers[GROUP_HISTORY] = new HistoryModelWorker(history_service); 119 registrar_.workers[GROUP_HISTORY] = new HistoryModelWorker(history_service);
115 } else { 120 } else {
(...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 } 860 }
856 861
857 void SyncBackendHost::Core::HandleSyncCycleCompletedOnFrontendLoop( 862 void SyncBackendHost::Core::HandleSyncCycleCompletedOnFrontendLoop(
858 SyncSessionSnapshot* snapshot) { 863 SyncSessionSnapshot* snapshot) {
859 if (!host_ || !host_->frontend_) 864 if (!host_ || !host_->frontend_)
860 return; 865 return;
861 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 866 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
862 867
863 host_->last_snapshot_.reset(snapshot); 868 host_->last_snapshot_.reset(snapshot);
864 869
865 const syncable::ModelTypeSet& to_migrate = 870 syncable::ModelTypeSet to_migrate =
866 snapshot->syncer_status.types_needing_local_migration; 871 snapshot->syncer_status.types_needing_local_migration;
867 if (!to_migrate.empty()) 872 if (sync_manager()->ShouldEnableSessions() && host_->initialized()) {
873 // Have to grab these before we register the sessions DTC.
874 syncable::ModelTypeSet enabled_types;
875 host_->frontend_->GetPreferredDataTypes(&enabled_types);
876 syncable::ModelTypeSet registered_types;
877 host_->frontend_->GetRegisteredDataTypes(&registered_types);
878
879 // Received notice to enable tab (sessions) sync. Check if sessions are
880 // registered, and if not register a new datatype controller.
881 if (registered_types.count(syncable::SESSIONS) == 0) {
tim (not reviewing) 2011/08/22 15:42:08 Something about this is circuitous. First, 'Get'i
Nicolas Zea 2011/08/22 22:50:15 Done.
882 ProfileSyncService* service = profile_->GetProfileSyncService();
883 ProfileSyncFactory* factory = host_->profile_sync_factory_;
884 host_->frontend_->RegisterDataTypeController(
885 new SessionDataTypeController(factory, profile_, service));
886
887 // Check if the user has "Keep Everything Synced" enabled. If so, we want
888 // to turn on sessions if it's not already on. Otherwise we leave it off.
889 // Note: if sessions are already registered, we don't turn it on. This
890 // covers the case where we're already in the process of reconfiguring
891 // to turn sessions on.
892 if (profile_->GetPrefs()->GetBoolean(prefs::kKeepEverythingSynced) &&
893 enabled_types.count(syncable::SESSIONS) == 0){
894 // Enable the about:flags switch for sessions so we don't have to always
895 // perform this reconfiguration. Once we set this, sessions will remain
896 // registered, so we will no longer go down this code path.
897 about_flags::SetExperimentEnabled(g_browser_process->local_state(),
898 "sync-sessions",
899 true);
900 profile_->GetPrefs()->SetBoolean(prefs::kSyncSessions, true);
901 to_migrate.insert(syncable::SESSIONS);
902 }
903 }
904 }
905
906 // We can only start migration if we have finished initialization. Any
907 // datatypes that need migration currently will still require it after we
908 // finish initializing.
909 if (!to_migrate.empty() && host_->initialized())
868 host_->frontend_->OnMigrationNeededForTypes(to_migrate); 910 host_->frontend_->OnMigrationNeededForTypes(to_migrate);
869 911
870 // If we are waiting for a configuration change, check here to see 912 // If we are waiting for a configuration change, check here to see
871 // if this sync cycle has initialized all of the types we've been 913 // if this sync cycle has initialized all of the types we've been
872 // waiting for. 914 // waiting for.
873 if (host_->pending_download_state_.get()) { 915 if (host_->pending_download_state_.get()) {
874 scoped_ptr<PendingConfigureDataTypesState> state( 916 scoped_ptr<PendingConfigureDataTypesState> state(
875 host_->pending_download_state_.release()); 917 host_->pending_download_state_.release());
876 DCHECK( 918 DCHECK(
877 std::includes(state->types_to_add.begin(), state->types_to_add.end(), 919 std::includes(state->types_to_add.begin(), state->types_to_add.end(),
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 } 1103 }
1062 1104
1063 void SyncBackendHost::Core::DeleteSyncDataFolder() { 1105 void SyncBackendHost::Core::DeleteSyncDataFolder() {
1064 if (file_util::DirectoryExists(host_->sync_data_folder_path())) { 1106 if (file_util::DirectoryExists(host_->sync_data_folder_path())) {
1065 if (!file_util::Delete(host_->sync_data_folder_path(), true)) 1107 if (!file_util::Delete(host_->sync_data_folder_path(), true))
1066 LOG(DFATAL) << "Could not delete the Sync Data folder."; 1108 LOG(DFATAL) << "Could not delete the Sync Data folder.";
1067 } 1109 }
1068 } 1110 }
1069 1111
1070 } // namespace browser_sync 1112 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698