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

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

Issue 2185973003: [Offline Pages] Delete associated page along with bookmark. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unintended changes. Created 4 years, 4 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
« no previous file with comments | « no previous file | components/offline_pages/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/offline_pages/offline_page_bookmark_observer.h"
26 #include "components/offline_pages/offline_page_model.h"
25 #include "components/prefs/pref_service.h" 27 #include "components/prefs/pref_service.h"
26 #include "components/undo/bookmark_undo_service.h" 28 #include "components/undo/bookmark_undo_service.h"
27 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
28 30
31 #if BUILDFLAG(ANDROID_JAVA_UI)
32 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h"
33 #endif
34
29 using bookmarks::BookmarkModel; 35 using bookmarks::BookmarkModel;
30 36
31 // static 37 // static
32 BookmarkModel* BookmarkModelFactory::GetForBrowserContext( 38 BookmarkModel* BookmarkModelFactory::GetForBrowserContext(
33 content::BrowserContext* context) { 39 content::BrowserContext* context) {
34 return static_cast<BookmarkModel*>( 40 return static_cast<BookmarkModel*>(
35 GetInstance()->GetServiceForBrowserContext(context, true)); 41 GetInstance()->GetServiceForBrowserContext(context, true));
36 } 42 }
37 43
38 // static 44 // static
39 BookmarkModel* BookmarkModelFactory::GetForBrowserContextIfExists( 45 BookmarkModel* BookmarkModelFactory::GetForBrowserContextIfExists(
40 content::BrowserContext* context) { 46 content::BrowserContext* context) {
41 return static_cast<BookmarkModel*>( 47 return static_cast<BookmarkModel*>(
42 GetInstance()->GetServiceForBrowserContext(context, false)); 48 GetInstance()->GetServiceForBrowserContext(context, false));
43 } 49 }
44 50
45 // static 51 // static
46 BookmarkModelFactory* BookmarkModelFactory::GetInstance() { 52 BookmarkModelFactory* BookmarkModelFactory::GetInstance() {
47 return base::Singleton<BookmarkModelFactory>::get(); 53 return base::Singleton<BookmarkModelFactory>::get();
48 } 54 }
49 55
50 BookmarkModelFactory::BookmarkModelFactory() 56 BookmarkModelFactory::BookmarkModelFactory()
51 : BrowserContextKeyedServiceFactory( 57 : BrowserContextKeyedServiceFactory(
52 "BookmarkModel", 58 "BookmarkModel",
53 BrowserContextDependencyManager::GetInstance()) { 59 BrowserContextDependencyManager::GetInstance()) {
54 DependsOn(BookmarkUndoServiceFactory::GetInstance()); 60 DependsOn(BookmarkUndoServiceFactory::GetInstance());
55 DependsOn(ManagedBookmarkServiceFactory::GetInstance()); 61 DependsOn(ManagedBookmarkServiceFactory::GetInstance());
62 #if BUILDFLAG(ANDROID_JAVA_UI)
63 DependsOn(offline_pages::OfflinePageModelFactory::GetInstance());
64 #endif
56 DependsOn(StartupTaskRunnerServiceFactory::GetInstance()); 65 DependsOn(StartupTaskRunnerServiceFactory::GetInstance());
57 } 66 }
58 67
59 BookmarkModelFactory::~BookmarkModelFactory() { 68 BookmarkModelFactory::~BookmarkModelFactory() {
60 } 69 }
61 70
62 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor( 71 KeyedService* BookmarkModelFactory::BuildServiceInstanceFor(
63 content::BrowserContext* context) const { 72 content::BrowserContext* context) const {
64 Profile* profile = Profile::FromBrowserContext(context); 73 Profile* profile = Profile::FromBrowserContext(context);
65 BookmarkModel* bookmark_model = 74 BookmarkModel* bookmark_model =
66 new BookmarkModel(base::WrapUnique(new ChromeBookmarkClient( 75 new BookmarkModel(base::WrapUnique(new ChromeBookmarkClient(
67 profile, ManagedBookmarkServiceFactory::GetForProfile(profile)))); 76 profile, ManagedBookmarkServiceFactory::GetForProfile(profile))));
68 bookmark_model->Load(profile->GetPrefs(), profile->GetPath(), 77 bookmark_model->Load(profile->GetPrefs(), profile->GetPath(),
69 StartupTaskRunnerServiceFactory::GetForProfile(profile) 78 StartupTaskRunnerServiceFactory::GetForProfile(profile)
70 ->GetBookmarkTaskRunner(), 79 ->GetBookmarkTaskRunner(),
71 content::BrowserThread::GetTaskRunnerForThread( 80 content::BrowserThread::GetTaskRunnerForThread(
72 content::BrowserThread::UI)); 81 content::BrowserThread::UI));
82 #if BUILDFLAG(ANDROID_JAVA_UI)
83 offline_pages::OfflinePageBookmarkObserver* offline_page_listener =
84 offline_pages::OfflinePageModelFactory::GetForBrowserContext(context)
Dmitry Titov 2016/08/17 03:58:36 But, doesn't it remove the benefit of having Offli
85 ->GetBookmarkObserver();
86 if (offline_page_listener)
87 bookmark_model->AddObserver(offline_page_listener);
88 #endif // BUILDFLAG(ANDROID_JAVA_UI)
73 bool register_bookmark_undo_service_as_observer = true; 89 bool register_bookmark_undo_service_as_observer = true;
90
74 #if !BUILDFLAG(ANDROID_JAVA_UI) 91 #if !BUILDFLAG(ANDROID_JAVA_UI)
75 register_bookmark_undo_service_as_observer = 92 register_bookmark_undo_service_as_observer =
76 base::CommandLine::ForCurrentProcess()->HasSwitch( 93 base::CommandLine::ForCurrentProcess()->HasSwitch(
77 switches::kEnableBookmarkUndo); 94 switches::kEnableBookmarkUndo);
78 #endif // !BUILDFLAG(ANDROID_JAVA_UI) 95 #endif // !BUILDFLAG(ANDROID_JAVA_UI)
79 if (register_bookmark_undo_service_as_observer) 96 if (register_bookmark_undo_service_as_observer)
80 BookmarkUndoServiceFactory::GetForProfile(profile)->Start(bookmark_model); 97 BookmarkUndoServiceFactory::GetForProfile(profile)->Start(bookmark_model);
81 98
82 return bookmark_model; 99 return bookmark_model;
83 } 100 }
84 101
85 void BookmarkModelFactory::RegisterProfilePrefs( 102 void BookmarkModelFactory::RegisterProfilePrefs(
86 user_prefs::PrefRegistrySyncable* registry) { 103 user_prefs::PrefRegistrySyncable* registry) {
87 bookmarks::RegisterProfilePrefs(registry); 104 bookmarks::RegisterProfilePrefs(registry);
88 } 105 }
89 106
90 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse( 107 content::BrowserContext* BookmarkModelFactory::GetBrowserContextToUse(
91 content::BrowserContext* context) const { 108 content::BrowserContext* context) const {
92 return chrome::GetBrowserContextRedirectedInIncognito(context); 109 return chrome::GetBrowserContextRedirectedInIncognito(context);
93 } 110 }
94 111
95 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const { 112 bool BookmarkModelFactory::ServiceIsNULLWhileTesting() const {
96 return true; 113 return true;
97 } 114 }
OLDNEW
« no previous file with comments | « no previous file | components/offline_pages/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698