Commit 3bb4c578 authored by Scott Chen's avatar Scott Chen Committed by Commit Bot

Nux Onboarding: move FaviconService initialization to handlers.

Bug: 891807
Change-Id: I7d630d5736de4c4b33efd958298cb3f941780129
Reviewed-on: https://chromium-review.googlesource.com/c/1300675
Commit-Queue: Scott Chen <scottchen@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604075}
parent 35e82159
......@@ -9,6 +9,8 @@
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/welcome/nux/bookmark_item.h"
#include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h"
......@@ -57,8 +59,7 @@ constexpr const int kEmailIconSize = 48; // Pixels.
static_assert(base::size(kEmail) == (size_t)EmailProviders::kCount,
"names and histograms must match");
EmailHandler::EmailHandler(favicon::FaviconService* favicon_service)
: favicon_service_(favicon_service) {}
EmailHandler::EmailHandler() {}
EmailHandler::~EmailHandler() {}
......@@ -89,11 +90,13 @@ void EmailHandler::HandleCacheEmailIcon(const base::ListValue* args) {
// pre-populated bookmarks don't have favicons and look bad. Favicons are
// updated automatically when a user visits a site.
GURL app_url = GURL(selectedEmail->url);
favicon_service_->MergeFavicon(
app_url, app_url, favicon_base::IconType::kFavicon,
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
selectedEmail->icon),
gfx::Size(kEmailIconSize, kEmailIconSize));
FaviconServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()),
ServiceAccessType::EXPLICIT_ACCESS)
->MergeFavicon(
app_url, app_url, favicon_base::IconType::kFavicon,
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
selectedEmail->icon),
gfx::Size(kEmailIconSize, kEmailIconSize));
}
void EmailHandler::HandleGetEmailList(const base::ListValue* args) {
......
......@@ -13,10 +13,6 @@ namespace content {
class WebUIDataSource;
} // namespace content
namespace favicon {
class FaviconService;
} // namespace favicon
namespace nux {
extern const char* kEmailInteractionHistogram;
......@@ -32,7 +28,7 @@ enum class EmailInteraction {
class EmailHandler : public content::WebUIMessageHandler {
public:
explicit EmailHandler(favicon::FaviconService* favicon_service);
EmailHandler();
~EmailHandler() override;
// WebUIMessageHandler:
......@@ -45,10 +41,6 @@ class EmailHandler : public content::WebUIMessageHandler {
// Adds webui sources.
static void AddSources(content::WebUIDataSource* html_source);
private:
// Weak reference.
favicon::FaviconService* favicon_service_;
DISALLOW_COPY_AND_ASSIGN(EmailHandler);
};
......
......@@ -8,6 +8,8 @@
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/welcome/nux/bookmark_item.h"
#include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h"
......@@ -54,8 +56,7 @@ const BookmarkItem kGoogleApps[] = {
constexpr const int kGoogleAppIconSize = 48; // Pixels.
GoogleAppsHandler::GoogleAppsHandler(favicon::FaviconService* favicon_service)
: favicon_service_(favicon_service) {}
GoogleAppsHandler::GoogleAppsHandler() {}
GoogleAppsHandler::~GoogleAppsHandler() {}
......@@ -88,11 +89,13 @@ void GoogleAppsHandler::HandleCacheGoogleAppIcon(const base::ListValue* args) {
// pre-populated bookmarks don't have favicons and look bad. Favicons are
// updated automatically when a user visits a site.
GURL app_url = GURL(selectedApp->url);
favicon_service_->MergeFavicon(
app_url, app_url, favicon_base::IconType::kFavicon,
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
selectedApp->icon),
gfx::Size(kGoogleAppIconSize, kGoogleAppIconSize));
FaviconServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()),
ServiceAccessType::EXPLICIT_ACCESS)
->MergeFavicon(
app_url, app_url, favicon_base::IconType::kFavicon,
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
selectedApp->icon),
gfx::Size(kGoogleAppIconSize, kGoogleAppIconSize));
}
void GoogleAppsHandler::HandleGetGoogleAppsList(const base::ListValue* args) {
......
......@@ -13,10 +13,6 @@ namespace content {
class WebUIDataSource;
} // namespace content
namespace favicon {
class FaviconService;
} // namespace favicon
namespace nux {
extern const char* kGoogleAppsInteractionHistogram;
......@@ -32,7 +28,7 @@ enum class GoogleAppsInteraction {
class GoogleAppsHandler : public content::WebUIMessageHandler {
public:
explicit GoogleAppsHandler(favicon::FaviconService* favicon_service);
GoogleAppsHandler();
~GoogleAppsHandler() override;
// WebUIMessageHandler:
......@@ -45,10 +41,6 @@ class GoogleAppsHandler : public content::WebUIMessageHandler {
// Adds webui sources.
static void AddSources(content::WebUIDataSource* html_source);
private:
// Weak reference.
favicon::FaviconService* favicon_service_;
DISALLOW_COPY_AND_ASSIGN(GoogleAppsHandler);
};
......
......@@ -9,7 +9,6 @@
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/ui/webui/welcome/nux/bookmark_handler.h"
#include "chrome/browser/ui/webui/welcome/nux/constants.h"
......@@ -198,15 +197,11 @@ WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
std::make_unique<nux::BookmarkHandler>(profile->GetPrefs()));
// Add email provider bookmarking onboarding module.
web_ui->AddMessageHandler(std::make_unique<nux::EmailHandler>(
FaviconServiceFactory::GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS)));
web_ui->AddMessageHandler(std::make_unique<nux::EmailHandler>());
nux::EmailHandler::AddSources(html_source);
// Add google apps bookmarking onboarding module.
web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>(
FaviconServiceFactory::GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS)));
web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>());
nux::GoogleAppsHandler::AddSources(html_source);
// Add set-as-default onboarding module.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment