summaryrefslogtreecommitdiffstats
path: root/chrome/browser/first_run
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-13 17:19:19 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-13 17:19:19 +0000
commit81585672180a76679b1ef028a95b70c822326487 (patch)
treeeedc374e94a2c104f92b356c7a6d188f589189dd /chrome/browser/first_run
parentaeb64bfed7785b3702c82f060e1155315c80c425 (diff)
downloadchromium_src-81585672180a76679b1ef028a95b70c822326487.zip
chromium_src-81585672180a76679b1ef028a95b70c822326487.tar.gz
chromium_src-81585672180a76679b1ef028a95b70c822326487.tar.bz2
first-run: Reland refactor of Upgrade class into upgrade_util API.
This fix linux_chromeos build by adding an appropriate #ifdef on upgrade_util_linux.cc. BUG=79203 TEST=None TBR=jhawkins@chromium.org Review URL: http://codereview.chromium.org/6839021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81431 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/first_run')
-rw-r--r--chrome/browser/first_run/try_chrome_dialog_view.cc20
-rw-r--r--chrome/browser/first_run/try_chrome_dialog_view.h6
-rw-r--r--chrome/browser/first_run/upgrade.cc21
-rw-r--r--chrome/browser/first_run/upgrade.h96
-rw-r--r--chrome/browser/first_run/upgrade_util.cc34
-rw-r--r--chrome/browser/first_run/upgrade_util.h83
-rw-r--r--chrome/browser/first_run/upgrade_util_linux.cc (renamed from chrome/browser/first_run/upgrade_gtk.cc)38
-rw-r--r--chrome/browser/first_run/upgrade_util_win.cc (renamed from chrome/browser/first_run/upgrade_win.cc)57
8 files changed, 175 insertions, 180 deletions
diff --git a/chrome/browser/first_run/try_chrome_dialog_view.cc b/chrome/browser/first_run/try_chrome_dialog_view.cc
index 5fa9aa2..6669887 100644
--- a/chrome/browser/first_run/try_chrome_dialog_view.cc
+++ b/chrome/browser/first_run/try_chrome_dialog_view.cc
@@ -36,13 +36,13 @@ TryChromeDialogView::TryChromeDialogView(size_t version)
popup_(NULL),
try_chrome_(NULL),
kill_chrome_(NULL),
- result_(Upgrade::COUNT) {
+ result_(upgrade_util::COUNT) {
}
TryChromeDialogView::~TryChromeDialogView() {
}
-Upgrade::TryResult TryChromeDialogView::ShowModal(
+upgrade_util::TryResult TryChromeDialogView::ShowModal(
ProcessSingleton* process_singleton) {
using views::GridLayout;
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
@@ -57,7 +57,7 @@ Upgrade::TryResult TryChromeDialogView::ShowModal(
popup_ = views::Widget::CreateWidget(params);
if (!popup_) {
NOTREACHED();
- return Upgrade::DIALOG_ERROR;
+ return upgrade_util::DIALOG_ERROR;
}
gfx::Rect pos(310, 160);
@@ -71,7 +71,7 @@ Upgrade::TryResult TryChromeDialogView::ShowModal(
views::GridLayout* layout = views::GridLayout::CreatePanel(root_view);
if (!layout) {
NOTREACHED();
- return Upgrade::DIALOG_ERROR;
+ return upgrade_util::DIALOG_ERROR;
}
root_view->SetLayoutManager(layout);
@@ -121,13 +121,13 @@ Upgrade::TryResult TryChromeDialogView::ShowModal(
BrowserDistribution* dist = BrowserDistribution::GetDistribution();
if (!dist) {
NOTREACHED() << "Cannot determine browser distribution";
- return Upgrade::DIALOG_ERROR;
+ return upgrade_util::DIALOG_ERROR;
}
BrowserDistribution::UserExperiment experiment;
if (!dist->GetExperimentDetails(&experiment, version_) ||
!experiment.heading) {
NOTREACHED() << "Cannot determine which headline to show.";
- return Upgrade::DIALOG_ERROR;
+ return upgrade_util::DIALOG_ERROR;
}
string16 heading = l10n_util::GetStringUTF16(experiment.heading);
views::Label* label = new views::Label(heading);
@@ -202,14 +202,14 @@ void TryChromeDialogView::ButtonPressed(views::Button* sender,
const views::Event& event) {
if (sender->tag() == BT_CLOSE_BUTTON) {
// The user pressed cancel or the [x] button.
- result_ = Upgrade::NOT_NOW;
+ result_ = upgrade_util::NOT_NOW;
} else if (!try_chrome_) {
// We don't have radio buttons, the user pressed ok.
- result_ = Upgrade::TRY_CHROME;
+ result_ = upgrade_util::TRY_CHROME;
} else {
// The outcome is according to the selected ratio button.
- result_ = try_chrome_->checked() ? Upgrade::TRY_CHROME :
- Upgrade::UNINSTALL_CHROME;
+ result_ = try_chrome_->checked() ? upgrade_util::TRY_CHROME :
+ upgrade_util::UNINSTALL_CHROME;
}
popup_->Close();
MessageLoop::current()->Quit();
diff --git a/chrome/browser/first_run/try_chrome_dialog_view.h b/chrome/browser/first_run/try_chrome_dialog_view.h
index a2fb243..6abe776 100644
--- a/chrome/browser/first_run/try_chrome_dialog_view.h
+++ b/chrome/browser/first_run/try_chrome_dialog_view.h
@@ -8,7 +8,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "chrome/browser/first_run/upgrade.h"
+#include "chrome/browser/first_run/upgrade_util.h"
#include "views/controls/button/button.h"
#include "views/controls/link.h"
#include "ui/gfx/native_widget_types.h"
@@ -47,7 +47,7 @@ class TryChromeDialogView : public views::ButtonListener,
// Shows the modal dialog asking the user to try chrome. Note that the dialog
// has no parent and it will position itself in a lower corner of the screen.
// The dialog does not steal focus and does not have an entry in the taskbar.
- Upgrade::TryResult ShowModal(ProcessSingleton* process_singleton);
+ upgrade_util::TryResult ShowModal(ProcessSingleton* process_singleton);
protected:
// views::ButtonListener:
@@ -87,7 +87,7 @@ class TryChromeDialogView : public views::ButtonListener,
views::Widget* popup_;
views::RadioButton* try_chrome_;
views::RadioButton* kill_chrome_;
- Upgrade::TryResult result_;
+ upgrade_util::TryResult result_;
DISALLOW_COPY_AND_ASSIGN(TryChromeDialogView);
};
diff --git a/chrome/browser/first_run/upgrade.cc b/chrome/browser/first_run/upgrade.cc
deleted file mode 100644
index 778f491..0000000
--- a/chrome/browser/first_run/upgrade.cc
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (c) 2011 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/first_run/upgrade.h"
-
-#include "base/command_line.h"
-#include "base/logging.h"
-
-// static
-void Upgrade::RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
- if (new_command_line_) {
- if (!RelaunchChromeBrowser(*new_command_line_)) {
- DLOG(ERROR) << "Launching a new instance of the browser failed.";
- } else {
- DLOG(WARNING) << "Launched a new instance of the browser.";
- }
- delete new_command_line_;
- new_command_line_ = NULL;
- }
-}
diff --git a/chrome/browser/first_run/upgrade.h b/chrome/browser/first_run/upgrade.h
deleted file mode 100644
index 265e094..0000000
--- a/chrome/browser/first_run/upgrade.h
+++ /dev/null
@@ -1,96 +0,0 @@
-// Copyright (c) 2011 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_FIRST_RUN_UPGRADE_H_
-#define CHROME_BROWSER_FIRST_RUN_UPGRADE_H_
-#pragma once
-
-#include "base/basictypes.h"
-#include "build/build_config.h"
-
-class CommandLine;
-
-#if defined(OS_WIN)
-class ProcessSingleton;
-#endif
-
-// This class contains the actions that need to be performed when an upgrade
-// is required. This involves mainly swapping the chrome exe and relaunching
-// the new browser.
-class Upgrade {
- public:
-#if defined(OS_WIN)
- // Possible results of ShowTryChromeDialog().
- enum TryResult {
- TRY_CHROME, // Launch chrome right now.
- NOT_NOW, // Don't launch chrome. Exit now.
- UNINSTALL_CHROME, // Initiate chrome uninstall and exit.
- DIALOG_ERROR, // An error occurred creating the dialog.
- COUNT
- };
-
- // Check if current chrome.exe is already running as a browser process by
- // trying to create a Global event with name same as full path of chrome.exe.
- // This method caches the handle to this event so on subsequent calls also
- // it can first close the handle and check for any other process holding the
- // handle to the event.
- static bool IsBrowserAlreadyRunning();
-
- // If the new_chrome.exe exists (placed by the installer then is swapped
- // to chrome.exe and the old chrome is renamed to old_chrome.exe. If there
- // is no new_chrome.exe or the swap fails the return is false;
- static bool SwapNewChromeExeIfPresent();
-
- // Combines the two methods, RelaunchChromeBrowser and
- // SwapNewChromeExeIfPresent, to perform the rename and relaunch of
- // the browser. Note that relaunch does NOT exit the existing browser process.
- // If this is called before message loop is executed, simply exit the main
- // function. If browser is already running, you will need to exit it.
- static bool DoUpgradeTasks(const CommandLine& command_line);
-
- // Shows a modal dialog asking the user to give chrome another try. See
- // above for the possible outcomes of the function. This is an experimental,
- // non-localized dialog.
- // |version| can be 0, 1 or 2 and selects what strings to present.
- // |process_singleton| needs to be valid and it will be locked while
- // the dialog is shown.
- static TryResult ShowTryChromeDialog(size_t version,
- ProcessSingleton* process_singleton);
-#endif // OS_WIN
-
- // Launches chrome again simulating a 'user' launch. If chrome could not
- // be launched the return is false.
- static bool RelaunchChromeBrowser(const CommandLine& command_line);
-
-#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
- static void SaveLastModifiedTimeOfExe();
-#endif
-
- static void SetNewCommandLine(CommandLine* new_command_line) {
- // Takes ownership of the pointer.
- new_command_line_ = new_command_line;
- }
-
- // Launches a new instance of the browser if the current instance in
- // persistent mode an upgrade is detected.
- static void RelaunchChromeBrowserWithNewCommandLineIfNeeded();
-
- // Windows:
- // Checks if chrome_new.exe is present in the current instance's install.
- // Linux:
- // Checks if the last modified time of chrome is newer than that of the
- // current running instance.
- static bool IsUpdatePendingRestart();
-
- private:
-#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
- static double GetLastModifiedTimeOfExe();
- static double saved_last_modified_time_of_exe_;
-#endif
- static CommandLine* new_command_line_;
-
- DISALLOW_IMPLICIT_CONSTRUCTORS(Upgrade);
-};
-
-#endif // CHROME_BROWSER_FIRST_RUN_UPGRADE_H_
diff --git a/chrome/browser/first_run/upgrade_util.cc b/chrome/browser/first_run/upgrade_util.cc
new file mode 100644
index 0000000..7e700aa
--- /dev/null
+++ b/chrome/browser/first_run/upgrade_util.cc
@@ -0,0 +1,34 @@
+// Copyright (c) 2011 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/first_run/upgrade_util.h"
+
+#include "base/command_line.h"
+#include "base/logging.h"
+
+namespace {
+
+CommandLine* command_line;
+
+} // namespace
+
+namespace upgrade_util {
+
+void SetNewCommandLine(CommandLine* new_command_line) {
+ command_line = new_command_line;
+}
+
+void RelaunchChromeBrowserWithNewCommandLineIfNeeded() {
+ if (command_line) {
+ if (!RelaunchChromeBrowser(*command_line)) {
+ DLOG(ERROR) << "Launching a new instance of the browser failed.";
+ } else {
+ DLOG(WARNING) << "Launched a new instance of the browser.";
+ }
+ delete command_line;
+ command_line = NULL;
+ }
+}
+
+} // namespace upgrade_util
diff --git a/chrome/browser/first_run/upgrade_util.h b/chrome/browser/first_run/upgrade_util.h
new file mode 100644
index 0000000..c5b4c6e
--- /dev/null
+++ b/chrome/browser/first_run/upgrade_util.h
@@ -0,0 +1,83 @@
+// Copyright (c) 2011 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_FIRST_RUN_UPGRADE_UTIL_H_
+#define CHROME_BROWSER_FIRST_RUN_UPGRADE_UTIL_H_
+#pragma once
+
+#include "build/build_config.h"
+
+class CommandLine;
+
+#if defined(OS_WIN)
+class ProcessSingleton;
+#endif
+
+namespace upgrade_util {
+
+void SetNewCommandLine(CommandLine* new_command_line);
+
+// Launches a new instance of the browser if the current instance in persistent
+// mode an upgrade is detected.
+void RelaunchChromeBrowserWithNewCommandLineIfNeeded();
+
+// Launches chrome again simulating a 'user' launch. If chrome could not be
+// launched the return is false.
+bool RelaunchChromeBrowser(const CommandLine& command_line);
+
+// Windows:
+// Checks if chrome_new.exe is present in the current instance's install.
+// Linux:
+// Checks if the last modified time of chrome is newer than that of the current
+// running instance.
+bool IsUpdatePendingRestart();
+
+#if defined(OS_WIN)
+// Possible results of ShowTryChromeDialog().
+enum TryResult {
+ TRY_CHROME, // Launch chrome right now.
+ NOT_NOW, // Don't launch chrome. Exit now.
+ UNINSTALL_CHROME, // Initiate chrome uninstall and exit.
+ DIALOG_ERROR, // An error occurred creating the dialog.
+ COUNT
+};
+
+// Check if current chrome.exe is already running as a browser process by
+// trying to create a Global event with name same as full path of chrome.exe.
+// This method caches the handle to this event so on subsequent calls also
+// it can first close the handle and check for any other process holding the
+// handle to the event.
+bool IsBrowserAlreadyRunning();
+
+// If the new_chrome.exe exists (placed by the installer then is swapped
+// to chrome.exe and the old chrome is renamed to old_chrome.exe. If there
+// is no new_chrome.exe or the swap fails the return is false;
+bool SwapNewChromeExeIfPresent();
+
+// Combines the two methods, RelaunchChromeBrowser and
+// SwapNewChromeExeIfPresent, to perform the rename and relaunch of
+// the browser. Note that relaunch does NOT exit the existing browser process.
+// If this is called before message loop is executed, simply exit the main
+// function. If browser is already running, you will need to exit it.
+bool DoUpgradeTasks(const CommandLine& command_line);
+
+// Shows a modal dialog asking the user to give chrome another try. See
+// above for the possible outcomes of the function. This is an experimental,
+// non-localized dialog.
+// |version| can be 0, 1 or 2 and selects what strings to present.
+// |process_singleton| needs to be valid and it will be locked while
+// the dialog is shown.
+TryResult ShowTryChromeDialog(size_t version,
+ ProcessSingleton* process_singleton);
+#endif // OS_WIN
+
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+void SaveLastModifiedTimeOfExe();
+
+double GetLastModifiedTimeOfExe();
+#endif
+
+} // namespace upgrade_util
+
+#endif // CHROME_BROWSER_FIRST_RUN_UPGRADE_UTIL_H_
diff --git a/chrome/browser/first_run/upgrade_gtk.cc b/chrome/browser/first_run/upgrade_util_linux.cc
index 419e58f..9cbf214 100644
--- a/chrome/browser/first_run/upgrade_gtk.cc
+++ b/chrome/browser/first_run/upgrade_util_linux.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/first_run/upgrade.h"
+#include "chrome/browser/first_run/upgrade_util.h"
#include "base/base_paths.h"
#include "base/command_line.h"
@@ -13,43 +13,43 @@
#include "base/platform_file.h"
#include "base/process_util.h"
+namespace {
+
#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
-// static
-CommandLine* Upgrade::new_command_line_ = NULL;
+double saved_last_modified_time_of_exe = 0;
+#endif
+
+} // namespace
-// static
-double Upgrade::saved_last_modified_time_of_exe_ = 0;
+namespace upgrade_util {
-// static
-bool Upgrade::RelaunchChromeBrowser(const CommandLine& command_line) {
+bool RelaunchChromeBrowser(const CommandLine& command_line) {
return base::LaunchApp(command_line, false, false, NULL);
}
-// static
-void Upgrade::SaveLastModifiedTimeOfExe() {
- saved_last_modified_time_of_exe_ = Upgrade::GetLastModifiedTimeOfExe();
+#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
+bool IsUpdatePendingRestart() {
+ return saved_last_modified_time_of_exe != GetLastModifiedTimeOfExe();
}
-// static
-bool Upgrade::IsUpdatePendingRestart() {
- return saved_last_modified_time_of_exe_ !=
- Upgrade::GetLastModifiedTimeOfExe();
+void SaveLastModifiedTimeOfExe() {
+ saved_last_modified_time_of_exe = GetLastModifiedTimeOfExe();
}
-// static
-double Upgrade::GetLastModifiedTimeOfExe() {
+double GetLastModifiedTimeOfExe() {
FilePath exe_file_path;
if (!PathService::Get(base::FILE_EXE, &exe_file_path)) {
LOG(WARNING) << "Failed to get FilePath object for FILE_EXE.";
- return saved_last_modified_time_of_exe_;
+ return saved_last_modified_time_of_exe;
}
base::PlatformFileInfo exe_file_info;
if (!file_util::GetFileInfo(exe_file_path, &exe_file_info)) {
LOG(WARNING) << "Failed to get FileInfo object for FILE_EXE - "
<< exe_file_path.value();
- return saved_last_modified_time_of_exe_;
+ return saved_last_modified_time_of_exe;
}
return exe_file_info.last_modified.ToDoubleT();
}
-
#endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
+
+} // namespace upgrade_util
diff --git a/chrome/browser/first_run/upgrade_win.cc b/chrome/browser/first_run/upgrade_util_win.cc
index 42f3b74..ee01ffe 100644
--- a/chrome/browser/first_run/upgrade_win.cc
+++ b/chrome/browser/first_run/upgrade_util_win.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/first_run/upgrade.h"
+#include "chrome/browser/first_run/upgrade_util.h"
#include <algorithm>
#include <string>
@@ -60,11 +60,24 @@ bool InvokeGoogleUpdateForRename() {
} // namespace
-// static
-CommandLine* Upgrade::new_command_line_ = NULL;
-// static
-bool Upgrade::IsBrowserAlreadyRunning() {
+namespace upgrade_util {
+
+bool RelaunchChromeBrowser(const CommandLine& command_line) {
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ env->UnSetVar(chrome::kChromeVersionEnvVar);
+ return base::LaunchApp(
+ command_line.command_line_string(), false, false, NULL);
+}
+
+bool IsUpdatePendingRestart() {
+ FilePath new_chrome_exe;
+ if (!GetNewerChromeFile(&new_chrome_exe))
+ return false;
+ return file_util::PathExists(new_chrome_exe);
+}
+
+bool IsBrowserAlreadyRunning() {
static HANDLE handle = NULL;
FilePath exe_path;
PathService::Get(base::FILE_EXE, &exe_path);
@@ -79,8 +92,7 @@ bool Upgrade::IsBrowserAlreadyRunning() {
return (error == ERROR_ALREADY_EXISTS || error == ERROR_ACCESS_DENIED);
}
-// static
-bool Upgrade::SwapNewChromeExeIfPresent() {
+bool SwapNewChromeExeIfPresent() {
FilePath new_chrome_exe;
if (!GetNewerChromeFile(&new_chrome_exe))
return false;
@@ -115,43 +127,26 @@ bool Upgrade::SwapNewChromeExeIfPresent() {
return InvokeGoogleUpdateForRename();
}
-// static
-bool Upgrade::DoUpgradeTasks(const CommandLine& command_line) {
- if (!Upgrade::SwapNewChromeExeIfPresent())
+bool DoUpgradeTasks(const CommandLine& command_line) {
+ if (!SwapNewChromeExeIfPresent())
return false;
// At this point the chrome.exe has been swapped with the new one.
- if (!Upgrade::RelaunchChromeBrowser(command_line)) {
+ if (!RelaunchChromeBrowser(command_line)) {
// The re-launch fails. Feel free to panic now.
NOTREACHED();
}
return true;
}
-// static
-Upgrade::TryResult Upgrade::ShowTryChromeDialog(
- size_t version,
- ProcessSingleton* process_singleton) {
+TryResult ShowTryChromeDialog(size_t version,
+ ProcessSingleton* process_singleton) {
if (version > 10000) {
// This is a test value. We want to make sure we exercise
// returning this early. See EarlyReturnTest test harness.
- return Upgrade::NOT_NOW;
+ return NOT_NOW;
}
TryChromeDialogView dialog(version);
return dialog.ShowModal(process_singleton);
}
-// static
-bool Upgrade::RelaunchChromeBrowser(const CommandLine& command_line) {
- scoped_ptr<base::Environment> env(base::Environment::Create());
- env->UnSetVar(chrome::kChromeVersionEnvVar);
- return base::LaunchApp(
- command_line.command_line_string(), false, false, NULL);
-}
-
-// static
-bool Upgrade::IsUpdatePendingRestart() {
- FilePath new_chrome_exe;
- if (!GetNewerChromeFile(&new_chrome_exe))
- return false;
- return file_util::PathExists(new_chrome_exe);
-}
+} // namespace upgrade_util