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

Side by Side Diff: chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.cc

Issue 2572533002: Add ChromeMostVisitedSitesFactory (Closed)
Patch Set: Use factory for webui Created 4 years 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 2013 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/ntp_tiles/chrome_most_visited_sites_factory.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/callback.h"
11 #include "base/memory/ptr_util.h"
12 #include "chrome/browser/favicon/favicon_service_factory.h"
13 #include "chrome/browser/history/top_sites_factory.h"
14 #include "chrome/browser/ntp_tiles/chrome_popular_sites_factory.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/search/suggestions/image_decoder_impl.h"
17 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
18 #include "chrome/browser/supervised_user/supervised_user_service.h"
19 #include "chrome/browser/supervised_user/supervised_user_service_factory.h"
20 #include "chrome/browser/supervised_user/supervised_user_service_observer.h"
21 #include "chrome/browser/supervised_user/supervised_user_url_filter.h"
22 #include "chrome/browser/thumbnails/thumbnail_list_source.h"
23 #include "components/history/core/browser/top_sites.h"
24 #include "components/image_fetcher/image_fetcher_impl.h"
25 #include "components/ntp_tiles/icon_cacher.h"
26 #include "components/ntp_tiles/metrics.h"
27 #include "components/ntp_tiles/most_visited_sites.h"
28
29 using suggestions::SuggestionsServiceFactory;
30
31 namespace {
32
33 class SupervisorBridge : public ntp_tiles::MostVisitedSitesSupervisor,
34 public SupervisedUserServiceObserver {
35 public:
36 explicit SupervisorBridge(Profile* profile);
37 ~SupervisorBridge() override;
38
39 void SetObserver(Observer* observer) override;
40 bool IsBlocked(const GURL& url) override;
41 std::vector<MostVisitedSitesSupervisor::Whitelist> whitelists() override;
42 bool IsChildProfile() override;
43
44 // SupervisedUserServiceObserver implementation.
45 void OnURLFilterChanged() override;
46
47 private:
48 Profile* const profile_;
49 Observer* supervisor_observer_;
50 ScopedObserver<SupervisedUserService, SupervisedUserServiceObserver>
51 register_observer_;
52 };
53
54 SupervisorBridge::SupervisorBridge(Profile* profile)
55 : profile_(profile),
56 supervisor_observer_(nullptr),
57 register_observer_(this) {
58 register_observer_.Add(SupervisedUserServiceFactory::GetForProfile(profile_));
59 }
60
61 SupervisorBridge::~SupervisorBridge() {}
62
63 void SupervisorBridge::SetObserver(Observer* new_observer) {
64 if (new_observer) {
65 DCHECK(!supervisor_observer_);
66 } else {
67 DCHECK(supervisor_observer_);
68 }
69
70 supervisor_observer_ = new_observer;
71 }
72
73 bool SupervisorBridge::IsBlocked(const GURL& url) {
74 SupervisedUserService* supervised_user_service =
75 SupervisedUserServiceFactory::GetForProfile(profile_);
76 auto* url_filter = supervised_user_service->GetURLFilterForUIThread();
77 return url_filter->GetFilteringBehaviorForURL(url) ==
78 SupervisedUserURLFilter::FilteringBehavior::BLOCK;
79 }
80
81 std::vector<ntp_tiles::MostVisitedSitesSupervisor::Whitelist>
82 SupervisorBridge::whitelists() {
83 std::vector<MostVisitedSitesSupervisor::Whitelist> results;
84 SupervisedUserService* supervised_user_service =
85 SupervisedUserServiceFactory::GetForProfile(profile_);
86 for (const auto& whitelist : supervised_user_service->whitelists()) {
87 results.emplace_back(Whitelist{
88 whitelist->title(), whitelist->entry_point(),
89 whitelist->large_icon_path(),
90 });
91 }
92 return results;
93 }
94
95 bool SupervisorBridge::IsChildProfile() {
96 return profile_->IsChild();
97 }
98
99 void SupervisorBridge::OnURLFilterChanged() {
100 if (supervisor_observer_) {
101 supervisor_observer_->OnBlockedSitesChanged();
102 }
103 }
104
105 } // namespace
106
107 // static
108 std::unique_ptr<ntp_tiles::MostVisitedSites>
109 ChromeMostVisitedSitesFactory::NewForProfile(Profile* profile) {
110 return base::MakeUnique<ntp_tiles::MostVisitedSites>(
111 profile->GetPrefs(), TopSitesFactory::GetForProfile(profile),
112 SuggestionsServiceFactory::GetForProfile(profile),
113 #if defined(OS_ANDROID)
114 ChromePopularSitesFactory::NewForProfile(profile),
115 #else
116 nullptr,
117 #endif
118 base::MakeUnique<ntp_tiles::IconCacher>(
119 FaviconServiceFactory::GetForProfile(
120 profile, ServiceAccessType::IMPLICIT_ACCESS),
121 base::MakeUnique<image_fetcher::ImageFetcherImpl>(
122 base::MakeUnique<suggestions::ImageDecoderImpl>(),
123 profile->GetRequestContext())),
124 base::MakeUnique<SupervisorBridge>(profile));
125 }
OLDNEW
« no previous file with comments | « chrome/browser/ntp_tiles/chrome_most_visited_sites_factory.h ('k') | chrome/browser/ntp_tiles/chrome_popular_sites_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698