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/deferred_sequenced_task_runner.h" | 7 #include "base/deferred_sequenced_task_runner.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
11 #include "chrome/browser/profiles/incognito_helpers.h" | 11 #include "chrome/browser/profiles/incognito_helpers.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/profiles/startup_task_runner_service.h" | 13 #include "chrome/browser/profiles/startup_task_runner_service.h" |
14 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" | 14 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 16 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
17 #include "components/user_prefs/pref_registry_syncable.h" | 17 #include "components/user_prefs/pref_registry_syncable.h" |
18 | 18 |
19 // static | 19 // static |
20 BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) { | 20 BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) { |
21 return static_cast<BookmarkModel*>( | 21 return static_cast<BookmarkModel*>( |
22 GetInstance()->GetServiceForProfile(profile, true)); | 22 GetInstance()->GetServiceForBrowserContext(profile, true)); |
23 } | 23 } |
24 | 24 |
25 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) { | 25 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) { |
26 return static_cast<BookmarkModel*>( | 26 return static_cast<BookmarkModel*>( |
27 GetInstance()->GetServiceForProfile(profile, false)); | 27 GetInstance()->GetServiceForBrowserContext(profile, false)); |
28 } | 28 } |
29 | 29 |
30 // static | 30 // static |
31 BookmarkModelFactory* BookmarkModelFactory::GetInstance() { | 31 BookmarkModelFactory* BookmarkModelFactory::GetInstance() { |
32 return Singleton<BookmarkModelFactory>::get(); | 32 return Singleton<BookmarkModelFactory>::get(); |
33 } | 33 } |
34 | 34 |
35 BookmarkModelFactory::BookmarkModelFactory() | 35 BookmarkModelFactory::BookmarkModelFactory() |
36 : ProfileKeyedServiceFactory("BookmarkModel", | 36 : BrowserContextKeyedServiceFactory( |
37 ProfileDependencyManager::GetInstance()) { | 37 "BookmarkModel", |
| 38 BrowserContextDependencyManager::GetInstance()) { |
38 } | 39 } |
39 | 40 |
40 BookmarkModelFactory::~BookmarkModelFactory() {} | 41 BookmarkModelFactory::~BookmarkModelFactory() {} |
41 | 42 |
42 ProfileKeyedService* BookmarkModelFactory::BuildServiceInstanceFor( | 43 BrowserContextKeyedService* BookmarkModelFactory::BuildServiceInstanceFor( |
43 content::BrowserContext* context) const { | 44 content::BrowserContext* context) const { |
44 Profile* profile = static_cast<Profile*>(context); | 45 Profile* profile = static_cast<Profile*>(context); |
45 BookmarkModel* bookmark_model = new BookmarkModel(profile); | 46 BookmarkModel* bookmark_model = new BookmarkModel(profile); |
46 bookmark_model->Load(StartupTaskRunnerServiceFactory::GetForProfile(profile)-> | 47 bookmark_model->Load(StartupTaskRunnerServiceFactory::GetForProfile(profile)-> |
47 GetBookmarkTaskRunner()); | 48 GetBookmarkTaskRunner()); |
48 return bookmark_model; | 49 return bookmark_model; |
49 } | 50 } |
50 | 51 |
51 void BookmarkModelFactory::RegisterUserPrefs( | 52 void BookmarkModelFactory::RegisterUserPrefs( |
52 user_prefs::PrefRegistrySyncable* registry) { | 53 user_prefs::PrefRegistrySyncable* registry) { |
53 // Don't sync this, as otherwise, due to a limitation in sync, it | 54 // Don't sync this, as otherwise, due to a limitation in sync, it |
54 // will cause a deadlock (see http://crbug.com/97955). If we truly | 55 // will cause a deadlock (see http://crbug.com/97955). If we truly |
55 // want to sync the expanded state of folders, it should be part of | 56 // want to sync the expanded state of folders, it should be part of |
56 // bookmark sync itself (i.e., a property of the sync folder nodes). | 57 // bookmark sync itself (i.e., a property of the sync folder nodes). |
57 registry->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, | 58 registry->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, |
58 new base::ListValue, | 59 new base::ListValue, |
59 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 60 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
60 } | 61 } |
61 | 62 |
62 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( | 63 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( |
63 content::BrowserContext* context) const { | 64 content::BrowserContext* context) const { |
64 return chrome::GetBrowserContextRedirectedInIncognito(context); | 65 return chrome::GetBrowserContextRedirectedInIncognito(context); |
65 } | 66 } |
66 | 67 |
67 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { | 68 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { |
68 return true; | 69 return true; |
69 } | 70 } |
OLD | NEW |