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/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/values.h" | 11 #include "base/values.h" |
11 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 13 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
12 #include "chrome/browser/omnibox/omnibox_field_trial.h" | 14 #include "chrome/browser/omnibox/omnibox_field_trial.h" |
13 #include "chrome/browser/profiles/incognito_helpers.h" | 15 #include "chrome/browser/profiles/incognito_helpers.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/startup_task_runner_service.h" | 17 #include "chrome/browser/profiles/startup_task_runner_service.h" |
16 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" | 18 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" |
17 #include "chrome/browser/undo/bookmark_undo_service.h" | 19 #include "chrome/browser/undo/bookmark_undo_service.h" |
18 #include "chrome/browser/undo/bookmark_undo_service_factory.h" | 20 #include "chrome/browser/undo/bookmark_undo_service_factory.h" |
19 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/pref_names.h" |
20 #include "components/bookmarks/core/common/bookmark_pref_names.h" | 23 #include "components/bookmarks/core/common/bookmark_pref_names.h" |
21 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 24 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
22 #include "components/user_prefs/pref_registry_syncable.h" | 25 #include "components/user_prefs/pref_registry_syncable.h" |
| 26 #include "content/public/browser/browser_thread.h" |
23 | 27 |
24 // static | 28 // static |
25 BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) { | 29 BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) { |
26 return static_cast<BookmarkModel*>( | 30 ChromeBookmarkClient* bookmark_client = static_cast<ChromeBookmarkClient*>( |
27 GetInstance()->GetServiceForBrowserContext(profile, true)); | 31 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 32 return bookmark_client ? bookmark_client->model() : NULL; |
28 } | 33 } |
29 | 34 |
30 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) { | 35 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) { |
31 return static_cast<BookmarkModel*>( | 36 ChromeBookmarkClient* bookmark_client = static_cast<ChromeBookmarkClient*>( |
32 GetInstance()->GetServiceForBrowserContext(profile, false)); | 37 GetInstance()->GetServiceForBrowserContext(profile, false)); |
| 38 return bookmark_client ? bookmark_client->model() : NULL; |
33 } | 39 } |
34 | 40 |
35 // static | 41 // static |
36 BookmarkModelFactory* BookmarkModelFactory::GetInstance() { | 42 BookmarkModelFactory* BookmarkModelFactory::GetInstance() { |
37 return Singleton<BookmarkModelFactory>::get(); | 43 return Singleton<BookmarkModelFactory>::get(); |
38 } | 44 } |
39 | 45 |
40 BookmarkModelFactory::BookmarkModelFactory() | 46 BookmarkModelFactory::BookmarkModelFactory() |
41 : BrowserContextKeyedServiceFactory( | 47 : BrowserContextKeyedServiceFactory( |
42 "BookmarkModel", | 48 "BookmarkModel", |
43 BrowserContextDependencyManager::GetInstance()) { | 49 BrowserContextDependencyManager::GetInstance()) { |
44 } | 50 } |
45 | 51 |
46 BookmarkModelFactory::~BookmarkModelFactory() {} | 52 BookmarkModelFactory::~BookmarkModelFactory() {} |
47 | 53 |
48 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( | 54 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( |
49 content::BrowserContext* context) const { | 55 content::BrowserContext* context) const { |
50 Profile* profile = static_cast<Profile*>(context); | 56 Profile* profile = static_cast<Profile*>(context); |
51 BookmarkModel* bookmark_model = | 57 ChromeBookmarkClient* bookmark_client = new ChromeBookmarkClient( |
52 new BookmarkModel(profile, OmniboxFieldTrial::BookmarksIndexURLsValue()); | 58 profile, OmniboxFieldTrial::BookmarksIndexURLsValue()); |
53 bookmark_model->Load(StartupTaskRunnerServiceFactory::GetForProfile(profile)-> | 59 bookmark_client->model()->Load( |
54 GetBookmarkTaskRunner()); | 60 profile->GetPrefs(), |
| 61 profile->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 62 profile->GetPath(), |
| 63 StartupTaskRunnerServiceFactory::GetForProfile(profile) |
| 64 ->GetBookmarkTaskRunner(), |
| 65 content::BrowserThread::GetMessageLoopProxyForThread( |
| 66 content::BrowserThread::UI)); |
55 #if !defined(OS_ANDROID) | 67 #if !defined(OS_ANDROID) |
56 if (CommandLine::ForCurrentProcess()->HasSwitch( | 68 if (CommandLine::ForCurrentProcess()->HasSwitch( |
57 switches::kEnableBookmarkUndo)) { | 69 switches::kEnableBookmarkUndo)) { |
58 bookmark_model->AddObserver( | 70 bookmark_client->model()->AddObserver( |
59 BookmarkUndoServiceFactory::GetForProfile(profile)); | 71 BookmarkUndoServiceFactory::GetForProfile(profile)); |
60 } | 72 } |
61 #endif // !defined(OS_ANDROID) | 73 #endif // !defined(OS_ANDROID) |
62 return bookmark_model; | 74 return bookmark_client; |
63 } | 75 } |
64 | 76 |
65 void BookmarkModelFactory::RegisterProfilePrefs( | 77 void BookmarkModelFactory::RegisterProfilePrefs( |
66 user_prefs::PrefRegistrySyncable* registry) { | 78 user_prefs::PrefRegistrySyncable* registry) { |
67 // Don't sync this, as otherwise, due to a limitation in sync, it | 79 // Don't sync this, as otherwise, due to a limitation in sync, it |
68 // will cause a deadlock (see http://crbug.com/97955). If we truly | 80 // will cause a deadlock (see http://crbug.com/97955). If we truly |
69 // want to sync the expanded state of folders, it should be part of | 81 // want to sync the expanded state of folders, it should be part of |
70 // bookmark sync itself (i.e., a property of the sync folder nodes). | 82 // bookmark sync itself (i.e., a property of the sync folder nodes). |
71 registry->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, | 83 registry->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, |
72 new base::ListValue, | 84 new base::ListValue, |
73 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 85 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
74 } | 86 } |
75 | 87 |
76 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( | 88 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( |
77 content::BrowserContext* context) const { | 89 content::BrowserContext* context) const { |
78 return chrome::GetBrowserContextRedirectedInIncognito(context); | 90 return chrome::GetBrowserContextRedirectedInIncognito(context); |
79 } | 91 } |
80 | 92 |
81 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { | 93 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { |
82 return true; | 94 return true; |
83 } | 95 } |
OLD | NEW |