Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: chrome/browser/bookmarks/bookmark_model_factory.cc

Issue 1904613005: [Offline pages] Removing bookmarks dependency from offline pages component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit tests compilation Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_model_factory.h"
31 #include "components/offline_pages/offline_page_bookmark_bridge.h"
32 #include "components/offline_pages/offline_page_feature.h"
33 #include "components/offline_pages/offline_page_model.h"
34 #endif // BUILDFLAG(ANDROID_JAVA_UI)
35
36 using bookmarks::BookmarkModel; 29 using bookmarks::BookmarkModel;
37 30
38 // static 31 // static
39 BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) { 32 BookmarkModel* BookmarkModelFactory::GetForProfile(Profile* profile) {
40 return static_cast<BookmarkModel*>( 33 return static_cast<BookmarkModel*>(
41 GetInstance()->GetServiceForBrowserContext(profile, true)); 34 GetInstance()->GetServiceForBrowserContext(profile, true));
42 } 35 }
43 36
44 // static 37 // static
45 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) { 38 BookmarkModel* BookmarkModelFactory::GetForProfileIfExists(Profile* profile) {
46 return static_cast<BookmarkModel*>( 39 return static_cast<BookmarkModel*>(
47 GetInstance()->GetServiceForBrowserContext(profile, false)); 40 GetInstance()->GetServiceForBrowserContext(profile, false));
48 } 41 }
49 42
50 // static 43 // static
51 BookmarkModelFactory* BookmarkModelFactory::GetInstance() { 44 BookmarkModelFactory* BookmarkModelFactory::GetInstance() {
52 return base::Singleton<BookmarkModelFactory>::get(); 45 return base::Singleton<BookmarkModelFactory>::get();
53 } 46 }
54 47
55 BookmarkModelFactory::BookmarkModelFactory() 48 BookmarkModelFactory::BookmarkModelFactory()
56 : BrowserContextKeyedServiceFactory( 49 : BrowserContextKeyedServiceFactory(
57 "BookmarkModel", 50 "BookmarkModel",
58 BrowserContextDependencyManager::GetInstance()) { 51 BrowserContextDependencyManager::GetInstance()) {
59 DependsOn(BookmarkUndoServiceFactory::GetInstance()); 52 DependsOn(BookmarkUndoServiceFactory::GetInstance());
60 DependsOn(ManagedBookmarkServiceFactory::GetInstance()); 53 DependsOn(ManagedBookmarkServiceFactory::GetInstance());
61 DependsOn(StartupTaskRunnerServiceFactory::GetInstance()); 54 DependsOn(StartupTaskRunnerServiceFactory::GetInstance());
62 #if BUILDFLAG(ANDROID_JAVA_UI)
63 if (offline_pages::IsOfflinePagesEnabled())
64 DependsOn(offline_pages::OfflinePageModelFactory::GetInstance());
65 #endif
66 } 55 }
67 56
68 BookmarkModelFactory::~BookmarkModelFactory() { 57 BookmarkModelFactory::~BookmarkModelFactory() {
69 } 58 }
70 59
71 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( 60 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor(
72 content::BrowserContext* context) const { 61 content::BrowserContext* context) const {
73 Profile* profile = Profile::FromBrowserContext(context); 62 Profile* profile = Profile::FromBrowserContext(context);
74 BookmarkModel* bookmark_model = 63 BookmarkModel* bookmark_model =
75 new BookmarkModel(base::WrapUnique(new ChromeBookmarkClient( 64 new BookmarkModel(base::WrapUnique(new ChromeBookmarkClient(
76 profile, ManagedBookmarkServiceFactory::GetForProfile(profile)))); 65 profile, ManagedBookmarkServiceFactory::GetForProfile(profile))));
77 bookmark_model->Load(profile->GetPrefs(), 66 bookmark_model->Load(profile->GetPrefs(),
78 profile->GetPath(), 67 profile->GetPath(),
79 StartupTaskRunnerServiceFactory::GetForProfile(profile) 68 StartupTaskRunnerServiceFactory::GetForProfile(profile)
80 ->GetBookmarkTaskRunner(), 69 ->GetBookmarkTaskRunner(),
81 content::BrowserThread::GetMessageLoopProxyForThread( 70 content::BrowserThread::GetMessageLoopProxyForThread(
82 content::BrowserThread::UI)); 71 content::BrowserThread::UI));
83 bool register_bookmark_undo_service_as_observer = true; 72 bool register_bookmark_undo_service_as_observer = true;
84 #if !BUILDFLAG(ANDROID_JAVA_UI) 73 #if !BUILDFLAG(ANDROID_JAVA_UI)
85 register_bookmark_undo_service_as_observer = 74 register_bookmark_undo_service_as_observer =
86 base::CommandLine::ForCurrentProcess()->HasSwitch( 75 base::CommandLine::ForCurrentProcess()->HasSwitch(
87 switches::kEnableBookmarkUndo); 76 switches::kEnableBookmarkUndo);
88 #endif // !BUILDFLAG(ANDROID_JAVA_UI) 77 #endif // !BUILDFLAG(ANDROID_JAVA_UI)
89 if (register_bookmark_undo_service_as_observer) 78 if (register_bookmark_undo_service_as_observer)
90 BookmarkUndoServiceFactory::GetForProfile(profile)->Start(bookmark_model); 79 BookmarkUndoServiceFactory::GetForProfile(profile)->Start(bookmark_model);
91 80
92 #if BUILDFLAG(ANDROID_JAVA_UI)
93 if (offline_pages::IsOfflinePagesEnabled()) {
94 // This observer will delete itself when BookmarkModelDeleted is called.
95 bookmark_model->AddObserver(new offline_pages::OfflinePageBookmarkBridge(
96 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile),
97 bookmark_model));
98 }
99 #endif // BUILDFLAG(ANDROID_JAVA_UI)
100
101 return bookmark_model; 81 return bookmark_model;
102 } 82 }
103 83
104 void BookmarkModelFactory::RegisterProfilePrefs( 84 void BookmarkModelFactory::RegisterProfilePrefs(
105 user_prefs::PrefRegistrySyncable* registry) { 85 user_prefs::PrefRegistrySyncable* registry) {
106 bookmarks::RegisterProfilePrefs(registry); 86 bookmarks::RegisterProfilePrefs(registry);
107 } 87 }
108 88
109 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( 89 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse(
110 content::BrowserContext* context) const { 90 content::BrowserContext* context) const {
111 return chrome::GetBrowserContextRedirectedInIncognito(context); 91 return chrome::GetBrowserContextRedirectedInIncognito(context);
112 } 92 }
113 93
114 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { 94 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const {
115 return true; 95 return true;
116 } 96 }
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/offline_page_utils_unittest.cc ('k') | chrome/browser/net/net_error_tab_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698