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

Side by Side Diff: chrome/browser/android/ntp/bookmark_suggestions_provider_factory.cc

Issue 2190583002: Add bookmark provider for content suggestions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments #2 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/ntp/bookmark_suggestions_provider_factory.h"
6
7 #include "base/feature_list.h"
8 #include "base/memory/singleton.h"
9 #include "chrome/browser/android/chrome_feature_list.h"
10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
11 #include "chrome/browser/ntp_snippets/content_suggestions_service_factory.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "components/bookmarks/browser/bookmark_model.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15 #include "components/ntp_snippets/bookmarks/bookmark_suggestions_provider.h"
16 #include "components/ntp_snippets/content_suggestions_service.h"
17 #include "content/public/browser/browser_context.h"
18
19 using ntp_snippets::ContentSuggestionsService;
20 using ntp_snippets::BookmarkSuggestionsProvider;
21 using bookmarks::BookmarkModel;
22
23 // static
24 BookmarkSuggestionsProviderFactory*
25 BookmarkSuggestionsProviderFactory::GetInstance() {
26 return base::Singleton<BookmarkSuggestionsProviderFactory>::get();
27 }
28
29 // static
30 BookmarkSuggestionsProvider* BookmarkSuggestionsProviderFactory::GetForProfile(
31 Profile* profile) {
32 DCHECK(!profile->IsOffTheRecord());
33 return static_cast<BookmarkSuggestionsProvider*>(
34 GetInstance()->GetServiceForBrowserContext(profile, true));
35 }
36
37 BookmarkSuggestionsProviderFactory::BookmarkSuggestionsProviderFactory()
38 : BrowserContextKeyedServiceFactory(
39 "BookmarkSuggestionsProvider",
40 BrowserContextDependencyManager::GetInstance()) {
41 DependsOn(ContentSuggestionsServiceFactory::GetInstance());
42 DependsOn(BookmarkModelFactory::GetInstance());
43 }
44
45 BookmarkSuggestionsProviderFactory::~BookmarkSuggestionsProviderFactory() {}
46
47 KeyedService* BookmarkSuggestionsProviderFactory::BuildServiceInstanceFor(
48 content::BrowserContext* context) const {
49 Profile* profile = Profile::FromBrowserContext(context);
50
51 ContentSuggestionsService* content_suggestions_service =
52 ContentSuggestionsServiceFactory::GetForProfile(profile);
53 if (content_suggestions_service->state() ==
54 ContentSuggestionsService::State::DISABLED) {
55 return nullptr;
56 }
57
58 if (!base::FeatureList::IsEnabled(
59 chrome::android::kNTPBookmarkSuggestionsFeature)) {
60 return nullptr;
61 }
62
63 BookmarkModel* bookmark_model = BookmarkModelFactory::GetForProfile(profile);
64
65 BookmarkSuggestionsProvider* bookmark_suggestions_provider =
66 new BookmarkSuggestionsProvider(bookmark_model);
67 content_suggestions_service->RegisterProvider(bookmark_suggestions_provider);
68 return bookmark_suggestions_provider;
69 }
OLDNEW
« no previous file with comments | « chrome/browser/android/ntp/bookmark_suggestions_provider_factory.h ('k') | chrome/browser/profiles/profile_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698