Chromium Code Reviews| 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("BookmarkModel", |
| 37 ProfileDependencyManager::GetInstance()) { | 37 BrowserContextDependencyManager::GetInstance()) { |
|
tfarina
2013/05/22 00:28:03
indentation.
| |
| 38 } | 38 } |
| 39 | 39 |
| 40 BookmarkModelFactory::~BookmarkModelFactory() {} | 40 BookmarkModelFactory::~BookmarkModelFactory() {} |
| 41 | 41 |
| 42 ProfileKeyedService* BookmarkModelFactory::BuildServiceInstanceFor( | 42 BrowserContextKeyedService* BookmarkModelFactory::BuildServiceInstanceFor( |
| 43 content::BrowserContext* context) const { | 43 content::BrowserContext* context) const { |
| 44 Profile* profile = static_cast<Profile*>(context); | 44 Profile* profile = static_cast<Profile*>(context); |
| 45 BookmarkModel* bookmark_model = new BookmarkModel(profile); | 45 BookmarkModel* bookmark_model = new BookmarkModel(profile); |
| 46 bookmark_model->Load(StartupTaskRunnerServiceFactory::GetForProfile(profile)-> | 46 bookmark_model->Load(StartupTaskRunnerServiceFactory::GetForProfile(profile)-> |
| 47 GetBookmarkTaskRunner()); | 47 GetBookmarkTaskRunner()); |
| 48 return bookmark_model; | 48 return bookmark_model; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void BookmarkModelFactory::RegisterUserPrefs( | 51 void BookmarkModelFactory::RegisterUserPrefs( |
| 52 user_prefs::PrefRegistrySyncable* registry) { | 52 user_prefs::PrefRegistrySyncable* registry) { |
| 53 // Don't sync this, as otherwise, due to a limitation in sync, it | 53 // 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 | 54 // 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 | 55 // 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). | 56 // bookmark sync itself (i.e., a property of the sync folder nodes). |
| 57 registry->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, | 57 registry->RegisterListPref(prefs::kBookmarkEditorExpandedNodes, |
| 58 new base::ListValue, | 58 new base::ListValue, |
| 59 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 59 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 60 } | 60 } |
| 61 | 61 |
| 62 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( | 62 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( |
| 63 content::BrowserContext* context) const { | 63 content::BrowserContext* context) const { |
| 64 return chrome::GetBrowserContextRedirectedInIncognito(context); | 64 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { | 67 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { |
| 68 return true; | 68 return true; |
| 69 } | 69 } |
| OLD | NEW |