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

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: Add missing dependency in components/policy/policy_browser.gypi 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 = 31 return static_cast<BookmarkModel*>(
31 GetChromeBookmarkClientForProfile(profile); 32 GetInstance()->GetServiceForBrowserContext(profile, true));
32 return bookmark_client ? bookmark_client->model() : NULL;
33 } 33 }
34 34
35 // static 35 // static
36 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) { 36 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) {
37 ChromeBookmarkClient* bookmark_client = static_cast<ChromeBookmarkClient*>( 37 return static_cast<BookmarkModel*>(
38 GetInstance()->GetServiceForBrowserContext(profile, false)); 38 GetInstance()->GetServiceForBrowserContext(profile, false));
39 return bookmark_client ? bookmark_client->model() : NULL;
40 } 39 }
41 40
42 // static 41 // static
43 ChromeBookmarkClient* BookmarkModelFactory::GetChromeBookmarkClientForProfile(
44 Profile* profile) {
45 return static_cast<ChromeBookmarkClient*>(
46 GetInstance()->GetServiceForBrowserContext(profile, true));
47 }
48
49 // static
50 BookmarkModelFactory* BookmarkModelFactory::GetInstance() { 42 BookmarkModelFactory* BookmarkModelFactory::GetInstance() {
51 return Singleton<BookmarkModelFactory>::get(); 43 return Singleton<BookmarkModelFactory>::get();
52 } 44 }
53 45
54 BookmarkModelFactory::BookmarkModelFactory() 46 BookmarkModelFactory::BookmarkModelFactory()
55 : BrowserContextKeyedServiceFactory( 47 : BrowserContextKeyedServiceFactory(
56 "BookmarkModel", 48 "BookmarkModel",
57 BrowserContextDependencyManager::GetInstance()) { 49 BrowserContextDependencyManager::GetInstance()) {
50 DependsOn(ChromeBookmarkClientFactory::GetInstance());
51 DependsOn(StartupTaskRunnerServiceFactory::GetInstance());
58 } 52 }
59 53
60 BookmarkModelFactory::~BookmarkModelFactory() {} 54 BookmarkModelFactory::~BookmarkModelFactory() {
55 }
61 56
62 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( 57 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor(
63 content::BrowserContext* context) const { 58 content::BrowserContext* context) const {
64 Profile* profile = static_cast<Profile*>(context); 59 Profile* profile = static_cast<Profile*>(context);
65 ChromeBookmarkClient* bookmark_client = new ChromeBookmarkClient( 60 ChromeBookmarkClient* bookmark_client =
66 profile, OmniboxFieldTrial::BookmarksIndexURLsValue()); 61 ChromeBookmarkClientFactory::GetForProfile(profile);
67 bookmark_client->model()->Load( 62 BookmarkModel* bookmark_model = new BookmarkModel(
68 profile->GetPrefs(), 63 bookmark_client, OmniboxFieldTrial::BookmarksIndexURLsValue());
69 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), 64 bookmark_client->Init(bookmark_model);
70 profile->GetPath(), 65 bookmark_model->Load(profile->GetPrefs(),
71 StartupTaskRunnerServiceFactory::GetForProfile(profile) 66 profile->GetPrefs()->GetString(prefs::kAcceptLanguages),
72 ->GetBookmarkTaskRunner(), 67 profile->GetPath(),
73 content::BrowserThread::GetMessageLoopProxyForThread( 68 StartupTaskRunnerServiceFactory::GetForProfile(profile)
74 content::BrowserThread::UI)); 69 ->GetBookmarkTaskRunner(),
70 content::BrowserThread::GetMessageLoopProxyForThread(
71 content::BrowserThread::UI));
75 #if !defined(OS_ANDROID) 72 #if !defined(OS_ANDROID)
76 bool register_bookmark_undo_service_as_observer = true; 73 bool register_bookmark_undo_service_as_observer = true;
77 #if !defined(OS_IOS) 74 #if !defined(OS_IOS)
78 register_bookmark_undo_service_as_observer = 75 register_bookmark_undo_service_as_observer =
79 CommandLine::ForCurrentProcess()->HasSwitch( 76 CommandLine::ForCurrentProcess()->HasSwitch(
80 switches::kEnableBookmarkUndo); 77 switches::kEnableBookmarkUndo);
81 #endif // !defined(OS_IOS) 78 #endif // !defined(OS_IOS)
82 if (register_bookmark_undo_service_as_observer) { 79 if (register_bookmark_undo_service_as_observer) {
83 bookmark_client->model()->AddObserver( 80 bookmark_model->AddObserver(
84 BookmarkUndoServiceFactory::GetForProfile(profile)); 81 BookmarkUndoServiceFactory::GetForProfile(profile));
85 } 82 }
86 #endif // !defined(OS_ANDROID) 83 #endif // !defined(OS_ANDROID)
87 return bookmark_client; 84 return bookmark_model;
88 } 85 }
89 86
90 void BookmarkModelFactory::RegisterProfilePrefs( 87 void BookmarkModelFactory::RegisterProfilePrefs(
91 user_prefs::PrefRegistrySyncable* registry) { 88 user_prefs::PrefRegistrySyncable* registry) {
92 // Don't sync this, as otherwise, due to a limitation in sync, it 89 // Don't sync this, as otherwise, due to a limitation in sync, it
93 // will cause a deadlock (see http://crbug.com/97955). If we truly 90 // will cause a deadlock (see http://crbug.com/97955). If we truly
94 // want to sync the expanded state of folders, it should be part of 91 // want to sync the expanded state of folders, it should be part of
95 // bookmark sync itself (i.e., a property of the sync folder nodes). 92 // bookmark sync itself (i.e., a property of the sync folder nodes).
96 registry->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, 93 registry->RegisterListPref(prefs::kBookmarkEditorExpandedNodes,
97 new base::ListValue, 94 new base::ListValue,
98 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 95 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
99 registry->RegisterListPref( 96 registry->RegisterListPref(
100 prefs::kManagedBookmarks, 97 prefs::kManagedBookmarks,
101 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 98 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
102 } 99 }
103 100
104 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( 101 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse(
105 content::BrowserContext* context) const { 102 content::BrowserContext* context) const {
106 return chrome::GetBrowserContextRedirectedInIncognito(context); 103 return chrome::GetBrowserContextRedirectedInIncognito(context);
107 } 104 }
108 105
109 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { 106 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const {
110 return true; 107 return true;
111 } 108 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_model_factory.h ('k') | chrome/browser/bookmarks/chrome_bookmark_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698