summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-12 22:39:58 +0000
committerkuchhal@chromium.org <kuchhal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-12 22:39:58 +0000
commitc4334a4b0cd6b1b11b115251d8859a502a22d6db (patch)
tree082b21a77e42b7f16185ef3031254a6633c62ef1 /chrome/browser
parent603c1d0ce8f84241739005df226f5e31494dd3cd (diff)
downloadchromium_src-c4334a4b0cd6b1b11b115251d8859a502a22d6db.zip
chromium_src-c4334a4b0cd6b1b11b115251d8859a502a22d6db.tar.gz
chromium_src-c4334a4b0cd6b1b11b115251d8859a502a22d6db.tar.bz2
* Try to rename chrome exes in shutdown path as well.
BUG=1463346 Review URL: http://codereview.chromium.org/10805 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5313 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser_main.cc13
-rw-r--r--chrome/browser/browser_shutdown.cc5
-rwxr-xr-x[-rw-r--r--]chrome/browser/first_run.cc26
-rw-r--r--chrome/browser/first_run.h14
4 files changed, 37 insertions, 21 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index cbfd34a..a60be84 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -214,17 +214,6 @@ bool DoUpgradeTasks(const CommandLine& command_line) {
return true;
}
-bool CreateUniqueChromeEvent() {
- std::wstring exe;
- PathService::Get(base::FILE_EXE, &exe);
- std::replace(exe.begin(), exe.end(), '\\', '!');
- std::transform(exe.begin(), exe.end(), exe.begin(), tolower);
- exe = L"Global\\" + exe;
- HANDLE handle = CreateEvent(NULL, TRUE, TRUE, exe.c_str());
- int error = GetLastError();
- return (error == ERROR_ALREADY_EXISTS || error == ERROR_ACCESS_DENIED);
-}
-
// Check if there is any machine level Chrome installed on the current
// machine. If yes and the current Chrome process is user level, we do not
// allow the user level Chrome to run. So we notify the user and uninstall
@@ -290,7 +279,7 @@ int BrowserMain(CommandLine &parsed_command_line, int show_command,
const char* thread_name = thread_name_string.c_str();
PlatformThread::SetName(thread_name);
main_message_loop.set_thread_name(thread_name);
- bool already_running = CreateUniqueChromeEvent();
+ bool already_running = Upgrade::IsBrowserAlreadyRunning();
#if defined(OS_WIN)
// Make the selection of network stacks early on before any consumers try to
diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc
index ef38181..e192688 100644
--- a/chrome/browser/browser_shutdown.cc
+++ b/chrome/browser/browser_shutdown.cc
@@ -10,6 +10,7 @@
#include "base/string_util.h"
#include "base/time.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/first_run.h"
#include "chrome/browser/jankometer.h"
#include "chrome/browser/metrics_service.h"
#include "chrome/browser/plugin_process_host.h"
@@ -123,6 +124,10 @@ void Shutdown() {
ResourceBundle::CleanupSharedInstance();
+ if (!Upgrade::IsBrowserAlreadyRunning()) {
+ Upgrade::SwapNewChromeExeIfPresent();
+ }
+
if (shutdown_type_ > NOT_VALID && shutdown_num_processes_ > 0) {
// Measure total shutdown time as late in the process as possible
// and then write it to a file to be read at startup.
diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc
index de08f40..3e82aa0 100644..100755
--- a/chrome/browser/first_run.cc
+++ b/chrome/browser/first_run.cc
@@ -190,6 +190,26 @@ bool FirstRun::ProcessMasterPreferences(
return false;
}
+bool Upgrade::IsBrowserAlreadyRunning() {
+ static HANDLE handle = NULL;
+ std::wstring exe;
+ PathService::Get(base::FILE_EXE, &exe);
+ std::replace(exe.begin(), exe.end(), '\\', '!');
+ std::transform(exe.begin(), exe.end(), exe.begin(), tolower);
+ exe = L"Global\\" + exe;
+ if (handle != NULL)
+ CloseHandle(handle);
+ handle = CreateEvent(NULL, TRUE, TRUE, exe.c_str());
+ int error = GetLastError();
+ return (error == ERROR_ALREADY_EXISTS || error == ERROR_ACCESS_DENIED);
+}
+
+bool Upgrade::RelaunchChromeBrowser(const CommandLine& command_line) {
+ ::SetEnvironmentVariable(google_update::kEnvProductVersionKey, NULL);
+ return process_util::LaunchApp(command_line.command_line_string(),
+ false, false, NULL);
+}
+
bool Upgrade::SwapNewChromeExeIfPresent() {
std::wstring new_chrome_exe;
if (!GetNewerChromeFile(&new_chrome_exe))
@@ -226,12 +246,6 @@ bool Upgrade::SwapNewChromeExeIfPresent() {
return false;
}
-bool Upgrade::RelaunchChromeBrowser(const CommandLine& command_line) {
- ::SetEnvironmentVariable(google_update::kEnvProductVersionKey, NULL);
- return process_util::LaunchApp(command_line.command_line_string(),
- false, false, NULL);
-}
-
void OpenFirstRunDialog(Profile* profile) {
views::Window::CreateChromeWindow(NULL, gfx::Rect(),
new FirstRunView(profile))->Show();
diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h
index 4cdd2b6..4332b8b 100644
--- a/chrome/browser/first_run.h
+++ b/chrome/browser/first_run.h
@@ -84,13 +84,21 @@ class FirstRun {
// the new browser.
class Upgrade {
public:
+ // 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();
+
+ // 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 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();
- // Launches chrome again simulating a 'user' launch. If chrome could not
- // be launched the return is false.
- static bool RelaunchChromeBrowser(const CommandLine& command_line);
};
// A subclass of BrowserProcessImpl that does not have a GoogleURLTracker