Commit fc06c167 authored by Scott Chen's avatar Scott Chen Committed by Commit Bot

Navi Onboarding: add capability to return country-specific

This CL makes EmailHandler use the new country_codes component to determine
what data to send back based on country codes. This CL adds the mechanism,
and there will be follow-up CLs (marked with TODOs) to add the data for more
countries.

Change-Id: I2fc39ae5bd086a1ee8b2871c166a0f4d46e531b8
Reviewed-on: https://chromium-review.googlesource.com/c/1343192
Commit-Queue: Scott Chen <scottchen@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611962}
parent f16626c2
...@@ -135,7 +135,7 @@ cr.define('nux', function() { ...@@ -135,7 +135,7 @@ cr.define('nux', function() {
this.savedProvider_ = providerId; this.savedProvider_ = providerId;
chrome.metricsPrivate.recordEnumerationValue( chrome.metricsPrivate.recordEnumerationValue(
SELECTION_METRIC_NAME, providerId, SELECTION_METRIC_NAME, providerId,
loadTimeData.getInteger('email_providers_count')); loadTimeData.getInteger('email_providers_enum_count'));
} }
/** @override */ /** @override */
......
...@@ -1872,6 +1872,8 @@ jumbo_split_static_library("ui") { ...@@ -1872,6 +1872,8 @@ jumbo_split_static_library("ui") {
"webui/welcome/nux/constants.h", "webui/welcome/nux/constants.h",
"webui/welcome/nux/email_handler.cc", "webui/welcome/nux/email_handler.cc",
"webui/welcome/nux/email_handler.h", "webui/welcome/nux/email_handler.h",
"webui/welcome/nux/email_providers_list.cc",
"webui/welcome/nux/email_providers_list.h",
"webui/welcome/nux/google_apps_handler.cc", "webui/welcome/nux/google_apps_handler.cc",
"webui/welcome/nux/google_apps_handler.h", "webui/welcome/nux/google_apps_handler.h",
"webui/welcome/nux/set_as_default_handler.cc", "webui/welcome/nux/set_as_default_handler.cc",
...@@ -1884,6 +1886,8 @@ jumbo_split_static_library("ui") { ...@@ -1884,6 +1886,8 @@ jumbo_split_static_library("ui") {
"webui/welcome/welcome_ui.h", "webui/welcome/welcome_ui.h",
] ]
deps += [ "//components/country_codes" ]
if (enable_dice_support) { if (enable_dice_support) {
sources += [ sources += [
"webui/signin/dice_turn_sync_on_helper.cc", "webui/signin/dice_turn_sync_on_helper.cc",
......
...@@ -13,10 +13,9 @@ base::ListValue bookmarkItemsToListValue(const BookmarkItem items[], ...@@ -13,10 +13,9 @@ base::ListValue bookmarkItemsToListValue(const BookmarkItem items[],
size_t count) { size_t count) {
base::ListValue list_value; base::ListValue list_value;
for (size_t i = 0; i < count; ++i) { for (size_t i = 0; i < count; ++i) {
std::unique_ptr<base::DictionaryValue> element = auto element = std::make_unique<base::DictionaryValue>();
std::make_unique<base::DictionaryValue>();
element->SetInteger("id", static_cast<int>(items[i].id)); element->SetInteger("id", items[i].id);
element->SetString("name", items[i].name); element->SetString("name", items[i].name);
element->SetString("icon", items[i].webui_icon); element->SetString("icon", items[i].webui_icon);
element->SetString("url", items[i].url); element->SetString("url", items[i].url);
...@@ -26,4 +25,20 @@ base::ListValue bookmarkItemsToListValue(const BookmarkItem items[], ...@@ -26,4 +25,20 @@ base::ListValue bookmarkItemsToListValue(const BookmarkItem items[],
return list_value; return list_value;
} }
base::ListValue bookmarkItemsToListValue(
const std::vector<BookmarkItem>& items) {
base::ListValue list_value;
for (const auto& item : items) {
auto element = std::make_unique<base::DictionaryValue>();
element->SetInteger("id", item.id);
element->SetString("name", item.name);
element->SetString("icon", item.webui_icon);
element->SetString("url", item.url);
list_value.Append(std::move(element));
}
return list_value;
}
} // namespace nux } // namespace nux
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_WEBUI_WELCOME_NUX_BOOKMARK_ITEM_H_ #define CHROME_BROWSER_UI_WEBUI_WELCOME_NUX_BOOKMARK_ITEM_H_
#include <stddef.h> #include <stddef.h>
#include <vector>
namespace base { namespace base {
class ListValue; class ListValue;
...@@ -24,6 +25,9 @@ struct BookmarkItem { ...@@ -24,6 +25,9 @@ struct BookmarkItem {
base::ListValue bookmarkItemsToListValue(const BookmarkItem items[], base::ListValue bookmarkItemsToListValue(const BookmarkItem items[],
size_t count); size_t count);
base::ListValue bookmarkItemsToListValue(
const std::vector<BookmarkItem>& items);
} // namespace nux } // namespace nux
#endif // CHROME_BROWSER_UI_WEBUI_WELCOME_NUX_BOOKMARK_ITEM_H_ #endif // CHROME_BROWSER_UI_WEBUI_WELCOME_NUX_BOOKMARK_ITEM_H_
...@@ -12,8 +12,10 @@ ...@@ -12,8 +12,10 @@
#include "chrome/browser/favicon/favicon_service_factory.h" #include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.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/browser/ui/webui/welcome/nux/email_providers_list.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/grit/onboarding_welcome_resources.h" #include "chrome/grit/onboarding_welcome_resources.h"
#include "components/country_codes/country_codes.h"
#include "components/favicon/core/favicon_service.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"
...@@ -25,41 +27,13 @@ ...@@ -25,41 +27,13 @@
namespace nux { namespace nux {
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class EmailProviders {
kGmail = 0,
kYahoo = 1,
kOutlook = 2,
kAol = 3,
kiCloud = 4,
kCount,
};
const char* kEmailInteractionHistogram = const char* kEmailInteractionHistogram =
"FirstRun.NewUserExperience.EmailInteraction"; "FirstRun.NewUserExperience.EmailInteraction";
// Strings in costants not translated because this is an experiment.
// Translate before wide release.
const BookmarkItem kEmail[] = {
{static_cast<int>(EmailProviders::kGmail), "Gmail", "gmail",
"https://accounts.google.com/b/0/AddMailService", IDR_NUX_EMAIL_GMAIL_1X},
{static_cast<int>(EmailProviders::kYahoo), "Yahoo", "yahoo",
"https://mail.yahoo.com", IDR_NUX_EMAIL_YAHOO_1X},
{static_cast<int>(EmailProviders::kOutlook), "Outlook", "outlook",
"https://login.live.com/login.srf?", IDR_NUX_EMAIL_OUTLOOK_1X},
{static_cast<int>(EmailProviders::kAol), "AOL", "aol",
"https://mail.aol.com", IDR_NUX_EMAIL_AOL_1X},
{static_cast<int>(EmailProviders::kiCloud), "iCloud", "icloud",
"https://www.icloud.com/mail", IDR_NUX_EMAIL_ICLOUD_1X},
};
constexpr const int kEmailIconSize = 48; // Pixels. constexpr const int kEmailIconSize = 48; // Pixels.
static_assert(base::size(kEmail) == (size_t)EmailProviders::kCount, EmailHandler::EmailHandler()
"names and histograms must match"); : email_providers_(GetCurrentCountryEmailProviders()) {}
EmailHandler::EmailHandler() {}
EmailHandler::~EmailHandler() {} EmailHandler::~EmailHandler() {}
...@@ -78,9 +52,9 @@ void EmailHandler::HandleCacheEmailIcon(const base::ListValue* args) { ...@@ -78,9 +52,9 @@ void EmailHandler::HandleCacheEmailIcon(const base::ListValue* args) {
args->GetInteger(0, &emailId); args->GetInteger(0, &emailId);
const BookmarkItem* selectedEmail = NULL; const BookmarkItem* selectedEmail = NULL;
for (size_t i = 0; i < base::size(kEmail); i++) { for (const auto& provider : email_providers_) {
if (static_cast<int>(kEmail[i].id) == emailId) { if (provider.id == emailId) {
selectedEmail = &kEmail[i]; selectedEmail = &provider;
break; break;
} }
} }
...@@ -104,14 +78,13 @@ void EmailHandler::HandleGetEmailList(const base::ListValue* args) { ...@@ -104,14 +78,13 @@ void EmailHandler::HandleGetEmailList(const base::ListValue* args) {
CHECK_EQ(1U, args->GetSize()); CHECK_EQ(1U, args->GetSize());
const base::Value* callback_id; const base::Value* callback_id;
CHECK(args->Get(0, &callback_id)); CHECK(args->Get(0, &callback_id));
ResolveJavascriptCallback( ResolveJavascriptCallback(*callback_id,
*callback_id, bookmarkItemsToListValue(kEmail, base::size(kEmail))); bookmarkItemsToListValue(email_providers_));
} }
void EmailHandler::AddSources(content::WebUIDataSource* html_source) { void EmailHandler::AddSources(content::WebUIDataSource* html_source) {
// Add constants to loadtime data // Add constants to loadtime data
html_source->AddInteger("email_providers_count", html_source->AddInteger("email_providers_enum_count", EmailProviders::kCount);
static_cast<int>(EmailProviders::kCount));
html_source->SetJsonPath("strings.js"); html_source->SetJsonPath("strings.js");
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_UI_WEBUI_WELCOME_NUX_EMAIL_HANDLER_H_ #ifndef CHROME_BROWSER_UI_WEBUI_WELCOME_NUX_EMAIL_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_WELCOME_NUX_EMAIL_HANDLER_H_ #define CHROME_BROWSER_UI_WEBUI_WELCOME_NUX_EMAIL_HANDLER_H_
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "base/values.h" #include "base/values.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
...@@ -15,6 +17,8 @@ class WebUIDataSource; ...@@ -15,6 +17,8 @@ class WebUIDataSource;
namespace nux { namespace nux {
struct BookmarkItem;
extern const char* kEmailInteractionHistogram; extern const char* kEmailInteractionHistogram;
// These values are persisted to logs. Entries should not be renumbered and // These values are persisted to logs. Entries should not be renumbered and
...@@ -41,6 +45,9 @@ class EmailHandler : public content::WebUIMessageHandler { ...@@ -41,6 +45,9 @@ 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:
const std::vector<BookmarkItem> email_providers_;
DISALLOW_COPY_AND_ASSIGN(EmailHandler); DISALLOW_COPY_AND_ASSIGN(EmailHandler);
}; };
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/welcome/nux/email_providers_list.h"
#include "chrome/browser/ui/webui/welcome/nux/bookmark_item.h"
#include "chrome/grit/onboarding_welcome_resources.h"
#include "components/country_codes/country_codes.h"
namespace nux {
std::vector<BookmarkItem> GetCurrentCountryEmailProviders() {
switch (country_codes::GetCurrentCountryID()) {
case country_codes::CountryCharsToCountryID('U', 'S'): {
return {
{EmailProviders::kGmail, "Gmail", "gmail",
"https://accounts.google.com/b/0/AddMailService",
IDR_NUX_EMAIL_GMAIL_1X},
{EmailProviders::kYahoo, "Yahoo", "yahoo", "https://mail.yahoo.com",
IDR_NUX_EMAIL_YAHOO_1X},
{EmailProviders::kOutlook, "Outlook", "outlook",
"https://login.live.com/login.srf?", IDR_NUX_EMAIL_OUTLOOK_1X},
{EmailProviders::kAol, "AOL", "aol", "https://mail.aol.com",
IDR_NUX_EMAIL_AOL_1X},
{EmailProviders::kiCloud, "iCloud", "icloud",
"https://www.icloud.com/mail", IDR_NUX_EMAIL_ICLOUD_1X},
};
}
// TODO(scottchen): define all supported countries here.
default:
return {
{EmailProviders::kGmail, "Gmail", "gmail",
"https://accounts.google.com/b/0/AddMailService",
IDR_NUX_EMAIL_GMAIL_1X},
// TODO(scottchen): add more default values here.
};
}
}
} // namespace nux
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_WELCOME_NUX_EMAIL_PROVIDERS_LIST_H_
#define CHROME_BROWSER_UI_WEBUI_WELCOME_NUX_EMAIL_PROVIDERS_LIST_H_
#include <vector>
#include "chrome/browser/ui/webui/welcome/nux/bookmark_item.h"
namespace nux {
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum EmailProviders {
kGmail = 0,
kYahoo = 1,
kOutlook = 2,
kAol = 3,
kiCloud = 4,
kCount,
};
std::vector<BookmarkItem> GetCurrentCountryEmailProviders();
} // namespace nux
#endif // CHROME_BROWSER_UI_WEBUI_WELCOME_NUX_EMAIL_PROVIDERS_LIST_H_
...@@ -28,10 +28,6 @@ namespace country_codes { ...@@ -28,10 +28,6 @@ namespace country_codes {
namespace { namespace {
int CountryCharsToCountryID(char c1, char c2) {
return c1 << 8 | c2;
}
// TODO(scottchen): remove this function after confirming if it only pertains // TODO(scottchen): remove this function after confirming if it only pertains
// to obsolete OSes. // to obsolete OSes.
int CountryCharsToCountryIDWithUpdate(char c1, char c2) { int CountryCharsToCountryIDWithUpdate(char c1, char c2) {
......
...@@ -29,6 +29,12 @@ extern const char kCountryIDAtInstall[]; ...@@ -29,6 +29,12 @@ extern const char kCountryIDAtInstall[];
const int kCountryIDUnknown = -1; const int kCountryIDUnknown = -1;
// Takes in each of the two characters of a ISO 3166-1 country code, and
// converts it into an int value to be used as a reference to that country.
constexpr int CountryCharsToCountryID(char c1, char c2) {
return c1 << 8 | c2;
}
void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
// Returns the identifier for the user current country. Used to update the list // Returns the identifier for the user current country. Used to update the list
......
...@@ -597,38 +597,8 @@ std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulationSetFromCountryID( ...@@ -597,38 +597,8 @@ std::vector<std::unique_ptr<TemplateURLData>> GetPrepopulationSetFromCountryID(
size_t num_engines; size_t num_engines;
// If you add a new country make sure to update the unit test for coverage. // If you add a new country make sure to update the unit test for coverage.
switch (country_id) { switch (country_id) {
#define CHAR_A 'A' #define UNHANDLED_COUNTRY(code1, code2) \
#define CHAR_B 'B' case country_codes::CountryCharsToCountryID((#code1)[0], (#code2)[0]):
#define CHAR_C 'C'
#define CHAR_D 'D'
#define CHAR_E 'E'
#define CHAR_F 'F'
#define CHAR_G 'G'
#define CHAR_H 'H'
#define CHAR_I 'I'
#define CHAR_J 'J'
#define CHAR_K 'K'
#define CHAR_L 'L'
#define CHAR_M 'M'
#define CHAR_N 'N'
#define CHAR_O 'O'
#define CHAR_P 'P'
#define CHAR_Q 'Q'
#define CHAR_R 'R'
#define CHAR_S 'S'
#define CHAR_T 'T'
#define CHAR_U 'U'
#define CHAR_V 'V'
#define CHAR_W 'W'
#define CHAR_X 'X'
#define CHAR_Y 'Y'
#define CHAR_Z 'Z'
#define CHAR(ch) CHAR_##ch
#define CODE_TO_ID(code1, code2)\
(CHAR(code1) << 8 | CHAR(code2))
#define UNHANDLED_COUNTRY(code1, code2)\
case CODE_TO_ID(code1, code2):
#define END_UNHANDLED_COUNTRIES(code1, code2)\ #define END_UNHANDLED_COUNTRIES(code1, code2)\
engines = engines_##code1##code2;\ engines = engines_##code1##code2;\
num_engines = arraysize(engines_##code1##code2);\ num_engines = arraysize(engines_##code1##code2);\
......
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