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