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/metrics/histogram_macros.h" |
11 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 15 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
15 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 16 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/defaults.h" | 18 #include "chrome/browser/defaults.h" |
18 #include "chrome/browser/gcm/gcm_profile_service_factory.h" | 19 #include "chrome/browser/gcm/gcm_profile_service_factory.h" |
19 #include "chrome/browser/history/history_service_factory.h" | 20 #include "chrome/browser/history/history_service_factory.h" |
20 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 21 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 69 |
69 void UpdateNetworkTime(const base::Time& network_time, | 70 void UpdateNetworkTime(const base::Time& network_time, |
70 const base::TimeDelta& resolution, | 71 const base::TimeDelta& resolution, |
71 const base::TimeDelta& latency) { | 72 const base::TimeDelta& latency) { |
72 content::BrowserThread::PostTask( | 73 content::BrowserThread::PostTask( |
73 content::BrowserThread::UI, FROM_HERE, | 74 content::BrowserThread::UI, FROM_HERE, |
74 base::Bind(&UpdateNetworkTimeOnUIThread, network_time, resolution, | 75 base::Bind(&UpdateNetworkTimeOnUIThread, network_time, resolution, |
75 latency, base::TimeTicks::Now())); | 76 latency, base::TimeTicks::Now())); |
76 } | 77 } |
77 | 78 |
78 #if defined(OS_WIN) | |
79 static const base::FilePath::CharType kLoopbackServerBackendFilename[] = | |
80 FILE_PATH_LITERAL("profile.pb"); | |
81 #endif | |
82 | |
83 } // anonymous namespace | 79 } // anonymous namespace |
84 | 80 |
85 // static | 81 // static |
86 ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { | 82 ProfileSyncServiceFactory* ProfileSyncServiceFactory::GetInstance() { |
87 return base::Singleton<ProfileSyncServiceFactory>::get(); | 83 return base::Singleton<ProfileSyncServiceFactory>::get(); |
88 } | 84 } |
89 | 85 |
90 // static | 86 // static |
91 ProfileSyncService* ProfileSyncServiceFactory::GetForProfile( | 87 ProfileSyncService* ProfileSyncServiceFactory::GetForProfile( |
92 Profile* profile) { | 88 Profile* profile) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 init_params.url_request_context = profile->GetRequestContext(); | 149 init_params.url_request_context = profile->GetRequestContext(); |
154 init_params.debug_identifier = profile->GetDebugName(); | 150 init_params.debug_identifier = profile->GetDebugName(); |
155 init_params.channel = chrome::GetChannel(); | 151 init_params.channel = chrome::GetChannel(); |
156 base::SequencedWorkerPool* blocking_pool = | 152 base::SequencedWorkerPool* blocking_pool = |
157 content::BrowserThread::GetBlockingPool(); | 153 content::BrowserThread::GetBlockingPool(); |
158 init_params.blocking_task_runner = | 154 init_params.blocking_task_runner = |
159 blocking_pool->GetSequencedTaskRunnerWithShutdownBehavior( | 155 blocking_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
160 blocking_pool->GetSequenceToken(), | 156 blocking_pool->GetSequenceToken(), |
161 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 157 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
162 | 158 |
| 159 if (!client_factory_) { |
| 160 init_params.sync_client = |
| 161 base::MakeUnique<browser_sync::ChromeSyncClient>(profile); |
| 162 } else { |
| 163 init_params.sync_client = client_factory_->Run(profile); |
| 164 } |
| 165 |
163 bool local_sync_backend_enabled = false; | 166 bool local_sync_backend_enabled = false; |
164 | |
165 // Since the local sync backend is currently only supported on Windows don't | 167 // Since the local sync backend is currently only supported on Windows don't |
166 // even check the pref on other os-es. | 168 // even check the pref on other os-es. |
167 #if defined(OS_WIN) | 169 #if defined(OS_WIN) |
168 syncer::SyncPrefs prefs(profile->GetPrefs()); | 170 syncer::SyncPrefs prefs(profile->GetPrefs()); |
169 local_sync_backend_enabled = prefs.IsLocalSyncEnabled(); | 171 local_sync_backend_enabled = prefs.IsLocalSyncEnabled(); |
| 172 UMA_HISTOGRAM_BOOLEAN("Sync.Local.Enabled", local_sync_backend_enabled); |
| 173 |
170 if (local_sync_backend_enabled) { | 174 if (local_sync_backend_enabled) { |
171 // This code as it is now will assume the same profile order is present on | 175 base::FilePath local_sync_backend_folder = |
172 // all machines, which is not a given. It is to be defined if only the | 176 init_params.sync_client->GetLocalSyncBackendFolder(); |
173 // Default profile should get this treatment or all profile as is the case | 177 |
174 // now. The solution for now will be to assume profiles are created in the | 178 // If the user has not specified a folder and we can't get the default |
175 // same order on all machines and in the future decide if only the Default | 179 // roaming profile location the sync service will not be created. |
176 // one should be considered roamed. | 180 UMA_HISTOGRAM_BOOLEAN("Sync.Local.RoamingProfileUnavailable", |
177 init_params.local_sync_backend_folder = prefs.GetLocalSyncBackendDir(); | 181 local_sync_backend_folder.empty()); |
178 init_params.local_sync_backend_folder = | 182 if (local_sync_backend_folder.empty()) |
179 init_params.local_sync_backend_folder.Append( | 183 return nullptr; |
180 init_params.base_directory.BaseName()); | |
181 init_params.local_sync_backend_folder = | |
182 init_params.local_sync_backend_folder.Append( | |
183 kLoopbackServerBackendFilename); | |
184 | 184 |
185 init_params.start_behavior = ProfileSyncService::AUTO_START; | 185 init_params.start_behavior = ProfileSyncService::AUTO_START; |
186 } | 186 } |
187 #endif // defined(OS_WIN) | 187 #endif // defined(OS_WIN) |
188 | 188 |
189 if (!local_sync_backend_enabled) { | 189 if (!local_sync_backend_enabled) { |
190 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); | 190 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); |
191 | 191 |
192 // Always create the GCMProfileService instance such that we can listen to | 192 // Always create the GCMProfileService instance such that we can listen to |
193 // the profile notifications and purge the GCM store when the profile is | 193 // the profile notifications and purge the GCM store when the profile is |
(...skipping 15 matching lines...) Expand all Loading... |
209 // is set up and *not* a browser restart for a manual-start platform (where | 209 // is set up and *not* a browser restart for a manual-start platform (where |
210 // sync has already been set up, and should be able to start without user | 210 // sync has already been set up, and should be able to start without user |
211 // intervention). We can get rid of the browser_default eventually, but | 211 // intervention). We can get rid of the browser_default eventually, but |
212 // need to take care that ProfileSyncService doesn't get tripped up between | 212 // need to take care that ProfileSyncService doesn't get tripped up between |
213 // those two cases. Bug 88109. | 213 // those two cases. Bug 88109. |
214 init_params.start_behavior = browser_defaults::kSyncAutoStarts | 214 init_params.start_behavior = browser_defaults::kSyncAutoStarts |
215 ? ProfileSyncService::AUTO_START | 215 ? ProfileSyncService::AUTO_START |
216 : ProfileSyncService::MANUAL_START; | 216 : ProfileSyncService::MANUAL_START; |
217 } | 217 } |
218 | 218 |
219 if (!client_factory_) { | |
220 init_params.sync_client = | |
221 base::MakeUnique<browser_sync::ChromeSyncClient>(profile); | |
222 } else { | |
223 init_params.sync_client = client_factory_->Run(profile); | |
224 } | |
225 | |
226 auto pss = base::MakeUnique<ProfileSyncService>(std::move(init_params)); | 219 auto pss = base::MakeUnique<ProfileSyncService>(std::move(init_params)); |
227 | 220 |
228 // Will also initialize the sync client. | 221 // Will also initialize the sync client. |
229 pss->Initialize(); | 222 pss->Initialize(); |
230 return pss.release(); | 223 return pss.release(); |
231 } | 224 } |
232 | 225 |
233 // static | 226 // static |
234 bool ProfileSyncServiceFactory::HasProfileSyncService(Profile* profile) { | 227 bool ProfileSyncServiceFactory::HasProfileSyncService(Profile* profile) { |
235 return GetInstance()->GetServiceForBrowserContext(profile, false) != nullptr; | 228 return GetInstance()->GetServiceForBrowserContext(profile, false) != nullptr; |
236 } | 229 } |
237 | 230 |
238 // static | 231 // static |
239 void ProfileSyncServiceFactory::SetSyncClientFactoryForTest( | 232 void ProfileSyncServiceFactory::SetSyncClientFactoryForTest( |
240 SyncClientFactory* client_factory) { | 233 SyncClientFactory* client_factory) { |
241 client_factory_ = client_factory; | 234 client_factory_ = client_factory; |
242 } | 235 } |
243 | 236 |
244 // static | 237 // static |
245 ProfileSyncServiceFactory::SyncClientFactory* | 238 ProfileSyncServiceFactory::SyncClientFactory* |
246 ProfileSyncServiceFactory::client_factory_ = nullptr; | 239 ProfileSyncServiceFactory::client_factory_ = nullptr; |
OLD | NEW |