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 @@ ...@@ -9,6 +9,8 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/utf_string_conversions.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/browser/ui/webui/welcome/nux/bookmark_item.h"
#include "chrome/grit/browser_resources.h" #include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -57,8 +59,7 @@ constexpr const int kEmailIconSize = 48; // Pixels. ...@@ -57,8 +59,7 @@ constexpr const int kEmailIconSize = 48; // Pixels.
static_assert(base::size(kEmail) == (size_t)EmailProviders::kCount, static_assert(base::size(kEmail) == (size_t)EmailProviders::kCount,
"names and histograms must match"); "names and histograms must match");
EmailHandler::EmailHandler(favicon::FaviconService* favicon_service) EmailHandler::EmailHandler() {}
: favicon_service_(favicon_service) {}
EmailHandler::~EmailHandler() {} EmailHandler::~EmailHandler() {}
...@@ -89,11 +90,13 @@ void EmailHandler::HandleCacheEmailIcon(const base::ListValue* args) { ...@@ -89,11 +90,13 @@ void EmailHandler::HandleCacheEmailIcon(const base::ListValue* args) {
// pre-populated bookmarks don't have favicons and look bad. Favicons are // pre-populated bookmarks don't have favicons and look bad. Favicons are
// updated automatically when a user visits a site. // updated automatically when a user visits a site.
GURL app_url = GURL(selectedEmail->url); GURL app_url = GURL(selectedEmail->url);
favicon_service_->MergeFavicon( FaviconServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()),
app_url, app_url, favicon_base::IconType::kFavicon, ServiceAccessType::EXPLICIT_ACCESS)
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes( ->MergeFavicon(
selectedEmail->icon), app_url, app_url, favicon_base::IconType::kFavicon,
gfx::Size(kEmailIconSize, kEmailIconSize)); ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
selectedEmail->icon),
gfx::Size(kEmailIconSize, kEmailIconSize));
} }
void EmailHandler::HandleGetEmailList(const base::ListValue* args) { void EmailHandler::HandleGetEmailList(const base::ListValue* args) {
......
...@@ -13,10 +13,6 @@ namespace content { ...@@ -13,10 +13,6 @@ namespace content {
class WebUIDataSource; class WebUIDataSource;
} // namespace content } // namespace content
namespace favicon {
class FaviconService;
} // namespace favicon
namespace nux { namespace nux {
extern const char* kEmailInteractionHistogram; extern const char* kEmailInteractionHistogram;
...@@ -32,7 +28,7 @@ enum class EmailInteraction { ...@@ -32,7 +28,7 @@ enum class EmailInteraction {
class EmailHandler : public content::WebUIMessageHandler { class EmailHandler : public content::WebUIMessageHandler {
public: public:
explicit EmailHandler(favicon::FaviconService* favicon_service); EmailHandler();
~EmailHandler() override; ~EmailHandler() override;
// WebUIMessageHandler: // WebUIMessageHandler:
...@@ -45,10 +41,6 @@ class EmailHandler : public content::WebUIMessageHandler { ...@@ -45,10 +41,6 @@ class EmailHandler : public content::WebUIMessageHandler {
// Adds webui sources. // Adds webui sources.
static void AddSources(content::WebUIDataSource* html_source); static void AddSources(content::WebUIDataSource* html_source);
private:
// Weak reference.
favicon::FaviconService* favicon_service_;
DISALLOW_COPY_AND_ASSIGN(EmailHandler); DISALLOW_COPY_AND_ASSIGN(EmailHandler);
}; };
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/stl_util.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/browser/ui/webui/welcome/nux/bookmark_item.h"
#include "chrome/grit/browser_resources.h" #include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -54,8 +56,7 @@ const BookmarkItem kGoogleApps[] = { ...@@ -54,8 +56,7 @@ const BookmarkItem kGoogleApps[] = {
constexpr const int kGoogleAppIconSize = 48; // Pixels. constexpr const int kGoogleAppIconSize = 48; // Pixels.
GoogleAppsHandler::GoogleAppsHandler(favicon::FaviconService* favicon_service) GoogleAppsHandler::GoogleAppsHandler() {}
: favicon_service_(favicon_service) {}
GoogleAppsHandler::~GoogleAppsHandler() {} GoogleAppsHandler::~GoogleAppsHandler() {}
...@@ -88,11 +89,13 @@ void GoogleAppsHandler::HandleCacheGoogleAppIcon(const base::ListValue* args) { ...@@ -88,11 +89,13 @@ void GoogleAppsHandler::HandleCacheGoogleAppIcon(const base::ListValue* args) {
// pre-populated bookmarks don't have favicons and look bad. Favicons are // pre-populated bookmarks don't have favicons and look bad. Favicons are
// updated automatically when a user visits a site. // updated automatically when a user visits a site.
GURL app_url = GURL(selectedApp->url); GURL app_url = GURL(selectedApp->url);
favicon_service_->MergeFavicon( FaviconServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()),
app_url, app_url, favicon_base::IconType::kFavicon, ServiceAccessType::EXPLICIT_ACCESS)
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes( ->MergeFavicon(
selectedApp->icon), app_url, app_url, favicon_base::IconType::kFavicon,
gfx::Size(kGoogleAppIconSize, kGoogleAppIconSize)); ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
selectedApp->icon),
gfx::Size(kGoogleAppIconSize, kGoogleAppIconSize));
} }
void GoogleAppsHandler::HandleGetGoogleAppsList(const base::ListValue* args) { void GoogleAppsHandler::HandleGetGoogleAppsList(const base::ListValue* args) {
......
...@@ -13,10 +13,6 @@ namespace content { ...@@ -13,10 +13,6 @@ namespace content {
class WebUIDataSource; class WebUIDataSource;
} // namespace content } // namespace content
namespace favicon {
class FaviconService;
} // namespace favicon
namespace nux { namespace nux {
extern const char* kGoogleAppsInteractionHistogram; extern const char* kGoogleAppsInteractionHistogram;
...@@ -32,7 +28,7 @@ enum class GoogleAppsInteraction { ...@@ -32,7 +28,7 @@ enum class GoogleAppsInteraction {
class GoogleAppsHandler : public content::WebUIMessageHandler { class GoogleAppsHandler : public content::WebUIMessageHandler {
public: public:
explicit GoogleAppsHandler(favicon::FaviconService* favicon_service); GoogleAppsHandler();
~GoogleAppsHandler() override; ~GoogleAppsHandler() override;
// WebUIMessageHandler: // WebUIMessageHandler:
...@@ -45,10 +41,6 @@ class GoogleAppsHandler : public content::WebUIMessageHandler { ...@@ -45,10 +41,6 @@ class GoogleAppsHandler : public content::WebUIMessageHandler {
// Adds webui sources. // Adds webui sources.
static void AddSources(content::WebUIDataSource* html_source); static void AddSources(content::WebUIDataSource* html_source);
private:
// Weak reference.
favicon::FaviconService* favicon_service_;
DISALLOW_COPY_AND_ASSIGN(GoogleAppsHandler); DISALLOW_COPY_AND_ASSIGN(GoogleAppsHandler);
}; };
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "build/build_config.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/signin/account_consistency_mode_manager.h"
#include "chrome/browser/ui/webui/welcome/nux/bookmark_handler.h" #include "chrome/browser/ui/webui/welcome/nux/bookmark_handler.h"
#include "chrome/browser/ui/webui/welcome/nux/constants.h" #include "chrome/browser/ui/webui/welcome/nux/constants.h"
...@@ -198,15 +197,11 @@ WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url) ...@@ -198,15 +197,11 @@ WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
std::make_unique<nux::BookmarkHandler>(profile->GetPrefs())); std::make_unique<nux::BookmarkHandler>(profile->GetPrefs()));
// Add email provider bookmarking onboarding module. // Add email provider bookmarking onboarding module.
web_ui->AddMessageHandler(std::make_unique<nux::EmailHandler>( web_ui->AddMessageHandler(std::make_unique<nux::EmailHandler>());
FaviconServiceFactory::GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS)));
nux::EmailHandler::AddSources(html_source); nux::EmailHandler::AddSources(html_source);
// Add google apps bookmarking onboarding module. // Add google apps bookmarking onboarding module.
web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>( web_ui->AddMessageHandler(std::make_unique<nux::GoogleAppsHandler>());
FaviconServiceFactory::GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS)));
nux::GoogleAppsHandler::AddSources(html_source); nux::GoogleAppsHandler::AddSources(html_source);
// Add set-as-default onboarding module. // 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