Commit bf48cde8 authored by Hector Carmona's avatar Hector Carmona Committed by Commit Bot

Navi: Cache Google Apps bookmark icons from web ui.

Bug: 889222
Change-Id: I5af4c643bd14e3e52b37a931eb04b7d3c533c6f1
Reviewed-on: https://chromium-review.googlesource.com/c/1287437
Commit-Queue: Hector Carmona <hcarmona@chromium.org>
Reviewed-by: default avatarScott Chen <scottchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602971}
parent b63b45e4
...@@ -42,26 +42,28 @@ Polymer({ ...@@ -42,26 +42,28 @@ Polymer({
}, },
/** @private {nux.NuxGoogleAppsProxy} */ /** @private {nux.NuxGoogleAppsProxy} */
appProxy_: null, appsProxy_: null,
/** @private {nux.BookmarkProxy} */ /** @private {nux.BookmarkProxy} */
bookmarkProxy_: null, bookmarkProxy_: null,
/** @override */ /** @override */
ready() { ready() {
this.appProxy_ = nux.NuxGoogleAppsProxyImpl.getInstance(); this.appsProxy_ = nux.NuxGoogleAppsProxyImpl.getInstance();
this.bookmarkProxy_ = nux.BookmarkProxyImpl.getInstance(); this.bookmarkProxy_ = nux.BookmarkProxyImpl.getInstance();
}, },
/** Called when bookmarks should be created for all selected apps. */ /** Called when bookmarks should be created for all selected apps. */
populateAllBookmarks() { populateAllBookmarks() {
if (!this.appList_) { if (!this.appList_) {
this.appProxy_.getGoogleAppsList().then(list => { this.appsProxy_.getGoogleAppsList().then(list => {
this.appList_ = list; this.appList_ = list;
this.appList_.forEach(app => { this.appList_.forEach(app => {
// Default select all items. // Default select all items.
app.selected = true; app.selected = true;
this.updateBookmark(app); this.updateBookmark(app);
// Icons only need to be added to the cache once.
this.appsProxy_.cacheBookmarkIcon(app.id);
}); });
}); });
} }
......
...@@ -28,14 +28,13 @@ Polymer({ ...@@ -28,14 +28,13 @@ Polymer({
/** @private */ /** @private */
onNoThanksClicked_: function() { onNoThanksClicked_: function() {
chrome.send('rejectGoogleApps'); // TODO(hcarmona): Add metrics.
welcome.navigateToNextStep(); welcome.navigateToNextStep();
}, },
/** @private */ /** @private */
onGetStartedClicked_: function() { onGetStartedClicked_: function() {
let selectedApps = this.$.appChooser.getSelectedAppList(); // TODO(hcarmona): Add metrics.
nux.NuxGoogleAppsProxyImpl.getInstance().addGoogleApps(selectedApps);
welcome.navigateToNextStep(); welcome.navigateToNextStep();
}, },
}); });
...@@ -6,10 +6,11 @@ cr.define('nux', function() { ...@@ -6,10 +6,11 @@ cr.define('nux', function() {
/** @interface */ /** @interface */
class NuxGoogleAppsProxy { class NuxGoogleAppsProxy {
/** /**
* Adds the selected apps to the bookmark bar. * Google app IDs are local to the list of Google apps, so their icon must
* @param {!Array<boolean>} selectedApps * be cached by the handler that provided the IDs.
* @param {number} appId
*/ */
addGoogleApps(selectedApps) {} cacheBookmarkIcon(appId) {}
/** /**
* Returns a promise for an array of Google apps. * Returns a promise for an array of Google apps.
...@@ -21,8 +22,8 @@ cr.define('nux', function() { ...@@ -21,8 +22,8 @@ cr.define('nux', function() {
/** @implements {nux.NuxGoogleAppsProxy} */ /** @implements {nux.NuxGoogleAppsProxy} */
class NuxGoogleAppsProxyImpl { class NuxGoogleAppsProxyImpl {
/** @override */ /** @override */
addGoogleApps(selectedApps) { cacheBookmarkIcon(appId) {
chrome.send('addGoogleApps', selectedApps); chrome.send('cacheGoogleAppIcon', [appId]);
} }
/** @override */ /** @override */
...@@ -37,4 +38,4 @@ cr.define('nux', function() { ...@@ -37,4 +38,4 @@ cr.define('nux', function() {
NuxGoogleAppsProxy: NuxGoogleAppsProxy, NuxGoogleAppsProxy: NuxGoogleAppsProxy,
NuxGoogleAppsProxyImpl: NuxGoogleAppsProxyImpl, NuxGoogleAppsProxyImpl: NuxGoogleAppsProxyImpl,
}; };
}); });
\ No newline at end of file
...@@ -61,13 +61,8 @@ GoogleAppsHandler::~GoogleAppsHandler() {} ...@@ -61,13 +61,8 @@ GoogleAppsHandler::~GoogleAppsHandler() {}
void GoogleAppsHandler::RegisterMessages() { void GoogleAppsHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"rejectGoogleApps", "cacheGoogleAppIcon",
base::BindRepeating(&GoogleAppsHandler::HandleRejectGoogleApps, base::BindRepeating(&GoogleAppsHandler::HandleCacheGoogleAppIcon,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"addGoogleApps",
base::BindRepeating(&GoogleAppsHandler::HandleAddGoogleApps,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
...@@ -76,38 +71,28 @@ void GoogleAppsHandler::RegisterMessages() { ...@@ -76,38 +71,28 @@ void GoogleAppsHandler::RegisterMessages() {
base::Unretained(this))); base::Unretained(this)));
} }
void GoogleAppsHandler::HandleRejectGoogleApps(const base::ListValue* args) { void GoogleAppsHandler::HandleCacheGoogleAppIcon(const base::ListValue* args) {
UMA_HISTOGRAM_ENUMERATION(kGoogleAppsInteractionHistogram, int appId;
GoogleAppsInteraction::kNoThanks, args->GetInteger(0, &appId);
GoogleAppsInteraction::kCount);
}
void GoogleAppsHandler::HandleAddGoogleApps(const base::ListValue* args) { const BookmarkItem* selectedApp = NULL;
// Add bookmarks for all selected apps. for (size_t i = 0; i < base::size(kGoogleApps); i++) {
for (size_t i = 0; i < base::size(kGoogleApps); ++i) { if (static_cast<int>(kGoogleApps[i].id) == appId) {
bool selected = false; selectedApp = &kGoogleApps[i];
CHECK(args->GetBoolean(i, &selected)); break;
if (selected) {
UMA_HISTOGRAM_ENUMERATION(
"FirstRun.NewUserExperience.GoogleAppsSelection",
(GoogleApps)kGoogleApps[i].id, GoogleApps::kCount);
GURL app_url = GURL(kGoogleApps[i].url);
// TODO(hcarmona): Add bookmark from JS.
// 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(
kGoogleApps[i].icon),
gfx::Size(kGoogleAppIconSize, kGoogleAppIconSize));
} }
} }
CHECK(selectedApp); // WebUI should not be able to pass non-existent ID.
UMA_HISTOGRAM_ENUMERATION(kGoogleAppsInteractionHistogram,
GoogleAppsInteraction::kGetStarted, // Preload the favicon cache with Chrome-bundled images. Otherwise, the
GoogleAppsInteraction::kCount); // 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));
} }
void GoogleAppsHandler::HandleGetGoogleAppsList(const base::ListValue* args) { void GoogleAppsHandler::HandleGetGoogleAppsList(const base::ListValue* args) {
......
...@@ -39,8 +39,7 @@ class GoogleAppsHandler : public content::WebUIMessageHandler { ...@@ -39,8 +39,7 @@ class GoogleAppsHandler : public content::WebUIMessageHandler {
void RegisterMessages() override; void RegisterMessages() override;
// Callbacks for JS APIs. // Callbacks for JS APIs.
void HandleRejectGoogleApps(const base::ListValue* args); void HandleCacheGoogleAppIcon(const base::ListValue* args);
void HandleAddGoogleApps(const base::ListValue* args);
void HandleGetGoogleAppsList(const base::ListValue* args); void HandleGetGoogleAppsList(const base::ListValue* args);
// Adds webui sources. // Adds webui sources.
......
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