Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "chrome/browser/sync/profile_sync_service_factory.h" | 5 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "base/path_service.h" | |
| 11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 12 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 13 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 14 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 15 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/defaults.h" | 17 #include "chrome/browser/defaults.h" |
| 17 #include "chrome/browser/history/history_service_factory.h" | 18 #include "chrome/browser/history/history_service_factory.h" |
| 18 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 19 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| 19 #include "chrome/browser/password_manager/password_store_factory.h" | 20 #include "chrome/browser/password_manager/password_store_factory.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/profiles/profile_manager.h" | 22 #include "chrome/browser/profiles/profile_manager.h" |
| 22 #include "chrome/browser/search_engines/template_url_service_factory.h" | 23 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 23 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 24 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 24 #include "chrome/browser/signin/about_signin_internals_factory.h" | 25 #include "chrome/browser/signin/about_signin_internals_factory.h" |
| 25 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 26 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
| 26 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" | 27 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" |
| 27 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 28 #include "chrome/browser/signin/signin_manager_factory.h" | 29 #include "chrome/browser/signin/signin_manager_factory.h" |
| 29 #include "chrome/browser/sync/chrome_sync_client.h" | 30 #include "chrome/browser/sync/chrome_sync_client.h" |
| 30 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" | 31 #include "chrome/browser/sync/supervised_user_signin_manager_wrapper.h" |
| 31 #include "chrome/browser/themes/theme_service_factory.h" | 32 #include "chrome/browser/themes/theme_service_factory.h" |
| 32 #include "chrome/browser/web_data_service_factory.h" | 33 #include "chrome/browser/web_data_service_factory.h" |
| 33 #include "chrome/common/channel_info.h" | 34 #include "chrome/common/channel_info.h" |
| 35 #include "components/browser_sync/browser_sync_switches.h" | |
| 34 #include "components/browser_sync/profile_sync_components_factory_impl.h" | 36 #include "components/browser_sync/profile_sync_components_factory_impl.h" |
| 35 #include "components/browser_sync/profile_sync_service.h" | 37 #include "components/browser_sync/profile_sync_service.h" |
| 36 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 38 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 37 #include "components/network_time/network_time_tracker.h" | 39 #include "components/network_time/network_time_tracker.h" |
| 38 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 40 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 39 #include "components/signin/core/browser/signin_manager.h" | 41 #include "components/signin/core/browser/signin_manager.h" |
| 40 #include "components/sync/driver/signin_manager_wrapper.h" | 42 #include "components/sync/driver/signin_manager_wrapper.h" |
| 41 #include "components/sync/driver/startup_controller.h" | 43 #include "components/sync/driver/startup_controller.h" |
| 42 #include "components/sync/driver/sync_util.h" | 44 #include "components/sync/driver/sync_util.h" |
| 43 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 67 | 69 |
| 68 void UpdateNetworkTime(const base::Time& network_time, | 70 void UpdateNetworkTime(const base::Time& network_time, |
| 69 const base::TimeDelta& resolution, | 71 const base::TimeDelta& resolution, |
| 70 const base::TimeDelta& latency) { | 72 const base::TimeDelta& latency) { |
| 71 content::BrowserThread::PostTask( | 73 content::BrowserThread::PostTask( |
| 72 content::BrowserThread::UI, FROM_HERE, | 74 content::BrowserThread::UI, FROM_HERE, |
| 73 base::Bind(&UpdateNetworkTimeOnUIThread, network_time, resolution, | 75 base::Bind(&UpdateNetworkTimeOnUIThread, network_time, resolution, |
| 74 latency, base::TimeTicks::Now())); | 76 latency, base::TimeTicks::Now())); |
| 75 } | 77 } |
| 76 | 78 |
| 79 #if defined(OS_WIN) | |
| 80 static const base::FilePath::CharType kLoopbackServerBackendFilename[] = | |
| 81 FILE_PATH_LITERAL("profile.pb"); | |
| 82 #endif | |
| 83 | |
| 77 } // anonymous namespace | 84 } // anonymous namespace |
| 78 | 85 |
| 79 // static | 86 // static |
| 80 ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { | 87 ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { |
| 81 return base::Singleton<ProfileSyncServiceFactory>::get(); | 88 return base::Singleton<ProfileSyncServiceFactory>::get(); |
| 82 } | 89 } |
| 83 | 90 |
| 84 // static | 91 // static |
| 85 ProfileSyncService* ProfileSyncServiceFactory::GetForProfile( | 92 ProfileSyncService* ProfileSyncServiceFactory::GetForProfile( |
| 86 Profile* profile) { | 93 Profile* profile) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 144 |
| 138 ProfileSyncServiceFactory::~ProfileSyncServiceFactory() { | 145 ProfileSyncServiceFactory::~ProfileSyncServiceFactory() { |
| 139 } | 146 } |
| 140 | 147 |
| 141 KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( | 148 KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( |
| 142 content::BrowserContext* context) const { | 149 content::BrowserContext* context) const { |
| 143 ProfileSyncService::InitParams init_params; | 150 ProfileSyncService::InitParams init_params; |
| 144 | 151 |
| 145 Profile* profile = Profile::FromBrowserContext(context); | 152 Profile* profile = Profile::FromBrowserContext(context); |
| 146 | 153 |
| 147 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); | 154 init_params.network_time_update_callback = base::Bind(&UpdateNetworkTime); |
| 155 init_params.base_directory = profile->GetPath(); | |
| 156 init_params.url_request_context = profile->GetRequestContext(); | |
| 157 init_params.debug_identifier = profile->GetDebugName(); | |
| 158 init_params.channel = chrome::GetChannel(); | |
| 159 init_params.blocking_pool = content::BrowserThread::GetBlockingPool(); | |
| 160 init_params.local_sync_backend_enabled = false; | |
| 148 | 161 |
| 149 // Always create the GCMProfileService instance such that we can listen to | 162 #if defined(OS_WIN) |
| 150 // the profile notifications and purge the GCM store when the profile is | 163 init_params.local_sync_backend_enabled = |
| 151 // being signed out. | 164 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 152 gcm::GCMProfileServiceFactory::GetForProfile(profile); | 165 switches::kEnableLocalSyncBackend); |
| 153 | 166 |
| 154 // TODO(atwilson): Change AboutSigninInternalsFactory to load on startup | 167 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
|
Nicolas Zea
2016/11/19 00:36:42
should all of this logic be dependent on local_syn
pastarmovj
2016/11/22 12:38:08
Done.
| |
| 155 // once http://crbug.com/171406 has been fixed. | 168 switches::kLocalSyncBackendDir)) { |
| 156 AboutSigninInternalsFactory::GetForProfile(profile); | 169 init_params.local_sync_backend_folder = |
| 170 base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( | |
| 171 switches::kLocalSyncBackendDir); | |
| 172 } else { | |
| 173 // TODO(pastarmovj): Add DIR_ROAMING_USER_DATA to PathService to simplify | |
| 174 // this code and move the logic in its right place. See crbug/657810. | |
| 175 CHECK(base::PathService::Get(base::DIR_APP_DATA, | |
| 176 &init_params.local_sync_backend_folder)); | |
| 177 init_params.local_sync_backend_folder = | |
| 178 init_params.local_sync_backend_folder.Append( | |
| 179 FILE_PATH_LITERAL("Chrome/User Data")); | |
| 180 } | |
| 181 // This code as it is now will assume the same profile order is present on all | |
| 182 // machines, which is not a given. It is to be defined if only the Default | |
| 183 // profile should get this treatment or all profile as is the case now. The | |
| 184 // solution for now will be to assume profiles are created in the same order | |
| 185 // on all machines and in the future decide if only the Default one should be | |
| 186 // considered roamed. | |
| 187 init_params.local_sync_backend_folder = | |
| 188 init_params.local_sync_backend_folder.Append( | |
| 189 init_params.base_directory.BaseName()); | |
| 190 init_params.local_sync_backend_folder = | |
| 191 init_params.local_sync_backend_folder.Append( | |
| 192 kLoopbackServerBackendFilename); | |
| 193 #endif // defined(OS_WIN) | |
| 157 | 194 |
| 158 init_params.signin_wrapper = | 195 if (!init_params.local_sync_backend_enabled) { |
| 159 base::MakeUnique<SupervisedUserSigninManagerWrapper>(profile, signin); | 196 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); |
| 160 init_params.oauth2_token_service = | |
| 161 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | |
| 162 init_params.gaia_cookie_manager_service = | |
| 163 GaiaCookieManagerServiceFactory::GetForProfile(profile); | |
| 164 | 197 |
| 165 // TODO(tim): Currently, AUTO/MANUAL settings refer to the *first* time sync | 198 // Always create the GCMProfileService instance such that we can listen to |
| 166 // is set up and *not* a browser restart for a manual-start platform (where | 199 // the profile notifications and purge the GCM store when the profile is |
| 167 // sync has already been set up, and should be able to start without user | 200 // being signed out. |
| 168 // intervention). We can get rid of the browser_default eventually, but | 201 gcm::GCMProfileServiceFactory::GetForProfile(profile); |
| 169 // need to take care that ProfileSyncService doesn't get tripped up between | 202 |
| 170 // those two cases. Bug 88109. | 203 // TODO(atwilson): Change AboutSigninInternalsFactory to load on startup |
| 171 init_params.start_behavior = browser_defaults::kSyncAutoStarts | 204 // once http://crbug.com/171406 has been fixed. |
| 172 ? ProfileSyncService::AUTO_START | 205 AboutSigninInternalsFactory::GetForProfile(profile); |
| 173 : ProfileSyncService::MANUAL_START; | 206 |
| 207 init_params.signin_wrapper = | |
| 208 base::MakeUnique<SupervisedUserSigninManagerWrapper>(profile, signin); | |
| 209 init_params.oauth2_token_service = | |
| 210 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | |
| 211 init_params.gaia_cookie_manager_service = | |
| 212 GaiaCookieManagerServiceFactory::GetForProfile(profile); | |
| 213 | |
| 214 // TODO(tim): Currently, AUTO/MANUAL settings refer to the *first* time sync | |
| 215 // is set up and *not* a browser restart for a manual-start platform (where | |
| 216 // sync has already been set up, and should be able to start without user | |
| 217 // intervention). We can get rid of the browser_default eventually, but | |
| 218 // need to take care that ProfileSyncService doesn't get tripped up between | |
| 219 // those two cases. Bug 88109. | |
| 220 init_params.start_behavior = browser_defaults::kSyncAutoStarts | |
| 221 ? ProfileSyncService::AUTO_START | |
| 222 : ProfileSyncService::MANUAL_START; | |
| 223 } else { | |
| 224 // In local mode none of the sign-in stuff is required. | |
| 225 init_params.start_behavior = ProfileSyncService::AUTO_START; | |
|
Nicolas Zea
2016/11/19 00:36:42
I think it's cleaner to move this up to the #if de
pastarmovj
2016/11/22 12:38:08
Done.
Btw technically all of the above can always
| |
| 226 } | |
| 174 | 227 |
| 175 if (!client_factory_) { | 228 if (!client_factory_) { |
| 176 init_params.sync_client = | 229 init_params.sync_client = |
| 177 base::MakeUnique<browser_sync::ChromeSyncClient>(profile); | 230 base::MakeUnique<browser_sync::ChromeSyncClient>(profile); |
| 178 } else { | 231 } else { |
| 179 init_params.sync_client = client_factory_->Run(profile); | 232 init_params.sync_client = client_factory_->Run(profile); |
| 180 } | 233 } |
| 181 | 234 |
| 182 init_params.network_time_update_callback = base::Bind(&UpdateNetworkTime); | |
| 183 init_params.base_directory = profile->GetPath(); | |
| 184 init_params.url_request_context = profile->GetRequestContext(); | |
| 185 init_params.debug_identifier = profile->GetDebugName(); | |
| 186 init_params.channel = chrome::GetChannel(); | |
| 187 init_params.blocking_pool = content::BrowserThread::GetBlockingPool(); | |
| 188 | |
| 189 auto pss = base::MakeUnique<ProfileSyncService>(std::move(init_params)); | 235 auto pss = base::MakeUnique<ProfileSyncService>(std::move(init_params)); |
| 190 | 236 |
| 191 // Will also initialize the sync client. | 237 // Will also initialize the sync client. |
| 192 pss->Initialize(); | 238 pss->Initialize(); |
| 193 return pss.release(); | 239 return pss.release(); |
| 194 } | 240 } |
| 195 | 241 |
| 196 // static | 242 // static |
| 197 bool ProfileSyncServiceFactory::HasProfileSyncService(Profile* profile) { | 243 bool ProfileSyncServiceFactory::HasProfileSyncService(Profile* profile) { |
| 198 return GetInstance()->GetServiceForBrowserContext(profile, false) != nullptr; | 244 return GetInstance()->GetServiceForBrowserContext(profile, false) != nullptr; |
| 199 } | 245 } |
| 200 | 246 |
| 201 // static | 247 // static |
| 202 void ProfileSyncServiceFactory::SetSyncClientFactoryForTest( | 248 void ProfileSyncServiceFactory::SetSyncClientFactoryForTest( |
| 203 SyncClientFactory* client_factory) { | 249 SyncClientFactory* client_factory) { |
| 204 client_factory_ = client_factory; | 250 client_factory_ = client_factory; |
| 205 } | 251 } |
| 206 | 252 |
| 207 // static | 253 // static |
| 208 ProfileSyncServiceFactory::SyncClientFactory* | 254 ProfileSyncServiceFactory::SyncClientFactory* |
| 209 ProfileSyncServiceFactory::client_factory_ = nullptr; | 255 ProfileSyncServiceFactory::client_factory_ = nullptr; |
| OLD | NEW |