diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-13 17:19:19 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-13 17:19:19 +0000 |
commit | 81585672180a76679b1ef028a95b70c822326487 (patch) | |
tree | eedc374e94a2c104f92b356c7a6d188f589189dd | |
parent | aeb64bfed7785b3702c82f060e1155315c80c425 (diff) | |
download | chromium_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
-rw-r--r-- | chrome/app/chrome_exe_main_gtk.cc | 4 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 20 | ||||
-rw-r--r-- | chrome/browser/browser_main_win.cc | 4 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 6 | ||||
-rw-r--r-- | chrome/browser/browser_shutdown.cc | 8 | ||||
-rw-r--r-- | chrome/browser/first_run/try_chrome_dialog_view.cc | 20 | ||||
-rw-r--r-- | chrome/browser/first_run/try_chrome_dialog_view.h | 6 | ||||
-rw-r--r-- | chrome/browser/first_run/upgrade.cc | 21 | ||||
-rw-r--r-- | chrome/browser/first_run/upgrade.h | 96 | ||||
-rw-r--r-- | chrome/browser/first_run/upgrade_util.cc | 34 | ||||
-rw-r--r-- | chrome/browser/first_run/upgrade_util.h | 83 | ||||
-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 | ||||
-rw-r--r-- | chrome/browser/process_singleton.h | 3 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 24 | ||||
-rw-r--r-- | chrome/installer/setup/install_worker.cc | 4 |
16 files changed, 212 insertions, 216 deletions
diff --git a/chrome/app/chrome_exe_main_gtk.cc b/chrome/app/chrome_exe_main_gtk.cc index bf9589d..1e3fa0e 100644 --- a/chrome/app/chrome_exe_main_gtk.cc +++ b/chrome/app/chrome_exe_main_gtk.cc @@ -6,7 +6,7 @@ #include "build/build_config.h" #if defined(OS_LINUX) && !defined(OS_CHROMEOS) -#include "chrome/browser/first_run/upgrade.h" +#include "chrome/browser/first_run/upgrade_util.h" #endif // The entry point for all invocations of Chromium, browser and renderer. On @@ -51,7 +51,7 @@ int main(int argc, const char** argv) { #if defined(OS_LINUX) && !defined(OS_CHROMEOS) // Launch a new instance if we're shutting down because we detected an // upgrade in the persistent mode. - Upgrade::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); + upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); #endif return return_code; diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 746ae30..e252687 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -41,7 +41,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extensions_startup.h" #include "chrome/browser/first_run/first_run.h" -#include "chrome/browser/first_run/upgrade.h" +#include "chrome/browser/first_run/upgrade_util.h" #include "chrome/browser/gpu_data_manager.h" #include "chrome/browser/jankometer.h" #include "chrome/browser/metrics/histogram_synchronizer.h" @@ -1052,7 +1052,7 @@ DLLEXPORT void __cdecl RelaunchChromeBrowserWithNewCommandLineIfNeeded() { // deletions. We need this new instance because, the old instance created // in ChromeMain() got destructed when the function returned. base::AtExitManager exit_manager; - Upgrade::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); + upgrade_util::RelaunchChromeBrowserWithNewCommandLineIfNeeded(); } #endif @@ -1234,15 +1234,15 @@ int BrowserMain(const MainFunctionParams& parameters) { // It seems that we don't need to run the experiment since chrome // in the same profile is already running. VLOG(1) << "Retention experiment not required"; - return Upgrade::NOT_NOW; + return upgrade_util::NOT_NOW; } int try_chrome_int; base::StringToInt(try_chrome, &try_chrome_int); - Upgrade::TryResult answer = - Upgrade::ShowTryChromeDialog(try_chrome_int, &process_singleton); - if (answer == Upgrade::NOT_NOW) + upgrade_util::TryResult answer = + upgrade_util::ShowTryChromeDialog(try_chrome_int, &process_singleton); + if (answer == upgrade_util::NOT_NOW) return ResultCodes::NORMAL_EXIT_CANCEL; - if (answer == Upgrade::UNINSTALL_CHROME) + if (answer == upgrade_util::UNINSTALL_CHROME) return ResultCodes::NORMAL_EXIT_EXP2; #else // We don't support retention experiments on Mac or Linux. @@ -1342,7 +1342,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // On Windows, we use our startup as an opportunity to do upgrade/uninstall // tasks. Those care whether the browser is already running. On Linux/Mac, // upgrade/uninstall happen separately. - bool already_running = Upgrade::IsBrowserAlreadyRunning(); + bool already_running = upgrade_util::IsBrowserAlreadyRunning(); // If the command line specifies 'uninstall' then we need to work here // unless we detect another chrome browser running. @@ -1485,7 +1485,7 @@ int BrowserMain(const MainFunctionParams& parameters) { #if defined(OS_WIN) // Do the tasks if chrome has been upgraded while it was last running. - if (!already_running && Upgrade::DoUpgradeTasks(parsed_command_line)) + if (!already_running && upgrade_util::DoUpgradeTasks(parsed_command_line)) return ResultCodes::NORMAL_EXIT; #endif @@ -1803,7 +1803,7 @@ int BrowserMain(const MainFunctionParams& parameters) { // available while the browser is running. We need to save the last // modified time of the exe, so we can compare to determine if there is // an upgrade while the browser is kept alive by a persistent extension. - Upgrade::SaveLastModifiedTimeOfExe(); + upgrade_util::SaveLastModifiedTimeOfExe(); #endif // Record now as the last successful chrome start. diff --git a/chrome/browser/browser_main_win.cc b/chrome/browser/browser_main_win.cc index ee8f9eb..fc69fcd 100644 --- a/chrome/browser/browser_main_win.cc +++ b/chrome/browser/browser_main_win.cc @@ -21,7 +21,7 @@ #include "base/win/windows_version.h" #include "base/win/wrapped_window_proc.h" #include "chrome/browser/first_run/first_run.h" -#include "chrome/browser/first_run/upgrade.h" +#include "chrome/browser/first_run/upgrade_util.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/views/uninstall_view.h" @@ -110,7 +110,7 @@ int DoUninstallTasks(bool chrome_still_running) { return ResultCodes::UNINSTALL_CHROME_ALIVE; } int ret = AskForUninstallConfirmation(); - if (Upgrade::IsBrowserAlreadyRunning()) { + if (upgrade_util::IsBrowserAlreadyRunning()) { ShowCloseBrowserFirstMessageBox(); return ResultCodes::UNINSTALL_CHROME_ALIVE; } diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index c521e11..f45f30c 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -26,7 +26,7 @@ #include "chrome/browser/extensions/extension_event_router_forwarder.h" #include "chrome/browser/extensions/extension_tab_id_map.h" #include "chrome/browser/extensions/user_script_listener.h" -#include "chrome/browser/first_run/upgrade.h" +#include "chrome/browser/first_run/upgrade_util.h" #include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/gpu_process_host_ui_shim.h" #include "chrome/browser/icon_manager.h" @@ -1000,7 +1000,7 @@ bool BrowserProcessImpl::CanAutorestartForUpdate() const { // Check if browser is in the background and if it needs to be restarted to // apply a pending update. return BrowserList::size() == 0 && BrowserList::WillKeepAlive() && - Upgrade::IsUpdatePendingRestart(); + upgrade_util::IsUpdatePendingRestart(); } // Switches to add when auto-restarting Chrome. @@ -1039,7 +1039,7 @@ void BrowserProcessImpl::RestartPersistentInstance() { BrowserList::CloseAllBrowsersAndExit(); // Transfer ownership to Upgrade. - Upgrade::SetNewCommandLine(new_cl.release()); + upgrade_util::SetNewCommandLine(new_cl.release()); } void BrowserProcessImpl::OnAutoupdateTimer() { diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc index 6c6d4fd..f5b5906 100644 --- a/chrome/browser/browser_shutdown.cc +++ b/chrome/browser/browser_shutdown.cc @@ -22,7 +22,7 @@ #include "build/build_config.h" #include "chrome/browser/about_flags.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/first_run/upgrade.h" +#include "chrome/browser/first_run/upgrade_util.h" #include "chrome/browser/jankometer.h" #include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/prefs/pref_service.h" @@ -189,9 +189,9 @@ void Shutdown() { ResourceBundle::CleanupSharedInstance(); #if defined(OS_WIN) - if (!Upgrade::IsBrowserAlreadyRunning() && + if (!upgrade_util::IsBrowserAlreadyRunning() && shutdown_type_ != browser_shutdown::END_SESSION) { - Upgrade::SwapNewChromeExeIfPresent(); + upgrade_util::SwapNewChromeExeIfPresent(); } #endif @@ -225,7 +225,7 @@ void Shutdown() { new_cl->AppendSwitch(switches::kRestoreLastSession); #if defined(OS_WIN) || defined(OS_LINUX) - Upgrade::RelaunchChromeBrowser(*new_cl.get()); + upgrade_util::RelaunchChromeBrowser(*new_cl.get()); #endif // defined(OS_WIN) || defined(OS_LINUX) #if defined(OS_MACOSX) 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 diff --git a/chrome/browser/process_singleton.h b/chrome/browser/process_singleton.h index cba8abd..5d6da98 100644 --- a/chrome/browser/process_singleton.h +++ b/chrome/browser/process_singleton.h @@ -82,7 +82,8 @@ class ProcessSingleton : public base::NonThreadSafe { // Used in specific cases to let us know that there is an existing instance // of Chrome running with this profile. In general, you should not use this // function. Instead consider using NotifyOtherProcessOrCreate(). - // For non profile-specific method, use Upgrade::IsBrowserAlreadyRunning(). + // For non profile-specific method, use + // upgrade_util::IsBrowserAlreadyRunning(). bool FoundOtherProcessWindow() const { return (NULL != remote_window_); } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 3a639ea..f288a04 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1062,10 +1062,10 @@ 'browser/first_run/first_run_gtk.cc', 'browser/first_run/first_run_mac.mm', 'browser/first_run/first_run_win.cc', - 'browser/first_run/upgrade.cc', - 'browser/first_run/upgrade.h', - 'browser/first_run/upgrade_gtk.cc', - 'browser/first_run/upgrade_win.cc', + 'browser/first_run/upgrade_util.cc', + 'browser/first_run/upgrade_util.h', + 'browser/first_run/upgrade_util_linux.cc', + 'browser/first_run/upgrade_util_win.cc', 'browser/first_run/try_chrome_dialog_view.cc', 'browser/first_run/try_chrome_dialog_view.h', 'browser/fullscreen.h', @@ -3418,8 +3418,8 @@ ['chromeos==1', { 'sources!': [ 'browser/background_mode_manager_linux.cc', - 'browser/first_run/upgrade.cc', - 'browser/first_run/upgrade.h', + 'browser/first_run/upgrade_util.cc', + 'browser/first_run/upgrade_util.h', 'browser/password_manager/native_backend_gnome_x.cc', 'browser/password_manager/native_backend_gnome_x.h', 'browser/password_manager/native_backend_kwallet_x.cc', @@ -3487,8 +3487,8 @@ ], 'sources': [ 'browser/crash_handler_host_linux.h', - 'browser/first_run/upgrade.cc', - 'browser/first_run/upgrade.h', + 'browser/first_run/upgrade_util.cc', + 'browser/first_run/upgrade_util.h', ], 'conditions': [ ['use_gnome_keyring==1', { @@ -3552,8 +3552,8 @@ 'browser/automation/automation_provider_list_generic.cc', 'browser/bookmarks/bookmark_context_menu.cc', 'browser/bookmarks/bookmark_drop_info.cc', - 'browser/first_run/upgrade.cc', - 'browser/first_run/upgrade.h', + 'browser/first_run/upgrade_util.cc', + 'browser/first_run/upgrade_util.h', 'browser/importer/nss_decryptor_system_nss.cc', 'browser/importer/nss_decryptor_system_nss.h', 'browser/jankometer.cc', @@ -3714,8 +3714,8 @@ } }, 'sources': [ - 'browser/first_run/upgrade.cc', - 'browser/first_run/upgrade.h', + 'browser/first_run/upgrade_util.cc', + 'browser/first_run/upgrade_util.h', # Using built-in rule in vstudio for midl. 'browser/history/history_indexer.idl', 'browser/ui/webui/conflicts_ui.cc', diff --git a/chrome/installer/setup/install_worker.cc b/chrome/installer/setup/install_worker.cc index 7bdc9e5..da91368 100644 --- a/chrome/installer/setup/install_worker.cc +++ b/chrome/installer/setup/install_worker.cc @@ -395,7 +395,7 @@ bool AppendPostInstallTasks(const InstallerState& installer_state, // However, as it stands, we don't have a way to know which distribution // will check the key and run the command, so we add it for all. // After the first run, the subsequent runs should just be noops. - // (see Upgrade::SwapNewChromeExeIfPresent). + // (see upgrade_utils::SwapNewChromeExeIfPresent). CommandLine product_rename_cmd(rename); products[i]->AppendProductFlags(&product_rename_cmd); in_use_update_work_items->AddSetRegValueWorkItem( @@ -416,7 +416,7 @@ bool AppendPostInstallTasks(const InstallerState& installer_state, UTF8ToWide(current_version->GetString()), true); // TODO(tommi): We should move the rename command here. We also need to - // update Upgrade::SwapNewChromeExeIfPresent. + // update upgrade_utils::SwapNewChromeExeIfPresent. } post_install_task_list->AddWorkItem(in_use_update_work_items.release()); |