summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-15 02:09:33 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-15 02:09:33 +0000
commita3abd5576efc64d117141bde14f390fd7e6c6e33 (patch)
tree5f77cfdbafd3f3b310710009d767b956320e987c
parentee1208717f1e931175c81f63a5a8ef6338091dee (diff)
downloadchromium_src-a3abd5576efc64d117141bde14f390fd7e6c6e33.zip
chromium_src-a3abd5576efc64d117141bde14f390fd7e6c6e33.tar.gz
chromium_src-a3abd5576efc64d117141bde14f390fd7e6c6e33.tar.bz2
first-run: Pull IsBrowserAlreadyRunning() out of upgrade_util_win.h.
This concept is not specific to upgrade path and thus shouldn't belong there. Move it to a new header file called browser_util_win.h as it's more appropriate. BUG=79203 TEST=None R=jhawkins@chromium.org Review URL: http://codereview.chromium.org/6861001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81691 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser_main.cc3
-rw-r--r--chrome/browser/browser_main_win.cc4
-rw-r--r--chrome/browser/browser_shutdown.cc3
-rw-r--r--chrome/browser/browser_util_win.cc33
-rw-r--r--chrome/browser/browser_util_win.h20
-rw-r--r--chrome/browser/first_run/upgrade_util_win.cc16
-rw-r--r--chrome/browser/first_run/upgrade_util_win.h7
-rw-r--r--chrome/browser/process_singleton.h2
-rw-r--r--chrome/chrome_browser.gypi2
9 files changed, 62 insertions, 28 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index faa2335..e8b96c8 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -159,6 +159,7 @@
#include "app/win/scoped_com_initializer.h"
#include "base/win/windows_version.h"
#include "chrome/browser/browser_trial.h"
+#include "chrome/browser/browser_util_win.h"
#include "chrome/browser/first_run/try_chrome_dialog_view.h"
#include "chrome/browser/first_run/upgrade_util_win.h"
#include "chrome/browser/metrics/user_metrics.h"
@@ -1356,7 +1357,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_util::IsBrowserAlreadyRunning();
+ bool already_running = browser_util::IsBrowserAlreadyRunning();
// If the command line specifies 'uninstall' then we need to work here
// unless we detect another chrome browser running.
diff --git a/chrome/browser/browser_main_win.cc b/chrome/browser/browser_main_win.cc
index d8b8cdd..e0a704c 100644
--- a/chrome/browser/browser_main_win.cc
+++ b/chrome/browser/browser_main_win.cc
@@ -20,8 +20,8 @@
#include "base/win/windows_version.h"
#include "base/win/wrapped_window_proc.h"
#include "crypto/nss_util.h"
+#include "chrome/browser/browser_util_win.h"
#include "chrome/browser/first_run/first_run.h"
-#include "chrome/browser/first_run/upgrade_util_win.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_util::IsBrowserAlreadyRunning()) {
+ if (browser_util::IsBrowserAlreadyRunning()) {
ShowCloseBrowserFirstMessageBox();
return ResultCodes::UNINSTALL_CHROME_ALIVE;
}
diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc
index 374e37c..cf6d1e5 100644
--- a/chrome/browser/browser_shutdown.cc
+++ b/chrome/browser/browser_shutdown.cc
@@ -43,6 +43,7 @@
#include "ui/base/resource/resource_bundle.h"
#if defined(OS_WIN)
+#include "chrome/browser/browser_util_win.h"
#include "chrome/browser/first_run/upgrade_util_win.h"
#include "chrome/browser/rlz/rlz.h"
#endif
@@ -190,7 +191,7 @@ void Shutdown() {
ResourceBundle::CleanupSharedInstance();
#if defined(OS_WIN)
- if (!upgrade_util::IsBrowserAlreadyRunning() &&
+ if (!browser_util::IsBrowserAlreadyRunning() &&
shutdown_type_ != browser_shutdown::END_SESSION) {
upgrade_util::SwapNewChromeExeIfPresent();
}
diff --git a/chrome/browser/browser_util_win.cc b/chrome/browser/browser_util_win.cc
new file mode 100644
index 0000000..f4c11c7
--- /dev/null
+++ b/chrome/browser/browser_util_win.cc
@@ -0,0 +1,33 @@
+// 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/browser_util_win.h"
+
+#include <windows.h>
+
+#include <algorithm>
+#include <string>
+
+#include "base/base_paths.h"
+#include "base/file_path.h"
+#include "base/path_service.h"
+
+namespace browser_util {
+
+bool IsBrowserAlreadyRunning() {
+ static HANDLE handle = NULL;
+ FilePath exe_path;
+ PathService::Get(base::FILE_EXE, &exe_path);
+ std::wstring exe = exe_path.value();
+ 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);
+}
+
+} // namespace browser_util
diff --git a/chrome/browser/browser_util_win.h b/chrome/browser/browser_util_win.h
new file mode 100644
index 0000000..236c936
--- /dev/null
+++ b/chrome/browser/browser_util_win.h
@@ -0,0 +1,20 @@
+// 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_BROWSER_UTIL_WIN_H_
+#define CHROME_BROWSER_BROWSER_UTIL_WIN_H_
+#pragma once
+
+namespace browser_util {
+
+// 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();
+
+} // namespace browser_util
+
+#endif // CHROME_BROWSER_BROWSER_UTIL_WIN_H_
diff --git a/chrome/browser/first_run/upgrade_util_win.cc b/chrome/browser/first_run/upgrade_util_win.cc
index 7789a2e..6b71d8a 100644
--- a/chrome/browser/first_run/upgrade_util_win.cc
+++ b/chrome/browser/first_run/upgrade_util_win.cc
@@ -59,7 +59,6 @@ bool InvokeGoogleUpdateForRename() {
} // namespace
-
namespace upgrade_util {
bool RelaunchChromeBrowser(const CommandLine& command_line) {
@@ -76,21 +75,6 @@ bool IsUpdatePendingRestart() {
return file_util::PathExists(new_chrome_exe);
}
-bool IsBrowserAlreadyRunning() {
- static HANDLE handle = NULL;
- FilePath exe_path;
- PathService::Get(base::FILE_EXE, &exe_path);
- std::wstring exe = exe_path.value();
- 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 SwapNewChromeExeIfPresent() {
FilePath new_chrome_exe;
if (!GetNewerChromeFile(&new_chrome_exe))
diff --git a/chrome/browser/first_run/upgrade_util_win.h b/chrome/browser/first_run/upgrade_util_win.h
index da63aaa..3bbbace 100644
--- a/chrome/browser/first_run/upgrade_util_win.h
+++ b/chrome/browser/first_run/upgrade_util_win.h
@@ -10,13 +10,6 @@ class CommandLine;
namespace upgrade_util {
-// 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;
diff --git a/chrome/browser/process_singleton.h b/chrome/browser/process_singleton.h
index 5d6da98..cc0ca08 100644
--- a/chrome/browser/process_singleton.h
+++ b/chrome/browser/process_singleton.h
@@ -83,7 +83,7 @@ class ProcessSingleton : public base::NonThreadSafe {
// 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_util::IsBrowserAlreadyRunning().
+ // browser_util::IsBrowserAlreadyRunning().
bool FoundOtherProcessWindow() const {
return (NULL != remote_window_);
}
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 79771de..a0bfb81 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -316,6 +316,8 @@
'browser/browser_trial.h',
'browser/browser_url_handler.cc',
'browser/browser_url_handler.h',
+ 'browser/browser_util_win.cc',
+ 'browser/browser_util_win.h',
'browser/browsing_data_appcache_helper.cc',
'browser/browsing_data_appcache_helper.h',
'browser/browsing_data_database_helper.cc',