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 <memory> | |
| 8 #include <utility> | |
| 9 | |
| 7 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 8 #include "base/deferred_sequenced_task_runner.h" | 11 #include "base/deferred_sequenced_task_runner.h" |
| 9 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 11 #include "base/values.h" | 14 #include "base/values.h" |
| 12 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 13 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | 16 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
| 14 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 17 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| 15 #include "chrome/browser/bookmarks/startup_task_runner_service_factory.h" | 18 #include "chrome/browser/bookmarks/startup_task_runner_service_factory.h" |
| 16 #include "chrome/browser/profiles/incognito_helpers.h" | 19 #include "chrome/browser/profiles/incognito_helpers.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/undo/bookmark_undo_service_factory.h" | 21 #include "chrome/browser/undo/bookmark_undo_service_factory.h" |
| 19 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/features.h" | 23 #include "chrome/common/features.h" |
| 21 #include "components/bookmarks/browser/bookmark_model.h" | 24 #include "components/bookmarks/browser/bookmark_model.h" |
| 22 #include "components/bookmarks/browser/bookmark_utils.h" | 25 #include "components/bookmarks/browser/bookmark_utils.h" |
| 23 #include "components/bookmarks/browser/startup_task_runner_service.h" | 26 #include "components/bookmarks/browser/startup_task_runner_service.h" |
| 24 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 27 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 28 #include "components/offline_pages/external_listener.h" | |
| 25 #include "components/prefs/pref_service.h" | 29 #include "components/prefs/pref_service.h" |
| 26 #include "components/undo/bookmark_undo_service.h" | 30 #include "components/undo/bookmark_undo_service.h" |
| 27 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 28 | 32 |
| 33 #if BUILDFLAG(ANDROID_JAVA_UI) | |
| 34 #include "chrome/browser/android/offline_pages/external_listener_impl.h" | |
| 35 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | |
| 36 #endif | |
| 37 | |
| 29 using bookmarks::BookmarkModel; | 38 using bookmarks::BookmarkModel; |
| 30 | 39 |
| 31 // static | 40 // static |
| 32 BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) { | 41 BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) { |
| 33 return static_cast<BookmarkModel*>( | 42 return static_cast<BookmarkModel*>( |
| 34 GetInstance()->GetServiceForBrowserContext(profile, true)); | 43 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 35 } | 44 } |
| 36 | 45 |
| 37 // static | 46 // static |
| 38 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) { | 47 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) { |
| 39 return static_cast<BookmarkModel*>( | 48 return static_cast<BookmarkModel*>( |
| 40 GetInstance()->GetServiceForBrowserContext(profile, false)); | 49 GetInstance()->GetServiceForBrowserContext(profile, false)); |
| 41 } | 50 } |
| 42 | 51 |
| 43 // static | 52 // static |
| 44 BookmarkModelFactory* BookmarkModelFactory::GetInstance() { | 53 BookmarkModelFactory* BookmarkModelFactory::GetInstance() { |
| 45 return base::Singleton<BookmarkModelFactory>::get(); | 54 return base::Singleton<BookmarkModelFactory>::get(); |
| 46 } | 55 } |
| 47 | 56 |
| 48 BookmarkModelFactory::BookmarkModelFactory() | 57 BookmarkModelFactory::BookmarkModelFactory() |
| 49 : BrowserContextKeyedServiceFactory( | 58 : BrowserContextKeyedServiceFactory( |
| 50 "BookmarkModel", | 59 "BookmarkModel", |
| 51 BrowserContextDependencyManager::GetInstance()) { | 60 BrowserContextDependencyManager::GetInstance()) { |
| 52 DependsOn(BookmarkUndoServiceFactory::GetInstance()); | 61 DependsOn(BookmarkUndoServiceFactory::GetInstance()); |
| 53 DependsOn(ManagedBookmarkServiceFactory::GetInstance()); | 62 DependsOn(ManagedBookmarkServiceFactory::GetInstance()); |
| 63 #if BUILDFLAG(ANDROID_JAVA_UI) | |
| 64 DependsOn(offline_pages::OfflinePageModelFactory::GetInstance()); | |
| 65 #endif | |
| 54 DependsOn(StartupTaskRunnerServiceFactory::GetInstance()); | 66 DependsOn(StartupTaskRunnerServiceFactory::GetInstance()); |
| 55 } | 67 } |
| 56 | 68 |
| 57 BookmarkModelFactory::~BookmarkModelFactory() { | 69 BookmarkModelFactory::~BookmarkModelFactory() { |
| 58 } | 70 } |
| 59 | 71 |
| 60 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( | 72 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( |
| 61 content::BrowserContext* context) const { | 73 content::BrowserContext* context) const { |
| 62 Profile* profile = Profile::FromBrowserContext(context); | 74 Profile* profile = Profile::FromBrowserContext(context); |
| 63 BookmarkModel* bookmark_model = | 75 offline_pages::ExternalListener* offline_page_listener = nullptr; |
| 64 new BookmarkModel(base::WrapUnique(new ChromeBookmarkClient( | 76 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 65 profile, ManagedBookmarkServiceFactory::GetForProfile(profile)))); | 77 offline_page_listener = new offline_pages::ExternalListenerImpl(profile); |
|
Dmitry Titov
2016/08/12 05:43:43
It's better to not use WrapUnique, instead:
auto
romax
2016/08/16 19:05:44
Done.
| |
| 78 #endif // BUILDFLAG(ANDROID_JAVA_UI) | |
| 79 BookmarkModel* bookmark_model = new BookmarkModel( | |
| 80 base::WrapUnique(new ChromeBookmarkClient( | |
| 81 profile, ManagedBookmarkServiceFactory::GetForProfile(profile))), | |
| 82 base::WrapUnique(offline_page_listener)); | |
| 66 bookmark_model->Load(profile->GetPrefs(), profile->GetPath(), | 83 bookmark_model->Load(profile->GetPrefs(), profile->GetPath(), |
| 67 StartupTaskRunnerServiceFactory::GetForProfile(profile) | 84 StartupTaskRunnerServiceFactory::GetForProfile(profile) |
| 68 ->GetBookmarkTaskRunner(), | 85 ->GetBookmarkTaskRunner(), |
| 69 content::BrowserThread::GetTaskRunnerForThread( | 86 content::BrowserThread::GetTaskRunnerForThread( |
| 70 content::BrowserThread::UI)); | 87 content::BrowserThread::UI)); |
| 88 if (offline_page_listener) | |
| 89 bookmark_model->AddObserver(offline_page_listener); | |
| 71 bool register_bookmark_undo_service_as_observer = true; | 90 bool register_bookmark_undo_service_as_observer = true; |
| 91 | |
| 72 #if !BUILDFLAG(ANDROID_JAVA_UI) | 92 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 73 register_bookmark_undo_service_as_observer = | 93 register_bookmark_undo_service_as_observer = |
| 74 base::CommandLine::ForCurrentProcess()->HasSwitch( | 94 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 75 switches::kEnableBookmarkUndo); | 95 switches::kEnableBookmarkUndo); |
| 76 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | 96 #endif // !BUILDFLAG(ANDROID_JAVA_UI) |
| 77 if (register_bookmark_undo_service_as_observer) | 97 if (register_bookmark_undo_service_as_observer) |
| 78 BookmarkUndoServiceFactory::GetForProfile(profile)->Start(bookmark_model); | 98 BookmarkUndoServiceFactory::GetForProfile(profile)->Start(bookmark_model); |
| 79 | 99 |
| 80 return bookmark_model; | 100 return bookmark_model; |
| 81 } | 101 } |
| 82 | 102 |
| 83 void BookmarkModelFactory::RegisterProfilePrefs( | 103 void BookmarkModelFactory::RegisterProfilePrefs( |
| 84 user_prefs::PrefRegistrySyncable* registry) { | 104 user_prefs::PrefRegistrySyncable* registry) { |
| 85 bookmarks::RegisterProfilePrefs(registry); | 105 bookmarks::RegisterProfilePrefs(registry); |
| 86 } | 106 } |
| 87 | 107 |
| 88 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( | 108 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( |
| 89 content::BrowserContext* context) const { | 109 content::BrowserContext* context) const { |
| 90 return chrome::GetBrowserContextRedirectedInIncognito(context); | 110 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 91 } | 111 } |
| 92 | 112 |
| 93 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { | 113 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { |
| 94 return true; | 114 return true; |
| 95 } | 115 } |
| OLD | NEW |