summaryrefslogtreecommitdiffstats
path: root/chrome/browser/process_singleton.h
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-18 00:34:21 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-18 00:34:21 +0000
commit7c47ae3e1448b0ae65d7d75a7ed82d66334b11f8 (patch)
treed718ace931258ad51fbcac618030aab236fb1bfb /chrome/browser/process_singleton.h
parente4844e11f1f5a9ee8707b1f6f79aa3de54db2248 (diff)
downloadchromium_src-7c47ae3e1448b0ae65d7d75a7ed82d66334b11f8.zip
chromium_src-7c47ae3e1448b0ae65d7d75a7ed82d66334b11f8.tar.gz
chromium_src-7c47ae3e1448b0ae65d7d75a7ed82d66334b11f8.tar.bz2
Rename MessageWindow to ProcessSingleton in anticipation of more refactoring.
Review URL: http://codereview.chromium.org/20437 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9923 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/process_singleton.h')
-rw-r--r--chrome/browser/process_singleton.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/chrome/browser/process_singleton.h b/chrome/browser/process_singleton.h
new file mode 100644
index 0000000..7e38def
--- /dev/null
+++ b/chrome/browser/process_singleton.h
@@ -0,0 +1,78 @@
+// Copyright (c) 2009 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_PROCESS_SINGLETON_H_
+#define CHROME_BROWSER_PROCESS_SINGLETON_H_
+
+#include <string>
+#include <windows.h>
+
+#include "base/basictypes.h"
+#include "base/file_path.h"
+
+// ProcessSingleton ----------------------------------------------------------
+//
+// This class allows different browser processes to communicate with
+// each other. It is named according to the user data directory, so
+// we can be sure that no more than one copy of the application can be
+// running at once with a given data directory.
+//
+// The Windows implementation uses an invisible global message window for
+// IPC.
+
+class ProcessSingleton {
+ public:
+ explicit ProcessSingleton(const FilePath& user_data_dir);
+ ~ProcessSingleton();
+
+ // Returns true if another process was found and notified, false if we
+ // should continue with this process. Roughly based on Mozilla
+ //
+ // TODO(brettw): this will not handle all cases. If two process start up too
+ // close to each other, the window might not have been created yet for the
+ // first one, so this function won't find it.
+ bool NotifyOtherProcess();
+
+ // Create the toplevel message window for IPC.
+ void Create();
+
+ // Blocks the dispatch of CopyData messages.
+ void Lock() {
+ locked_ = true;
+ }
+
+ // Allows the dispatch of CopyData messages.
+ void Unlock() {
+ locked_ = false;
+ }
+
+ // This ugly behemoth handles startup commands sent from another process.
+ LRESULT OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds);
+
+ // Looks for zombie renderer and plugin processes that could have survived.
+ void HuntForZombieChromeProcesses();
+
+ private:
+ LRESULT CALLBACK WndProc(HWND hwnd,
+ UINT message,
+ WPARAM wparam,
+ LPARAM lparam);
+
+ static LRESULT CALLBACK WndProcStatic(HWND hwnd,
+ UINT message,
+ WPARAM wparam,
+ LPARAM lparam) {
+ ProcessSingleton* msg_wnd = reinterpret_cast<ProcessSingleton*>(
+ GetWindowLongPtr(hwnd, GWLP_USERDATA));
+ return msg_wnd->WndProc(hwnd, message, wparam, lparam);
+ }
+
+ HWND remote_window_; // The HWND_MESSAGE of another browser.
+ HWND window_; // The HWND_MESSAGE window.
+ bool locked_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProcessSingleton);
+};
+
+#endif // #ifndef CHROME_BROWSER_PROCESS_SINGLETON_H_