1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ios/chrome/browser/sync/glue/sync_start_util.h"
8 #include "base/files/file_path.h"
9 #include "base/location.h"
10 #include "components/sync_driver/sync_service.h"
11 #include "ios/chrome/browser/application_context.h"
12 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
13 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state_manager.h"
14 #include "ios/public/provider/chrome/browser/keyed_service_provider.h"
15 #include "ios/web/public/web_thread.h"
20 void StartSyncOnUIThread(const base::FilePath
& browser_state_path
,
21 syncer::ModelType type
) {
22 ios::ChromeBrowserStateManager
* browser_state_manager
=
23 GetApplicationContext()->GetChromeBrowserStateManager();
24 if (!browser_state_manager
) {
25 // Can happen in tests.
26 DVLOG(2) << "No ChromeBrowserStateManager, can't start sync.";
30 ios::ChromeBrowserState
* browser_state
=
31 browser_state_manager
->GetChromeBrowserState(browser_state_path
);
33 DVLOG(2) << "ChromeBrowserState not found, can't start sync.";
37 sync_driver::SyncService
* sync_service
=
38 ios::GetKeyedServiceProvider()->GetSyncServiceForBrowserState(
41 DVLOG(2) << "No SyncService for browser state, can't start sync.";
44 sync_service
->OnDataTypeRequestsSyncStartup(type
);
47 void StartSyncProxy(const base::FilePath
& browser_state_path
,
48 syncer::ModelType type
) {
49 web::WebThread::PostTask(
50 web::WebThread::UI
, FROM_HERE
,
51 base::Bind(&StartSyncOnUIThread
, browser_state_path
, type
));
56 namespace sync_start_util
{
58 syncer::SyncableService::StartSyncFlare
GetFlareForSyncableService(
59 const base::FilePath
& browser_state_path
) {
60 return base::Bind(&StartSyncProxy
, browser_state_path
);
63 } // namespace sync_start_util