diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 20:41:00 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-20 20:41:00 +0000 |
commit | b674dc73f0b635aa2f7be660153e5b05f6a9b593 (patch) | |
tree | a4cd2becc248b9ea67aa42dbea9956a1148811f4 /chrome/browser/process_singleton.h | |
parent | 7adb10a395b875ab2c8cc47c8723c70f1cfd7025 (diff) | |
download | chromium_src-b674dc73f0b635aa2f7be660153e5b05f6a9b593.zip chromium_src-b674dc73f0b635aa2f7be660153e5b05f6a9b593.tar.gz chromium_src-b674dc73f0b635aa2f7be660153e5b05f6a9b593.tar.bz2 |
Implement process singleton on linux so if the user tries to
open multiple chrome processes, the first one just opens a new window.
This is based on http://codereview.chromium.org/88067 by Nikita
Ofitserov (himikof).
BUG=8073
Review URL: http://codereview.chromium.org/115572
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16528 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/process_singleton.h')
-rw-r--r-- | chrome/browser/process_singleton.h | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/chrome/browser/process_singleton.h b/chrome/browser/process_singleton.h index 0e39417..3ef620a 100644 --- a/chrome/browser/process_singleton.h +++ b/chrome/browser/process_singleton.h @@ -14,6 +14,9 @@ #include "base/basictypes.h" #include "base/file_path.h" #include "base/gfx/native_widget_types.h" +#include "base/logging.h" +#include "base/non_thread_safe.h" +#include "base/ref_counted.h" // ProcessSingleton ---------------------------------------------------------- // @@ -26,7 +29,7 @@ // - the Windows implementation uses an invisible global message window; // - the Linux implementation uses a Unix domain socket in the user data dir. -class ProcessSingleton { +class ProcessSingleton : public NonThreadSafe { public: explicit ProcessSingleton(const FilePath& user_data_dir); ~ProcessSingleton(); @@ -40,23 +43,30 @@ class ProcessSingleton { // first one, so this function won't find it. bool NotifyOtherProcess(); - // Set ourselves up as the singleton instance. + // Sets ourself up as the singleton instance. void Create(); // Blocks the dispatch of CopyData messages. foreground_window refers // to the window that should be set to the foreground if a CopyData message // is received while the ProcessSingleton is locked. void Lock(gfx::NativeWindow foreground_window) { + DCHECK(CalledOnValidThread()); locked_ = true; foreground_window_ = foreground_window; } // Allows the dispatch of CopyData messages. void Unlock() { + DCHECK(CalledOnValidThread()); locked_ = false; foreground_window_ = NULL; } + bool locked() { + DCHECK(CalledOnValidThread()); + return locked_; + } + private: bool locked_; gfx::NativeWindow foreground_window_; @@ -87,6 +97,11 @@ class ProcessSingleton { // Path in file system to the socket. FilePath socket_path_; + + // Helper class for linux specific messages. LinuxWatcher is ref counted + // because it posts messages between threads. + class LinuxWatcher; + scoped_refptr<LinuxWatcher> watcher_; #endif DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); |