summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgrt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-14 00:16:51 +0000
committergrt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-14 00:16:51 +0000
commitf7f9cc0c9a12699b9ce626a8ca739a3fb8f1fa3e (patch)
tree3cfe030e875eda715dead1bb182158694f5d751c
parent81de0950bc023d55e1b1d95536628ac2bc160692 (diff)
downloadchromium_src-f7f9cc0c9a12699b9ce626a8ca739a3fb8f1fa3e.zip
chromium_src-f7f9cc0c9a12699b9ce626a8ca739a3fb8f1fa3e.tar.gz
chromium_src-f7f9cc0c9a12699b9ce626a8ca739a3fb8f1fa3e.tar.bz2
Relaunch into metro mode after chrome is made the default browser if desired.
Where "if desired" is defined as: the device appears to be a tablet and the switch hasn't been suppressed via master_preferences. BUG=148698 TEST=make IE the default browser, nuke your user data dir, launch chrome, make it the default, and confirm that it either stays in desktop or switches to metro based on the above. Review URL: https://chromiumcodereview.appspot.com/10910255 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156691 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/first_run/first_run_win.cc62
-rw-r--r--chrome/browser/ui/webui/set_as_default_browser_ui.cc68
2 files changed, 99 insertions, 31 deletions
diff --git a/chrome/browser/first_run/first_run_win.cc b/chrome/browser/first_run/first_run_win.cc
index 48e2402..077a1cf 100644
--- a/chrome/browser/first_run/first_run_win.cc
+++ b/chrome/browser/first_run/first_run_win.cc
@@ -55,6 +55,8 @@
namespace {
+const char kEULASentinelFile[] = "EULA Accepted";
+
// Helper class that performs delayed first-run tasks that need more of the
// chrome infrastructure to be up and running before they can be attempted.
class FirstRunDelayedTasks : public content::NotificationObserver {
@@ -171,19 +173,38 @@ bool LaunchSetupWithParam(const std::string& param,
return (TRUE == ::GetExitCodeProcess(ph, reinterpret_cast<DWORD*>(ret_code)));
}
+// Populates |path| with the path to |file| in the sentinel directory. This is
+// the application directory for user-level installs, and the default user data
+// dir for system-level installs. Returns false on error.
+bool GetSentinelFilePath(const char* file, FilePath* path) {
+ FilePath exe_path;
+ if (!PathService::Get(base::DIR_EXE, &exe_path))
+ return false;
+ if (InstallUtil::IsPerUserInstall(exe_path.value().c_str()))
+ *path = exe_path;
+ else if (!PathService::Get(chrome::DIR_USER_DATA, path))
+ return false;
+
+ *path = path->AppendASCII(file);
+ return true;
+}
+
+bool GetEULASentinelFilePath(FilePath* path) {
+ return GetSentinelFilePath(kEULASentinelFile, path);
+}
+
// Returns true if the EULA is required but has not been accepted by this user.
// The EULA is considered having been accepted if the user has gotten past
// first run in the "other" environment (desktop or metro).
-bool IsEulaNotAccepted(installer::MasterPreferences* install_prefs) {
+bool IsEULANotAccepted(installer::MasterPreferences* install_prefs) {
bool value = false;
if (install_prefs->GetBool(installer::master_preferences::kRequireEula,
&value) && value) {
- // Check for a first run sentinel in the alternate user data dir.
- FilePath alt_user_data_dir;
- if (!PathService::Get(chrome::DIR_ALT_USER_DATA, &alt_user_data_dir) ||
- !file_util::DirectoryExists(alt_user_data_dir) ||
- !file_util::PathExists(alt_user_data_dir.AppendASCII(
- first_run::internal::kSentinelFile))) {
+ FilePath eula_sentinel;
+ // Be conservative and show the EULA if the path to the sentinel can't be
+ // determined.
+ if (!GetEULASentinelFilePath(&eula_sentinel) ||
+ !file_util::PathExists(eula_sentinel)) {
return true;
}
}
@@ -204,8 +225,17 @@ bool WriteEULAtoTempFile(FilePath* eula_path) {
return good;
}
+// Creates the sentinel indicating that the EULA was required and has been
+// accepted.
+bool CreateEULASentinel() {
+ FilePath eula_sentinel;
+ if (!GetEULASentinelFilePath(&eula_sentinel))
+ return false;
+ return file_util::WriteFile(eula_sentinel, "", 0) != -1;
+}
+
void ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) {
- if (IsEulaNotAccepted(install_prefs)) {
+ if (IsEULANotAccepted(install_prefs)) {
// Show the post-installation EULA. This is done by setup.exe and the
// result determines if we continue or not. We wait here until the user
// dismisses the dialog.
@@ -222,6 +252,7 @@ void ShowPostInstallEULAIfNeeded(installer::MasterPreferences* install_prefs) {
LOG(WARNING) << "EULA rejected. Fast exit.";
::ExitProcess(1);
}
+ CreateEULASentinel();
if (retcode == installer::EULA_ACCEPTED) {
VLOG(1) << "EULA : no collection";
GoogleUpdateSettings::SetCollectStatsConsent(false);
@@ -467,20 +498,7 @@ bool ImportSettings(Profile* profile,
}
bool GetFirstRunSentinelFilePath(FilePath* path) {
- FilePath first_run_sentinel;
-
- FilePath exe_path;
- if (!PathService::Get(base::DIR_EXE, &exe_path))
- return false;
- if (InstallUtil::IsPerUserInstall(exe_path.value().c_str())) {
- first_run_sentinel = exe_path;
- } else {
- if (!PathService::Get(chrome::DIR_USER_DATA, &first_run_sentinel))
- return false;
- }
-
- *path = first_run_sentinel.AppendASCII(kSentinelFile);
- return true;
+ return GetSentinelFilePath(kSentinelFile, path);
}
void SetImportPreferencesAndLaunchImport(
diff --git a/chrome/browser/ui/webui/set_as_default_browser_ui.cc b/chrome/browser/ui/webui/set_as_default_browser_ui.cc
index b1961cd..6e45921 100644
--- a/chrome/browser/ui/webui/set_as_default_browser_ui.cc
+++ b/chrome/browser/ui/webui/set_as_default_browser_ui.cc
@@ -8,7 +8,9 @@
#include "base/bind_helpers.h"
#include "base/metrics/histogram.h"
#include "base/path_service.h"
+#include "base/win/win_util.h"
#include "chrome/browser/first_run/first_run.h"
+#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shell_integration.h"
@@ -51,10 +53,12 @@ const char kSetAsDefaultBrowserHistogram[] = "DefaultBrowser.InteractionResult";
// ACCEPTED: user pressed Next and made Chrome default.
// DECLINED: user simply closed the dialog without making Chrome default.
// REGRETTED: user pressed Next but then elected a different default browser.
+// ACCEPTED_IMMERSE: as above with a switch to metro mode.
enum MakeChromeDefaultResult {
MAKE_CHROME_DEFAULT_ACCEPTED,
MAKE_CHROME_DEFAULT_DECLINED,
MAKE_CHROME_DEFAULT_REGRETTED,
+ MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE,
MAKE_CHROME_DEFAULT_MAX
};
@@ -113,6 +117,15 @@ class SetAsDefaultBrowserHandler
// Close this web ui.
void ConcludeInteraction(MakeChromeDefaultResult interaction_result);
+ // Returns true if Chrome should be restarted in immersive mode upon being
+ // made the default browser.
+ bool ShouldAttemptImmersiveRestart();
+
+ // Handles Chrome being made the default browser on the FILE thread. This
+ // determines whether or not the browser should be restarted in immersive
+ // mode, then concludes the interaction.
+ void HandleDefaultOnFileThread();
+
scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
bool set_default_returned_;
bool set_default_result_;
@@ -153,7 +166,10 @@ void SetAsDefaultBrowserHandler::SetDefaultWebClientUIState(
// chrome the default.
ConcludeInteraction(MAKE_CHROME_DEFAULT_REGRETTED);
} else if (state == ShellIntegration::STATE_IS_DEFAULT) {
- ConcludeInteraction(MAKE_CHROME_DEFAULT_ACCEPTED);
+ BrowserThread::PostTask(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&SetAsDefaultBrowserHandler::HandleDefaultOnFileThread,
+ base::Unretained(this)));
}
// Otherwise, keep the dialog open since the user probably didn't make a
@@ -192,6 +208,32 @@ void SetAsDefaultBrowserHandler::ConcludeInteraction(
}
}
+bool SetAsDefaultBrowserHandler::ShouldAttemptImmersiveRestart() {
+ return (base::win::IsMachineATablet() &&
+ !Profile::FromWebUI(web_ui())->GetPrefs()->GetBoolean(
+ prefs::kSuppressSwitchToMetroModeOnSetDefault));
+}
+
+void SetAsDefaultBrowserHandler::HandleDefaultOnFileThread() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+
+ MakeChromeDefaultResult result = MAKE_CHROME_DEFAULT_ACCEPTED;
+
+ if (ShouldAttemptImmersiveRestart()) {
+ result = MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE;
+ // If the sentinel was created for this launch, remove it before restarting
+ // in immersive mode so that the user is taken through the full first-run
+ // flow there.
+ if (first_run::IsChromeFirstRun())
+ first_run::RemoveSentinel();
+ }
+
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&SetAsDefaultBrowserHandler::ConcludeInteraction,
+ base::Unretained(this), result));
+}
+
// A web dialog delegate implementation for when 'Make Chrome Metro' UI
// is displayed on a dialog.
class SetAsDefaultBrowserDialogImpl : public ui::WebDialogDelegate,
@@ -298,14 +340,22 @@ void SetAsDefaultBrowserDialogImpl::OnDialogClosed(
dialog_interation_result_,
MAKE_CHROME_DEFAULT_MAX);
- // Carry on with a normal chrome session. For the purpose of surfacing this
- // dialog the actual browser window had to remain hidden. Now it's time to
- // show it.
- BrowserWindow* window = browser_->window();
- WebContents* contents = chrome::GetActiveWebContents(browser_);
- window->Show();
- if (contents)
- contents->GetView()->SetInitialFocus();
+ if (dialog_interation_result_ == MAKE_CHROME_DEFAULT_ACCEPTED_IMMERSE) {
+ // Do a straight-up restart rather than a mode-switch restart.
+ // delegate_execute.exe will choose an immersive launch on the basis of the
+ // same IsMachineATablet check, but will not store this as the user's
+ // choice.
+ browser::AttemptRestart();
+ } else {
+ // Carry on with a normal chrome session. For the purpose of surfacing this
+ // dialog the actual browser window had to remain hidden. Now it's time to
+ // show it.
+ BrowserWindow* window = browser_->window();
+ WebContents* contents = chrome::GetActiveWebContents(browser_);
+ window->Show();
+ if (contents)
+ contents->GetView()->SetInitialFocus();
+ }
delete this;
}