| 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_im
pl.h" |
| 31 #endif |
| 32 |
| 29 using bookmarks::BookmarkModel; | 33 using bookmarks::BookmarkModel; |
| 30 | 34 |
| 31 // static | 35 // static |
| 32 BookmarkModel* BookmarkModelFactory::GetForBrowserContext( | 36 BookmarkModel* BookmarkModelFactory::GetForBrowserContext( |
| 33 content::BrowserContext* context) { | 37 content::BrowserContext* context) { |
| 34 return static_cast<BookmarkModel*>( | 38 return static_cast<BookmarkModel*>( |
| 35 GetInstance()->GetServiceForBrowserContext(context, true)); | 39 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 36 } | 40 } |
| 37 | 41 |
| 38 // static | 42 // static |
| (...skipping 16 matching lines...) Expand all Loading... |
| 55 DependsOn(ManagedBookmarkServiceFactory::GetInstance()); | 59 DependsOn(ManagedBookmarkServiceFactory::GetInstance()); |
| 56 DependsOn(StartupTaskRunnerServiceFactory::GetInstance()); | 60 DependsOn(StartupTaskRunnerServiceFactory::GetInstance()); |
| 57 } | 61 } |
| 58 | 62 |
| 59 BookmarkModelFactory::~BookmarkModelFactory() { | 63 BookmarkModelFactory::~BookmarkModelFactory() { |
| 60 } | 64 } |
| 61 | 65 |
| 62 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( | 66 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( |
| 63 content::BrowserContext* context) const { | 67 content::BrowserContext* context) const { |
| 64 Profile* profile = Profile::FromBrowserContext(context); | 68 Profile* profile = Profile::FromBrowserContext(context); |
| 65 BookmarkModel* bookmark_model = | 69 std::unique_ptr<bookmarks::OfflinePageBookmarkObserver> |
| 66 new BookmarkModel(base::WrapUnique(new ChromeBookmarkClient( | 70 offline_page_observer = nullptr; |
| 67 profile, ManagedBookmarkServiceFactory::GetForProfile(profile)))); | 71 #if BUILDFLAG(ANDROID_JAVA_UI) |
| 72 offline_page_observer = |
| 73 base::MakeUnique<offline_pages::OfflinePageBookmarkObserverImpl>(profile); |
| 74 #endif // BUILDFLAG(ANDROID_JAVA_UI) |
| 75 BookmarkModel* bookmark_model = new BookmarkModel( |
| 76 base::WrapUnique(new ChromeBookmarkClient( |
| 77 profile, ManagedBookmarkServiceFactory::GetForProfile(profile))), |
| 78 std::move(offline_page_observer)); |
| 68 bookmark_model->Load(profile->GetPrefs(), profile->GetPath(), | 79 bookmark_model->Load(profile->GetPrefs(), profile->GetPath(), |
| 69 StartupTaskRunnerServiceFactory::GetForProfile(profile) | 80 StartupTaskRunnerServiceFactory::GetForProfile(profile) |
| 70 ->GetBookmarkTaskRunner(), | 81 ->GetBookmarkTaskRunner(), |
| 71 content::BrowserThread::GetTaskRunnerForThread( | 82 content::BrowserThread::GetTaskRunnerForThread( |
| 72 content::BrowserThread::UI)); | 83 content::BrowserThread::UI)); |
| 73 bool register_bookmark_undo_service_as_observer = true; | 84 bool register_bookmark_undo_service_as_observer = true; |
| 74 #if !BUILDFLAG(ANDROID_JAVA_UI) | 85 #if !BUILDFLAG(ANDROID_JAVA_UI) |
| 75 register_bookmark_undo_service_as_observer = | 86 register_bookmark_undo_service_as_observer = |
| 76 base::CommandLine::ForCurrentProcess()->HasSwitch( | 87 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 77 switches::kEnableBookmarkUndo); | 88 switches::kEnableBookmarkUndo); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 88 } | 99 } |
| 89 | 100 |
| 90 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( | 101 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( |
| 91 content::BrowserContext* context) const { | 102 content::BrowserContext* context) const { |
| 92 return chrome::GetBrowserContextRedirectedInIncognito(context); | 103 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 93 } | 104 } |
| 94 | 105 |
| 95 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { | 106 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { |
| 96 return true; | 107 return true; |
| 97 } | 108 } |
| OLD | NEW |