Commit 82ae5869 authored by Hector Carmona's avatar Hector Carmona Committed by Commit Bot

NUX Google Apps - Preload icons for bookmarks created on first run.

We are preloading the favicon cache for bookmarks created by this
onboarding flow. The icons that we preload are overdidden when the
user navigates to the site.

Bug: 832938
Change-Id: I3866ca4fdbc1044f7492f85f7f52c6d119a2a227
Reviewed-on: https://chromium-review.googlesource.com/1168397Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Commit-Queue: Hector Carmona <hcarmona@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581939}
parent 3db2d0fb
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <string> #include <string>
#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_handler.h" #include "chrome/browser/ui/webui/welcome_handler.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
...@@ -16,6 +17,7 @@ ...@@ -16,6 +17,7 @@
#include "chrome/grit/chromium_strings.h" #include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/sync/driver/sync_service.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "net/base/url_util.h" #include "net/base/url_util.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -115,6 +117,8 @@ WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url) ...@@ -115,6 +117,8 @@ WelcomeUI::WelcomeUI(content::WebUI* web_ui, const GURL& url)
web_ui->AddMessageHandler( web_ui->AddMessageHandler(
std::make_unique<nux_google_apps::GoogleAppsHandler>( std::make_unique<nux_google_apps::GoogleAppsHandler>(
profile->GetPrefs(), profile->GetPrefs(),
FaviconServiceFactory::GetForProfile(
profile, ServiceAccessType::EXPLICIT_ACCESS),
BookmarkModelFactory::GetForBrowserContext(browser_context))); BookmarkModelFactory::GetForBrowserContext(browser_context)));
nux_google_apps::GoogleAppsHandler::AddSources(html_source); nux_google_apps::GoogleAppsHandler::AddSources(html_source);
......
...@@ -22,6 +22,7 @@ if (is_win && is_chrome_branded) { ...@@ -22,6 +22,7 @@ if (is_win && is_chrome_branded) {
deps = [ deps = [
"//components/bookmarks/browser", "//components/bookmarks/browser",
"//components/bookmarks/common", "//components/bookmarks/common",
"//components/favicon/core",
"//components/pref_registry", "//components/pref_registry",
"//components/prefs", "//components/prefs",
"//components/resources", "//components/resources",
......
...@@ -3,6 +3,8 @@ include_rules = [ ...@@ -3,6 +3,8 @@ include_rules = [
"+components/grit", "+components/grit",
"+components/prefs", "+components/prefs",
"+components/nux", "+components/nux",
"+components/favicon",
"+components/strings/grit/components_strings.h", "+components/strings/grit/components_strings.h",
"+content/public/browser", "+content/public/browser",
"+ui/base",
] ]
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h" #include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/common/bookmark_pref_names.h" #include "components/bookmarks/common/bookmark_pref_names.h"
#include "components/favicon/core/favicon_service.h"
#include "components/grit/components_resources.h" #include "components/grit/components_resources.h"
#include "components/grit/components_scaled_resources.h" #include "components/grit/components_scaled_resources.h"
#include "components/nux/show_promo_delegate.h" #include "components/nux/show_promo_delegate.h"
...@@ -20,6 +21,7 @@ ...@@ -20,6 +21,7 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h" #include "content/public/browser/web_ui_data_source.h"
#include "ui/base/resource/resource_bundle.h"
namespace nux_google_apps { namespace nux_google_apps {
...@@ -51,14 +53,26 @@ constexpr const char* kGoogleAppUrls[] = { ...@@ -51,14 +53,26 @@ constexpr const char* kGoogleAppUrls[] = {
"https://news.google.com", "https://chrome.google.com/webstore", "https://news.google.com", "https://chrome.google.com/webstore",
}; };
constexpr const int kGoogleAppIconSize = 48; // Pixels.
constexpr const int kGoogleAppIcons[] = {
IDR_NUX_GOOGLE_APPS_GMAIL_1X, IDR_NUX_GOOGLE_APPS_YOUTUBE_1X,
IDR_NUX_GOOGLE_APPS_MAPS_1X, IDR_NUX_GOOGLE_APPS_TRANSLATE_1X,
IDR_NUX_GOOGLE_APPS_NEWS_1X, IDR_NUX_GOOGLE_APPS_CHROME_STORE_1X,
};
static_assert(base::size(kGoogleAppNames) == base::size(kGoogleAppUrls), static_assert(base::size(kGoogleAppNames) == base::size(kGoogleAppUrls),
"names and urls must match"); "names and urls must match");
static_assert(base::size(kGoogleAppNames) == (size_t)GoogleApps::kCount, static_assert(base::size(kGoogleAppNames) == (size_t)GoogleApps::kCount,
"names and histograms must match"); "names and histograms must match");
static_assert(base::size(kGoogleAppNames) == base::size(kGoogleAppIcons),
"names and icons must match");
GoogleAppsHandler::GoogleAppsHandler(PrefService* prefs, GoogleAppsHandler::GoogleAppsHandler(PrefService* prefs,
favicon::FaviconService* favicon_service,
bookmarks::BookmarkModel* bookmark_model) bookmarks::BookmarkModel* bookmark_model)
: prefs_(prefs), bookmark_model_(bookmark_model) {} : prefs_(prefs),
favicon_service_(favicon_service),
bookmark_model_(bookmark_model) {}
GoogleAppsHandler::~GoogleAppsHandler() {} GoogleAppsHandler::~GoogleAppsHandler() {}
...@@ -90,9 +104,19 @@ void GoogleAppsHandler::HandleAddGoogleApps(const base::ListValue* args) { ...@@ -90,9 +104,19 @@ void GoogleAppsHandler::HandleAddGoogleApps(const base::ListValue* args) {
UMA_HISTOGRAM_ENUMERATION( UMA_HISTOGRAM_ENUMERATION(
"FirstRun.NewUserExperience.GoogleAppsSelection", (GoogleApps)i, "FirstRun.NewUserExperience.GoogleAppsSelection", (GoogleApps)i,
GoogleApps::kCount); GoogleApps::kCount);
bookmark_model_->AddURL( GURL app_url = GURL(kGoogleAppUrls[i]);
bookmark_model_->bookmark_bar_node(), bookmarkIndex++, bookmark_model_->AddURL(bookmark_model_->bookmark_bar_node(),
base::ASCIIToUTF16(kGoogleAppNames[i]), GURL(kGoogleAppUrls[i])); bookmarkIndex++,
base::ASCIIToUTF16(kGoogleAppNames[i]), app_url);
// Preload the favicon cache with Chrome-bundled images. Otherwise, the
// pre-populated bookmarks don't have favicons and look bad. Favicons are
// updated automatically when a user visits a site.
favicon_service_->MergeFavicon(
app_url, app_url, favicon_base::IconType::kFavicon,
ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
kGoogleAppIcons[i]),
gfx::Size(kGoogleAppIconSize, kGoogleAppIconSize));
} }
} }
......
...@@ -19,6 +19,10 @@ namespace content { ...@@ -19,6 +19,10 @@ namespace content {
class WebUIDataSource; class WebUIDataSource;
} // namespace content } // namespace content
namespace favicon {
class FaviconService;
} // namespace favicon
namespace nux_google_apps { namespace nux_google_apps {
extern const char* kGoogleAppsInteractionHistogram; extern const char* kGoogleAppsInteractionHistogram;
...@@ -35,6 +39,7 @@ enum class GoogleAppsInteraction { ...@@ -35,6 +39,7 @@ enum class GoogleAppsInteraction {
class GoogleAppsHandler : public content::WebUIMessageHandler { class GoogleAppsHandler : public content::WebUIMessageHandler {
public: public:
GoogleAppsHandler(PrefService* prefs, GoogleAppsHandler(PrefService* prefs,
favicon::FaviconService* favicon_service,
bookmarks::BookmarkModel* bookmark_model); bookmarks::BookmarkModel* bookmark_model);
~GoogleAppsHandler() override; ~GoogleAppsHandler() override;
...@@ -52,6 +57,9 @@ class GoogleAppsHandler : public content::WebUIMessageHandler { ...@@ -52,6 +57,9 @@ class GoogleAppsHandler : public content::WebUIMessageHandler {
// Weak reference. // Weak reference.
PrefService* prefs_; PrefService* prefs_;
// Weak reference.
favicon::FaviconService* favicon_service_;
// Weak reference. // Weak reference.
bookmarks::BookmarkModel* bookmark_model_; bookmarks::BookmarkModel* bookmark_model_;
......
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