Commit 341426ee authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Adding an experiment to automatically open the default browser chooser

Bug: 798612
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: Ie9bb7d1af812a96f11058c928cb32fa6491d96db
Reviewed-on: https://chromium-review.googlesource.com/981079
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarRobert Kaplow <rkaplow@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567797}
parent 1582e398
......@@ -339,6 +339,12 @@ const char kInstantUIZeroSuggestUrlPrefix[] =
const char kTouchHudProjectionEnabled[] = "touch_hud.projection_enabled";
#endif
#if defined(OS_WIN)
// Deprecated 6/2018.
const char kResetHasSeenWin10PromoPage[] =
"browser.reset_has_seen_win10_promo_page";
#endif
// Register prefs used only for migration (clearing or moving to a new key).
void RegisterProfilePrefsForMigration(
user_prefs::PrefRegistrySyncable* registry) {
......@@ -485,6 +491,8 @@ void RegisterLocalState(PrefRegistrySimple* registry) {
ModuleDatabase::RegisterLocalStatePrefs(registry);
ThirdPartyConflictsManager::RegisterLocalStatePrefs(registry);
#endif // defined(GOOGLE_CHROME_BUILD)
registry->RegisterBooleanPref(kResetHasSeenWin10PromoPage, false);
#endif
#if defined(TOOLKIT_VIEWS)
......@@ -747,6 +755,11 @@ void MigrateObsoleteBrowserPrefs(Profile* profile, PrefService* local_state) {
// Added 5/2018.
local_state->ClearPref(prefs::kProblematicPrograms);
#endif
#if defined(OS_WIN)
// Added 6/2018.
local_state->ClearPref(kResetHasSeenWin10PromoPage);
#endif
}
// This method should be periodically pruned of year+ old migrations.
......
......@@ -8,9 +8,12 @@
<link rel="import" href="chrome://resources/cr_elements/icons.html">
<link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="chrome://resources/html/load_time_data.html">
<link rel="import" href="chrome://resources/html/util.html">
<link rel="import" href="chrome://resources/html/action_link.html">
<link rel="import" href="chrome://resources/html/action_link_css.html">
<link rel="import" href="chrome://resources/html/util.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-styles/color.html">
......@@ -18,11 +21,12 @@
<link rel="stylesheet" href="chrome://resources/css/text_defaults_md.css">
<link rel="stylesheet" href="/welcome_win10.css">
<script src="strings.js"></script>
<dom-module id="welcome-win10">
<template>
<style include="action-link">
:host {
--expandable-section-height: 28.375em;
align-items: flex-start;
display: inline-flex;
flex-direction: column;
......@@ -31,6 +35,14 @@
transition: opacity 300ms;
}
:host .section {
--expandable-section-height: 28.375em;
}
:host([is-accelerated]) .section {
--expandable-section-height: 26.375em;
}
a {
color: var(--google-blue-500);
text-decoration: none;
......@@ -52,8 +64,10 @@
margin: 0 -0.0625em;
}
.heading {
h1 {
font-size: 2.125em;
font-weight: normal;
margin: 0;
padding-bottom: 2rem;
padding-top: 1rem;
}
......@@ -274,7 +288,7 @@
}
</style>
<div class="header-logo" role="presentation"></div>
<div class="heading">$i18n{headerText}</div>
<h1>$i18n{headerText}</h1>
<div class="sections">
<div class$="[[computeClasses(isCombined)]]">
<template is="dom-if" if="[[isCombined]]">
......
......@@ -8,10 +8,19 @@ Polymer({
properties: {
// Determines if the combined variant should be displayed. The combined
// variant includes instructions on how to pin Chrome to the taskbar.
isCombined: Boolean,
isCombined: {
type: Boolean,
value: false,
},
// Indicates if the accelerated flow is enabled.
isAccelerated: Boolean,
isAccelerated: {
type: Boolean,
value: function() {
return loadTimeData.getBoolean('acceleratedFlowEnabled');
},
reflectToAttribute: true,
},
},
receivePinnedState_: function(isPinnedToTaskbar) {
......@@ -30,21 +39,15 @@ Polymer({
},
ready: function() {
this.isCombined = false;
this.isAccelerated = false;
// The accelerated flow can be overridden with a query parameter.
const FLOWTYPE_KEY = 'flowtype';
const FLOW_TYPE_MAP = {'regular': false, 'accelerated': true};
var params = new URLSearchParams(location.search);
if (params.has(FLOWTYPE_KEY)) {
if (params.get(FLOWTYPE_KEY) in FLOW_TYPE_MAP) {
this.isAccelerated = FLOW_TYPE_MAP[params.get(FLOWTYPE_KEY)];
// Adjust the height since the accelerated flow contains fewer steps.
this.customStyle['--expandable-section-height'] = '26.375em';
this.updateStyles();
} else {
console.log(
console.error(
'Found invalid value for the \'flowtype\' parameter: %s',
params.get(FLOWTYPE_KEY));
}
......
......@@ -11,6 +11,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/welcome_win10_handler.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/browser_resources.h"
......@@ -87,8 +88,15 @@ WelcomeWin10UI::WelcomeWin10UI(content::WebUI* web_ui, const GURL& url)
content::WebUIDataSource* html_source =
content::WebUIDataSource::Create(url.host());
html_source->SetJsonPath("strings.js");
AddLocalizedStrings(html_source, is_first_run);
// Controls the accelerated default browser flow experiment.
html_source->AddBoolean("acceleratedFlowEnabled",
base::FeatureList::IsEnabled(
features::kWin10AcceleratedDefaultBrowserFlow));
html_source->AddResourcePath("welcome_win10.css", IDR_WELCOME_WIN10_CSS);
html_source->AddResourcePath("welcome_win10.js", IDR_WELCOME_WIN10_JS);
html_source->AddResourcePath("default.webp", IDR_WELCOME_WIN10_DEFAULT_WEBP);
......
......@@ -9,8 +9,10 @@
#include <utility>
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/location.h"
#include "base/memory/scoped_refptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/pattern.h"
#include "base/strings/string16.h"
......@@ -19,6 +21,7 @@
#include "base/win/scoped_variant.h"
#include "chrome/browser/win/automation_controller.h"
#include "chrome/browser/win/ui_automation_util.h"
#include "chrome/common/chrome_features.h"
namespace {
......@@ -43,6 +46,7 @@ void ConfigureCacheRequest(IUIAutomationCacheRequest* cache_request) {
cache_request->AddProperty(UIA_AutomationIdPropertyId);
cache_request->AddProperty(UIA_NamePropertyId);
cache_request->AddProperty(UIA_ClassNamePropertyId);
cache_request->AddPattern(UIA_InvokePatternId);
}
// Helper function to get the parent element with class name "Flyout". Used to
......@@ -123,6 +127,10 @@ class SettingsAppMonitor::AutomationControllerDelegate
IUIAutomationElement* sender) const override;
private:
// Invokes the |browser_button| if the Win10AcceleratedDefaultBrowserFlow
// feature is enabled.
void MaybeInvokeChooser(IUIAutomationElement* browser_button) const;
// The task runner on which the SettingsAppMonitor lives.
const scoped_refptr<base::SequencedTaskRunner> monitor_runner_;
......@@ -135,6 +143,12 @@ class SettingsAppMonitor::AutomationControllerDelegate
// State to suppress duplicate "focus changed" events.
mutable ElementType last_focused_element_;
// Protect against concurrent accesses to |browser_chooser_invoked_|.
mutable base::Lock browser_chooser_invoked_lock_;
// The browser chooser must only be invoked once.
mutable bool browser_chooser_invoked_;
DISALLOW_COPY_AND_ASSIGN(AutomationControllerDelegate);
};
......@@ -143,7 +157,8 @@ SettingsAppMonitor::AutomationControllerDelegate::AutomationControllerDelegate(
base::WeakPtr<SettingsAppMonitor> monitor)
: monitor_runner_(monitor_runner),
monitor_(std::move(monitor)),
last_focused_element_(ElementType::UNKNOWN) {}
last_focused_element_(ElementType::UNKNOWN),
browser_chooser_invoked_(false) {}
SettingsAppMonitor::AutomationControllerDelegate::
~AutomationControllerDelegate() = default;
......@@ -208,6 +223,7 @@ void SettingsAppMonitor::AutomationControllerDelegate::OnFocusChangedEvent(
}
if (element_type == ElementType::DEFAULT_BROWSER) {
MaybeInvokeChooser(sender);
monitor_runner_->PostTask(
FROM_HERE, base::BindOnce(&SettingsAppMonitor::OnAppFocused, monitor_));
} else if (element_type == ElementType::CHECK_IT_OUT) {
......@@ -217,6 +233,30 @@ void SettingsAppMonitor::AutomationControllerDelegate::OnFocusChangedEvent(
}
}
void SettingsAppMonitor::AutomationControllerDelegate::MaybeInvokeChooser(
IUIAutomationElement* browser_button) const {
if (!base::FeatureList::IsEnabled(
features::kWin10AcceleratedDefaultBrowserFlow)) {
return;
}
{
// Only invoke the browser chooser once.
base::AutoLock auto_lock(browser_chooser_invoked_lock_);
if (browser_chooser_invoked_)
return;
browser_chooser_invoked_ = true;
}
// Invoke the dialog and record whether it was successful.
Microsoft::WRL::ComPtr<IUIAutomationInvokePattern> invoke_pattern;
bool succeeded = SUCCEEDED(browser_button->GetCachedPatternAs(
UIA_InvokePatternId, IID_PPV_ARGS(&invoke_pattern))) &&
invoke_pattern && SUCCEEDED(invoke_pattern->Invoke());
UMA_HISTOGRAM_BOOLEAN("DefaultBrowser.Win10ChooserInvoked", succeeded);
}
SettingsAppMonitor::SettingsAppMonitor(Delegate* delegate)
: delegate_(delegate), weak_ptr_factory_(this) {
// A fully initialized WeakPtrFactory is needed to create the
......
......@@ -625,4 +625,10 @@ const base::Feature kCrOSEnableUSMUserService{"CrOSEnableUSMUserService",
#endif // defined(OS_CHROMEOS)
#if defined(OS_WIN)
// Enables the accelerated default browser flow for Windows 10.
const base::Feature kWin10AcceleratedDefaultBrowserFlow{
"Win10AcceleratedDefaultBrowserFlow", base::FEATURE_DISABLED_BY_DEFAULT};
#endif // defined(OS_WIN)
} // namespace features
......@@ -339,6 +339,10 @@ extern const base::Feature kTPMFirmwareUpdate;
extern const base::Feature kCrOSEnableUSMUserService;
#endif // defined(OS_CHROMEOS)
#if defined(OS_WIN)
extern const base::Feature kWin10AcceleratedDefaultBrowserFlow;
#endif // defined(OS_WIN)
bool PrefServiceEnabled();
// DON'T ADD RANDOM STUFF HERE. Put it in the main section above in
......
......@@ -4680,6 +4680,21 @@
]
}
],
"Win10AcceleratedDefaultBrowserFlow": [
{
"platforms": [
"win"
],
"experiments": [
{
"name": "Enabled",
"enable_features": [
"Win10AcceleratedDefaultBrowserFlow"
]
}
]
}
],
"WorkStealingInScriptRunner": [
{
"platforms": [
......
......@@ -16672,6 +16672,16 @@ uploading your change for review.
<summary>Whether Chrome was the default browser when it started up.</summary>
</histogram>
<histogram name="DefaultBrowser.Win10ChooserInvoked" enum="BooleanSuccess">
<owner>pmonette@chromium.org</owner>
<summary>
When changing the default browser on Windows 10, records whether the browser
chooser is successfully invoked when opening the settings page. This
histogram is only recorded when the Win10AcceleratedDefaultBrowserFlow
experiment is enabled.
</summary>
</histogram>
<histogram name="DefaultBrowserWarning.DontSetAsDefault" enum="BooleanHit">
<obsolete>
Deprecated 2015/11. The same information is available as the value Failure
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