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/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/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | 13 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
| 14 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" | 14 #include "chrome/browser/bookmarks/managed_bookmark_service_factory.h" |
| 15 #include "chrome/browser/bookmarks/startup_task_runner_service_factory.h" | 15 #include "chrome/browser/bookmarks/startup_task_runner_service_factory.h" |
| 16 #include "chrome/browser/profiles/incognito_helpers.h" | 16 #include "chrome/browser/profiles/incognito_helpers.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/undo/bookmark_undo_service_factory.h" | 18 #include "chrome/browser/undo/bookmark_undo_service_factory.h" |
| 19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/features.h" | 20 #include "chrome/common/features.h" |
| 21 #include "components/bookmarks/browser/bookmark_model.h" | 21 #include "components/bookmarks/browser/bookmark_model.h" |
| 22 #include "components/bookmarks/browser/bookmark_utils.h" | 22 #include "components/bookmarks/browser/bookmark_utils.h" |
| 23 #include "components/bookmarks/browser/startup_task_runner_service.h" | 23 #include "components/bookmarks/browser/startup_task_runner_service.h" |
| 24 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 24 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 25 #include "components/prefs/pref_service.h" | 25 #include "components/prefs/pref_service.h" |
| 26 #include "components/undo/bookmark_undo_service.h" | 26 #include "components/undo/bookmark_undo_service.h" |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 | 28 |
| 29 #if BUILDFLAG(ANDROID_JAVA_UI) | |
| 30 #include "chrome/browser/android/offline_pages/offline_page_bookmark_observer.h" | |
| 31 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | |
|
Dmitry Titov
2016/08/26 23:08:59
I think you don't use factory here.
romax
2016/08/29 22:58:02
Done.
| |
| 32 #endif | |
| 33 | |
| 29 using bookmarks::BookmarkModel; | 34 using bookmarks::BookmarkModel; |
| 30 | 35 |
| 31 // static | 36 // static |
| 32 BookmarkModel* BookmarkModelFactory::GetForBrowserContext( | 37 BookmarkModel* BookmarkModelFactory::GetForBrowserContext( |
| 33 content::BrowserContext* context) { | 38 content::BrowserContext* context) { |
| 34 return static_cast<BookmarkModel*>( | 39 return static_cast<BookmarkModel*>( |
| 35 GetInstance()->GetServiceForBrowserContext(context, true)); | 40 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 36 } | 41 } |
| 37 | 42 |
| 38 // static | 43 // static |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 55 DependsOn(ManagedBookmarkServiceFactory::GetInstance()); | 60 DependsOn(ManagedBookmarkServiceFactory::GetInstance()); |
| 56 DependsOn(StartupTaskRunnerServiceFactory::GetInstance()); | 61 DependsOn(StartupTaskRunnerServiceFactory::GetInstance()); |
| 57 } | 62 } |
| 58 | 63 |
| 59 BookmarkModelFactory::~BookmarkModelFactory() { | 64 BookmarkModelFactory::~BookmarkModelFactory() { |
| 60 } | 65 } |
| 61 | 66 |
| 62 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( | 67 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( |
| 63 content::BrowserContext* context) const { | 68 content::BrowserContext* context) const { |
| 64 Profile* profile = Profile::FromBrowserContext(context); | 69 Profile* profile = Profile::FromBrowserContext(context); |
| 65 BookmarkModel* bookmark_model = | 70 std::unique_ptr<bookmarks::OwnedBookmarkModelObserver> offline_page_observer = |
| 66 new BookmarkModel(base::WrapUnique(new ChromeBookmarkClient( | 71 nullptr; |
| 67 profile, ManagedBookmarkServiceFactory::GetForProfile(profile)))); | 72 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 73 offline_page_observer = | |
| 74 base::MakeUnique<offline_pages::OfflinePageBookmarkObserver>(profile); | |
| 75 #endif // BUILDFLAG(ANDROID_JAVA_UI) | |
| 76 BookmarkModel* bookmark_model = new BookmarkModel( | |
| 77 base::WrapUnique(new ChromeBookmarkClient( | |
| 78 profile, ManagedBookmarkServiceFactory::GetForProfile(profile))), | |
| 79 std::move(offline_page_observer)); | |
| 68 bookmark_model->Load(profile->GetPrefs(), profile->GetPath(), | 80 bookmark_model->Load(profile->GetPrefs(), profile->GetPath(), |
| 69 StartupTaskRunnerServiceFactory::GetForProfile(profile) | 81 StartupTaskRunnerServiceFactory::GetForProfile(profile) |
| 70 ->GetBookmarkTaskRunner(), | 82 ->GetBookmarkTaskRunner(), |
| 71 content::BrowserThread::GetTaskRunnerForThread( | 83 content::BrowserThread::GetTaskRunnerForThread( |
| 72 content::BrowserThread::UI)); | 84 content::BrowserThread::UI)); |
| 73 bool register_bookmark_undo_service_as_observer = true; | 85 bool register_bookmark_undo_service_as_observer = true; |
| 86 | |
| 74 #if !BUILDFLAG(ANDROID_JAVA_UI) | 87 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 75 register_bookmark_undo_service_as_observer = | 88 register_bookmark_undo_service_as_observer = |
| 76 base::CommandLine::ForCurrentProcess()->HasSwitch( | 89 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 77 switches::kEnableBookmarkUndo); | 90 switches::kEnableBookmarkUndo); |
| 78 #endif // !BUILDFLAG(ANDROID_JAVA_UI) | 91 #endif // !BUILDFLAG(ANDROID_JAVA_UI) |
| 79 if (register_bookmark_undo_service_as_observer) | 92 if (register_bookmark_undo_service_as_observer) |
| 80 BookmarkUndoServiceFactory::GetForProfile(profile)->Start(bookmark_model); | 93 BookmarkUndoServiceFactory::GetForProfile(profile)->Start(bookmark_model); |
| 81 | 94 |
| 82 return bookmark_model; | 95 return bookmark_model; |
| 83 } | 96 } |
| 84 | 97 |
| 85 void BookmarkModelFactory::RegisterProfilePrefs( | 98 void BookmarkModelFactory::RegisterProfilePrefs( |
| 86 user_prefs::PrefRegistrySyncable* registry) { | 99 user_prefs::PrefRegistrySyncable* registry) { |
| 87 bookmarks::RegisterProfilePrefs(registry); | 100 bookmarks::RegisterProfilePrefs(registry); |
| 88 } | 101 } |
| 89 | 102 |
| 90 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( | 103 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( |
| 91 content::BrowserContext* context) const { | 104 content::BrowserContext* context) const { |
| 92 return chrome::GetBrowserContextRedirectedInIncognito(context); | 105 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 93 } | 106 } |
| 94 | 107 |
| 95 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { | 108 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { |
| 96 return true; | 109 return true; |
| 97 } | 110 } |
| OLD | NEW |