| 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" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 void UpdateNetworkTime(const base::Time& network_time, | 68 void UpdateNetworkTime(const base::Time& network_time, |
| 69 const base::TimeDelta& resolution, | 69 const base::TimeDelta& resolution, |
| 70 const base::TimeDelta& latency) { | 70 const base::TimeDelta& latency) { |
| 71 content::BrowserThread::PostTask( | 71 content::BrowserThread::PostTask( |
| 72 content::BrowserThread::UI, FROM_HERE, | 72 content::BrowserThread::UI, FROM_HERE, |
| 73 base::Bind(&UpdateNetworkTimeOnUIThread, network_time, resolution, | 73 base::Bind(&UpdateNetworkTimeOnUIThread, network_time, resolution, |
| 74 latency, base::TimeTicks::Now())); | 74 latency, base::TimeTicks::Now())); |
| 75 } | 75 } |
| 76 | 76 |
| 77 #if defined(OS_WIN) |
| 78 static const base::FilePath::CharType kLoopbackServerBackendFilename[] = |
| 79 FILE_PATH_LITERAL("profile.pb"); |
| 80 #endif |
| 81 |
| 77 } // anonymous namespace | 82 } // anonymous namespace |
| 78 | 83 |
| 79 // static | 84 // static |
| 80 ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { | 85 ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { |
| 81 return base::Singleton<ProfileSyncServiceFactory>::get(); | 86 return base::Singleton<ProfileSyncServiceFactory>::get(); |
| 82 } | 87 } |
| 83 | 88 |
| 84 // static | 89 // static |
| 85 ProfileSyncService* ProfileSyncServiceFactory::GetForProfile( | 90 ProfileSyncService* ProfileSyncServiceFactory::GetForProfile( |
| 86 Profile* profile) { | 91 Profile* profile) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 140 |
| 136 ProfileSyncServiceFactory::~ProfileSyncServiceFactory() { | 141 ProfileSyncServiceFactory::~ProfileSyncServiceFactory() { |
| 137 } | 142 } |
| 138 | 143 |
| 139 KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( | 144 KeyedService* ProfileSyncServiceFactory::BuildServiceInstanceFor( |
| 140 content::BrowserContext* context) const { | 145 content::BrowserContext* context) const { |
| 141 ProfileSyncService::InitParams init_params; | 146 ProfileSyncService::InitParams init_params; |
| 142 | 147 |
| 143 Profile* profile = Profile::FromBrowserContext(context); | 148 Profile* profile = Profile::FromBrowserContext(context); |
| 144 | 149 |
| 145 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); | 150 init_params.network_time_update_callback = base::Bind(&UpdateNetworkTime); |
| 151 init_params.base_directory = profile->GetPath(); |
| 152 init_params.url_request_context = profile->GetRequestContext(); |
| 153 init_params.debug_identifier = profile->GetDebugName(); |
| 154 init_params.channel = chrome::GetChannel(); |
| 155 init_params.blocking_pool = content::BrowserThread::GetBlockingPool(); |
| 146 | 156 |
| 147 // Always create the GCMProfileService instance such that we can listen to | 157 bool local_sync_backend_enabled = false; |
| 148 // the profile notifications and purge the GCM store when the profile is | |
| 149 // being signed out. | |
| 150 gcm::GCMProfileServiceFactory::GetForProfile(profile); | |
| 151 | 158 |
| 152 // TODO(atwilson): Change AboutSigninInternalsFactory to load on startup | 159 // Since the local sync backend is currently only supported on Windows don't |
| 153 // once http://crbug.com/171406 has been fixed. | 160 // even check the pref on other os-es. |
| 154 AboutSigninInternalsFactory::GetForProfile(profile); | 161 #if defined(OS_WIN) |
| 162 syncer::SyncPrefs prefs(profile->GetPrefs()); |
| 163 local_sync_backend_enabled = prefs.IsLocalSyncEnabled(); |
| 164 if (local_sync_backend_enabled) { |
| 165 // This code as it is now will assume the same profile order is present on |
| 166 // all machines, which is not a given. It is to be defined if only the |
| 167 // Default profile should get this treatment or all profile as is the case |
| 168 // now. The solution for now will be to assume profiles are created in the |
| 169 // same order on all machines and in the future decide if only the Default |
| 170 // one should be considered roamed. |
| 171 init_params.local_sync_backend_folder = prefs.GetLocalSyncBackendDir(); |
| 172 init_params.local_sync_backend_folder = |
| 173 init_params.local_sync_backend_folder.Append( |
| 174 init_params.base_directory.BaseName()); |
| 175 init_params.local_sync_backend_folder = |
| 176 init_params.local_sync_backend_folder.Append( |
| 177 kLoopbackServerBackendFilename); |
| 155 | 178 |
| 156 init_params.signin_wrapper = | 179 init_params.start_behavior = ProfileSyncService::AUTO_START; |
| 157 base::MakeUnique<SupervisedUserSigninManagerWrapper>(profile, signin); | 180 } |
| 158 init_params.oauth2_token_service = | 181 #endif // defined(OS_WIN) |
| 159 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | |
| 160 init_params.gaia_cookie_manager_service = | |
| 161 GaiaCookieManagerServiceFactory::GetForProfile(profile); | |
| 162 | 182 |
| 163 // TODO(tim): Currently, AUTO/MANUAL settings refer to the *first* time sync | 183 if (!local_sync_backend_enabled) { |
| 164 // is set up and *not* a browser restart for a manual-start platform (where | 184 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); |
| 165 // sync has already been set up, and should be able to start without user | 185 |
| 166 // intervention). We can get rid of the browser_default eventually, but | 186 // Always create the GCMProfileService instance such that we can listen to |
| 167 // need to take care that ProfileSyncService doesn't get tripped up between | 187 // the profile notifications and purge the GCM store when the profile is |
| 168 // those two cases. Bug 88109. | 188 // being signed out. |
| 169 init_params.start_behavior = browser_defaults::kSyncAutoStarts | 189 gcm::GCMProfileServiceFactory::GetForProfile(profile); |
| 170 ? ProfileSyncService::AUTO_START | 190 |
| 171 : ProfileSyncService::MANUAL_START; | 191 // TODO(atwilson): Change AboutSigninInternalsFactory to load on startup |
| 192 // once http://crbug.com/171406 has been fixed. |
| 193 AboutSigninInternalsFactory::GetForProfile(profile); |
| 194 |
| 195 init_params.signin_wrapper = |
| 196 base::MakeUnique<SupervisedUserSigninManagerWrapper>(profile, signin); |
| 197 init_params.oauth2_token_service = |
| 198 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 199 init_params.gaia_cookie_manager_service = |
| 200 GaiaCookieManagerServiceFactory::GetForProfile(profile); |
| 201 |
| 202 // TODO(tim): Currently, AUTO/MANUAL settings refer to the *first* time sync |
| 203 // is set up and *not* a browser restart for a manual-start platform (where |
| 204 // sync has already been set up, and should be able to start without user |
| 205 // intervention). We can get rid of the browser_default eventually, but |
| 206 // need to take care that ProfileSyncService doesn't get tripped up between |
| 207 // those two cases. Bug 88109. |
| 208 init_params.start_behavior = browser_defaults::kSyncAutoStarts |
| 209 ? ProfileSyncService::AUTO_START |
| 210 : ProfileSyncService::MANUAL_START; |
| 211 } |
| 172 | 212 |
| 173 if (!client_factory_) { | 213 if (!client_factory_) { |
| 174 init_params.sync_client = | 214 init_params.sync_client = |
| 175 base::MakeUnique<browser_sync::ChromeSyncClient>(profile); | 215 base::MakeUnique<browser_sync::ChromeSyncClient>(profile); |
| 176 } else { | 216 } else { |
| 177 init_params.sync_client = client_factory_->Run(profile); | 217 init_params.sync_client = client_factory_->Run(profile); |
| 178 } | 218 } |
| 179 | 219 |
| 180 init_params.network_time_update_callback = base::Bind(&UpdateNetworkTime); | |
| 181 init_params.base_directory = profile->GetPath(); | |
| 182 init_params.url_request_context = profile->GetRequestContext(); | |
| 183 init_params.debug_identifier = profile->GetDebugName(); | |
| 184 init_params.channel = chrome::GetChannel(); | |
| 185 init_params.blocking_pool = content::BrowserThread::GetBlockingPool(); | |
| 186 | |
| 187 auto pss = base::MakeUnique<ProfileSyncService>(std::move(init_params)); | 220 auto pss = base::MakeUnique<ProfileSyncService>(std::move(init_params)); |
| 188 | 221 |
| 189 // Will also initialize the sync client. | 222 // Will also initialize the sync client. |
| 190 pss->Initialize(); | 223 pss->Initialize(); |
| 191 return pss.release(); | 224 return pss.release(); |
| 192 } | 225 } |
| 193 | 226 |
| 194 // static | 227 // static |
| 195 bool ProfileSyncServiceFactory::HasProfileSyncService(Profile* profile) { | 228 bool ProfileSyncServiceFactory::HasProfileSyncService(Profile* profile) { |
| 196 return GetInstance()->GetServiceForBrowserContext(profile, false) != nullptr; | 229 return GetInstance()->GetServiceForBrowserContext(profile, false) != nullptr; |
| 197 } | 230 } |
| 198 | 231 |
| 199 // static | 232 // static |
| 200 void ProfileSyncServiceFactory::SetSyncClientFactoryForTest( | 233 void ProfileSyncServiceFactory::SetSyncClientFactoryForTest( |
| 201 SyncClientFactory* client_factory) { | 234 SyncClientFactory* client_factory) { |
| 202 client_factory_ = client_factory; | 235 client_factory_ = client_factory; |
| 203 } | 236 } |
| 204 | 237 |
| 205 // static | 238 // static |
| 206 ProfileSyncServiceFactory::SyncClientFactory* | 239 ProfileSyncServiceFactory::SyncClientFactory* |
| 207 ProfileSyncServiceFactory::client_factory_ = nullptr; | 240 ProfileSyncServiceFactory::client_factory_ = nullptr; |
| OLD | NEW |