Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: chrome/browser/bookmarks/bookmark_model_factory.cc

Issue 306293006: Introduce ChromeBookmarkClientFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@364865
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/bookmarks/bookmark_model_factory.h" 5 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/deferred_sequenced_task_runner.h" 8 #include "base/deferred_sequenced_task_runner.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" 12 #include "chrome/browser/bookmarks/chrome_bookmark_client.h"
13 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h"
13 #include "chrome/browser/omnibox/omnibox_field_trial.h" 14 #include "chrome/browser/omnibox/omnibox_field_trial.h"
14 #include "chrome/browser/profiles/incognito_helpers.h" 15 #include "chrome/browser/profiles/incognito_helpers.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/profiles/startup_task_runner_service.h" 17 #include "chrome/browser/profiles/startup_task_runner_service.h"
17 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" 18 #include "chrome/browser/profiles/startup_task_runner_service_factory.h"
18 #include "chrome/browser/undo/bookmark_undo_service.h" 19 #include "chrome/browser/undo/bookmark_undo_service.h"
19 #include "chrome/browser/undo/bookmark_undo_service_factory.h" 20 #include "chrome/browser/undo/bookmark_undo_service_factory.h"
20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
22 #include "components/bookmarks/browser/bookmark_model.h" 23 #include "components/bookmarks/browser/bookmark_model.h"
23 #include "components/bookmarks/common/bookmark_pref_names.h" 24 #include "components/bookmarks/common/bookmark_pref_names.h"
24 #include "components/keyed_service/content/browser_context_dependency_manager.h" 25 #include "components/keyed_service/content/browser_context_dependency_manager.h"
25 #include "components/pref_registry/pref_registry_syncable.h" 26 #include "components/pref_registry/pref_registry_syncable.h"
26 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
27 28
28 // static 29 // static
29 BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) { 30 BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) {
30 ChromeBookmarkClient* bookmark_client = static_cast<ChromeBookmarkClient*>( 31 return static_cast<BookmarkModel*>(
31 GetInstance()->GetServiceForBrowserContext(profile, true)); 32 GetInstance()->GetServiceForBrowserContext(profile, true));
32 return bookmark_client ? bookmark_client->model() : NULL;
33 } 33 }
34 34
35 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) { 35 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) {
36 ChromeBookmarkClient* bookmark_client = static_cast<ChromeBookmarkClient*>( 36 return static_cast<BookmarkModel*>(
37 GetInstance()->GetServiceForBrowserContext(profile, false)); 37 GetInstance()->GetServiceForBrowserContext(profile, false));
38 return bookmark_client ? bookmark_client->model() : NULL;
39 } 38 }
40 39
41 // static 40 // static
42 BookmarkModelFactory* BookmarkModelFactory::GetInstance() { 41 BookmarkModelFactory* BookmarkModelFactory::GetInstance() {
43 return Singleton<BookmarkModelFactory>::get(); 42 return Singleton<BookmarkModelFactory>::get();
44 } 43 }
45 44
46 BookmarkModelFactory::BookmarkModelFactory() 45 BookmarkModelFactory::BookmarkModelFactory()
47 : BrowserContextKeyedServiceFactory( 46 : BrowserContextKeyedServiceFactory(
48 "BookmarkModel", 47 "BookmarkModel",
49 BrowserContextDependencyManager::GetInstance()) { 48 BrowserContextDependencyManager::GetInstance()) {
49 DependsOn(ChromeBookmarkClientFactory::GetInstance());
50 DependsOn(StartupTaskRunnerServiceFactory::GetInstance());
50 } 51 }
51 52
52 BookmarkModelFactory::~BookmarkModelFactory() {} 53 BookmarkModelFactory::~BookmarkModelFactory() {
54 }
53 55
54 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( 56 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor(
55 content::BrowserContext* context) const { 57 content::BrowserContext* context) const {
56 Profile* profile = static_cast<Profile*>(context); 58 Profile* profile = static_cast<Profile*>(context);
57 ChromeBookmarkClient* bookmark_client = new ChromeBookmarkClient( 59 ChromeBookmarkClient* bookmark_client =
58 profile, OmniboxFieldTrial::BookmarksIndexURLsValue()); 60 ChromeBookmarkClientFactory::GetForProfile(profile);
59 bookmark_client->model()->Load( 61 BookmarkModel* bookmark_model = new BookmarkModel(
60 profile->GetPrefs(), 62 bookmark_client, OmniboxFieldTrial::BookmarksIndexURLsValue());
61 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), 63 bookmark_client->Init(bookmark_model);
62 profile->GetPath(), 64 bookmark_model->Load(profile->GetPrefs(),
63 StartupTaskRunnerServiceFactory::GetForProfile(profile) 65 profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
64 ->GetBookmarkTaskRunner(), 66 profile->GetPath(),
65 content::BrowserThread::GetMessageLoopProxyForThread( 67 StartupTaskRunnerServiceFactory::GetForProfile(profile)
66 content::BrowserThread::UI)); 68 ->GetBookmarkTaskRunner(),
69 content::BrowserThread::GetMessageLoopProxyForThread(
70 content::BrowserThread::UI));
67 #if !defined(OS_ANDROID) 71 #if !defined(OS_ANDROID)
68 bool register_bookmark_undo_service_as_observer = true; 72 bool register_bookmark_undo_service_as_observer = true;
69 #if !defined(OS_IOS) 73 #if !defined(OS_IOS)
70 register_bookmark_undo_service_as_observer = 74 register_bookmark_undo_service_as_observer =
71 CommandLine::ForCurrentProcess()->HasSwitch( 75 CommandLine::ForCurrentProcess()->HasSwitch(
72 switches::kEnableBookmarkUndo); 76 switches::kEnableBookmarkUndo);
73 #endif // !defined(OS_IOS) 77 #endif // !defined(OS_IOS)
74 if (register_bookmark_undo_service_as_observer) { 78 if (register_bookmark_undo_service_as_observer) {
75 bookmark_client->model()->AddObserver( 79 bookmark_model->AddObserver(
76 BookmarkUndoServiceFactory::GetForProfile(profile)); 80 BookmarkUndoServiceFactory::GetForProfile(profile));
77 } 81 }
78 #endif // !defined(OS_ANDROID) 82 #endif // !defined(OS_ANDROID)
79 return bookmark_client; 83 return bookmark_client;
80 } 84 }
81 85
82 void BookmarkModelFactory::RegisterProfilePrefs( 86 void BookmarkModelFactory::RegisterProfilePrefs(
83 user_prefs::PrefRegistrySyncable* registry) { 87 user_prefs::PrefRegistrySyncable* registry) {
84 // Don't sync this, as otherwise, due to a limitation in sync, it 88 // Don't sync this, as otherwise, due to a limitation in sync, it
85 // will cause a deadlock (see http://crbug.com/97955). If we truly 89 // will cause a deadlock (see http://crbug.com/97955). If we truly
86 // want to sync the expanded state of folders, it should be part of 90 // want to sync the expanded state of folders, it should be part of
87 // bookmark sync itself (i.e., a property of the sync folder nodes). 91 // bookmark sync itself (i.e., a property of the sync folder nodes).
88 registry->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, 92 registry->RegisterListPref(prefs::kBookmarkEditorExpandedNodes,
89 new base::ListValue, 93 new base::ListValue,
90 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 94 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
91 registry->RegisterListPref( 95 registry->RegisterListPref(
92 prefs::kManagedBookmarks, 96 prefs::kManagedBookmarks,
93 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 97 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
94 } 98 }
95 99
96 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( 100 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse(
97 content::BrowserContext* context) const { 101 content::BrowserContext* context) const {
98 return chrome::GetBrowserContextRedirectedInIncognito(context); 102 return chrome::GetBrowserContextRedirectedInIncognito(context);
99 } 103 }
100 104
101 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { 105 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const {
102 return true; 106 return true;
103 } 107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698