Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1592)

Unified Diff: chrome/browser/process_singleton_win.cc

Issue 10702159: Implement lock file for windows profiles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved the check to after checking for local instances. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/process_singleton.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/process_singleton_win.cc
diff --git a/chrome/browser/process_singleton_win.cc b/chrome/browser/process_singleton_win.cc
index 783c9da1a6260270fecd633ad675d9e16a3125e4..793a336a811843da616fb24816e20503d633f91f 100644
--- a/chrome/browser/process_singleton_win.cc
+++ b/chrome/browser/process_singleton_win.cc
@@ -148,7 +148,7 @@ bool ProcessSingleton::EscapeVirtualization(const FilePath& user_data_dir) {
// the profile directory path.
ProcessSingleton::ProcessSingleton(const FilePath& user_data_dir)
: window_(NULL), locked_(false), foreground_window_(NULL),
- is_virtualized_(false) {
+ is_virtualized_(false), lock_file_(INVALID_HANDLE_VALUE) {
remote_window_ = FindWindowEx(HWND_MESSAGE, NULL,
chrome::kMessageWindowClass,
user_data_dir.value().c_str());
@@ -175,7 +175,42 @@ ProcessSingleton::ProcessSingleton(const FilePath& user_data_dir)
remote_window_ = FindWindowEx(HWND_MESSAGE, NULL,
chrome::kMessageWindowClass,
user_data_dir.value().c_str());
- if (!remote_window_) {
+ // We have to make sure there is no Chrome instance running on another
cpu_(ooo_6.6-7.5) 2012/07/13 23:16:53 why do it if the directory is not remote?
pastarmovj 2012/07/14 01:21:58 To check if a path contains a reparse point hence
+ // machine that uses the same profile.
+ FilePath lock_file_path = user_data_dir.AppendASCII("lockfile");
+ lock_file_ = CreateFile(lock_file_path.value().c_str(),
+ GENERIC_WRITE,
+ FILE_SHARE_READ,
+ NULL,
+ CREATE_NEW,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE,
+ NULL);
+ DWORD error = GetLastError();
+ LOG(ERROR) << "@@@ First lock file attempt : " << lock_file_
+ << " code " << error;
+ if (lock_file_ == INVALID_HANDLE_VALUE && error == ERROR_FILE_EXISTS) {
+ // If we are inside here that means that some other machine has or had an
+ // active chrome process. This second try destinguishes between stale file
+ // and really actively opened file. We should directly do this check but
+ // for completeness we do both check sequentially.
+ lock_file_ = CreateFile(lock_file_path.value().c_str(),
+ GENERIC_WRITE,
+ FILE_SHARE_READ,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE,
+ NULL);
+ error = GetLastError();
+ LOG(ERROR) << "@@@ Second lock file attempt : " << lock_file_
+ << " code " << error;
+ }
+ if (lock_file_ == INVALID_HANDLE_VALUE) {
+ // If both attempts failed we are left with no other option but to admit
+ // defeat and make harakiri to ourselves.
+ LOG(ERROR) << "@@@ There is another chrome process that is still active";
+ }
+
+ if (!remote_window_ && lock_file_ != INVALID_HANDLE_VALUE) {
HINSTANCE hinst = base::GetModuleFromAddress(&ThunkWndProc);
WNDCLASSEX wc = {0};
@@ -207,6 +242,8 @@ ProcessSingleton::~ProcessSingleton() {
::UnregisterClass(chrome::kMessageWindowClass,
base::GetModuleFromAddress(&ThunkWndProc));
}
+ if (lock_file_ != INVALID_HANDLE_VALUE)
+ CloseHandle(lock_file_);
cpu_(ooo_6.6-7.5) 2012/07/13 23:16:53 why close it here?
pastarmovj 2012/07/14 01:21:58 Mmmm...clean up...I guess :-) . Well basically th
}
ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() {
@@ -299,6 +336,9 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessOrCreate(
// Create().
bool ProcessSingleton::Create(
const NotificationCallback& notification_callback) {
+ if (lock_file_ == INVALID_HANDLE_VALUE)
+ return false;
+
cpu_(ooo_6.6-7.5) 2012/07/13 23:16:53 and not sure we need this here either..
pastarmovj 2012/07/14 01:21:58 This actually will make the newly started process
DCHECK(!remote_window_);
DCHECK(notification_callback_.is_null());
« no previous file with comments | « chrome/browser/process_singleton.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698