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