Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / ios / chrome / browser / sync / glue / sync_start_util.cc
blob93753bfbb59cd38645c08f53b3b0be03516bc32d
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"
7 #include "base/bind.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"
17 namespace ios {
18 namespace {
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.";
27 return;
30 ios::ChromeBrowserState* browser_state =
31 browser_state_manager->GetChromeBrowserState(browser_state_path);
32 if (!browser_state) {
33 DVLOG(2) << "ChromeBrowserState not found, can't start sync.";
34 return;
37 sync_driver::SyncService* sync_service =
38 ios::GetKeyedServiceProvider()->GetSyncServiceForBrowserState(
39 browser_state);
40 if (!sync_service) {
41 DVLOG(2) << "No SyncService for browser state, can't start sync.";
42 return;
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));
54 } // namespace
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
64 } // namespace ios