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

Side by Side Diff: chrome/browser/process_singleton.h

Issue 218883008: Use process_singleton_linux on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Handle old SingletonLock Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_PROCESS_SINGLETON_H_ 5 #ifndef CHROME_BROWSER_PROCESS_SINGLETON_H_
6 #define CHROME_BROWSER_PROCESS_SINGLETON_H_ 6 #define CHROME_BROWSER_PROCESS_SINGLETON_H_
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #if defined(OS_WIN) 10 #if defined(OS_WIN)
11 #include <windows.h> 11 #include <windows.h>
12 #endif // defined(OS_WIN) 12 #endif // defined(OS_WIN)
13 13
14 #include <set> 14 #include <set>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/basictypes.h" 17 #include "base/basictypes.h"
18 #include "base/callback.h" 18 #include "base/callback.h"
19 #include "base/command_line.h" 19 #include "base/command_line.h"
20 #include "base/files/file_path.h" 20 #include "base/files/file_path.h"
21 #include "base/logging.h" 21 #include "base/logging.h"
22 #include "base/memory/ref_counted.h" 22 #include "base/memory/ref_counted.h"
23 #include "base/process/process.h" 23 #include "base/process/process.h"
24 #include "base/threading/non_thread_safe.h" 24 #include "base/threading/non_thread_safe.h"
25 #include "ui/gfx/native_widget_types.h" 25 #include "ui/gfx/native_widget_types.h"
26 26
27 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 27 #if defined(OS_POSIX) && !defined(OS_ANDROID)
28 #include "base/files/scoped_temp_dir.h" 28 #include "base/files/scoped_temp_dir.h"
29 #endif 29 #endif
30 30
31 #if defined(OS_WIN) 31 #if defined(OS_WIN)
32 #include "base/win/message_window.h" 32 #include "base/win/message_window.h"
33 #endif // defined(OS_WIN) 33 #endif // defined(OS_WIN)
34 34
35 namespace base { 35 namespace base {
36 class CommandLine; 36 class CommandLine;
37 } 37 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // false is returned, we are not the singleton instance and the caller must 82 // false is returned, we are not the singleton instance and the caller must
83 // exit. 83 // exit.
84 // NOTE: Most callers should generally prefer NotifyOtherProcessOrCreate() to 84 // NOTE: Most callers should generally prefer NotifyOtherProcessOrCreate() to
85 // this method, only callers for whom failure is prefered to notifying another 85 // this method, only callers for whom failure is prefered to notifying another
86 // process should call this directly. 86 // process should call this directly.
87 bool Create(); 87 bool Create();
88 88
89 // Clear any lock state during shutdown. 89 // Clear any lock state during shutdown.
90 void Cleanup(); 90 void Cleanup();
91 91
92 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 92 #if defined(OS_POSIX) && !defined(OS_ANDROID)
93 static void DisablePromptForTesting(); 93 static void DisablePromptForTesting();
94 #endif 94 #endif
95 95
96 protected: 96 protected:
97 // Notify another process, if available. 97 // Notify another process, if available.
98 // Returns true if another process was found and notified, false if we should 98 // Returns true if another process was found and notified, false if we should
99 // continue with the current process. 99 // continue with the current process.
100 // On Windows, Create() has to be called before this. 100 // On Windows, Create() has to be called before this.
101 NotifyResult NotifyOtherProcess(); 101 NotifyResult NotifyOtherProcess();
102 102
103 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 103 #if defined(OS_POSIX) && !defined(OS_ANDROID)
104 // Exposed for testing. We use a timeout on Linux, and in tests we want 104 // Exposed for testing. We use a timeout on Linux, and in tests we want
105 // this timeout to be short. 105 // this timeout to be short.
106 NotifyResult NotifyOtherProcessWithTimeout( 106 NotifyResult NotifyOtherProcessWithTimeout(
107 const base::CommandLine& command_line, 107 const base::CommandLine& command_line,
108 int timeout_seconds, 108 int timeout_seconds,
109 bool kill_unresponsive); 109 bool kill_unresponsive);
110 NotifyResult NotifyOtherProcessWithTimeoutOrCreate( 110 NotifyResult NotifyOtherProcessWithTimeoutOrCreate(
111 const base::CommandLine& command_line, 111 const base::CommandLine& command_line,
112 int timeout_seconds); 112 int timeout_seconds);
113 void OverrideCurrentPidForTesting(base::ProcessId pid); 113 void OverrideCurrentPidForTesting(base::ProcessId pid);
114 void OverrideKillCallbackForTesting( 114 void OverrideKillCallbackForTesting(
115 const base::Callback<void(int)>& callback); 115 const base::Callback<void(int)>& callback);
116 #endif 116 #endif
117 117
118 private: 118 private:
119 #if !defined(OS_MACOSX)
120 // Timeout for the current browser process to respond. 20 seconds should be 119 // Timeout for the current browser process to respond. 20 seconds should be
121 // enough. It's only used in Windows and Linux implementations. 120 // enough.
122 static const int kTimeoutInSeconds = 20; 121 static const int kTimeoutInSeconds = 20;
123 #endif
124 122
125 NotificationCallback notification_callback_; // Handler for notifications. 123 NotificationCallback notification_callback_; // Handler for notifications.
126 124
127 #if defined(OS_WIN) 125 #if defined(OS_WIN)
128 bool EscapeVirtualization(const base::FilePath& user_data_dir); 126 bool EscapeVirtualization(const base::FilePath& user_data_dir);
129 127
130 HWND remote_window_; // The HWND_MESSAGE of another browser. 128 HWND remote_window_; // The HWND_MESSAGE of another browser.
131 base::win::MessageWindow window_; // The message-only window. 129 base::win::MessageWindow window_; // The message-only window.
132 bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment. 130 bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment.
133 HANDLE lock_file_; 131 HANDLE lock_file_;
134 base::FilePath user_data_dir_; 132 base::FilePath user_data_dir_;
135 #elif defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 133 #elif defined(OS_POSIX) && !defined(OS_ANDROID)
136 // Return true if the given pid is one of our child processes. 134 // Return true if the given pid is one of our child processes.
137 // Assumes that the current pid is the root of all pids of the current 135 // Assumes that the current pid is the root of all pids of the current
138 // instance. 136 // instance.
139 bool IsSameChromeInstance(pid_t pid); 137 bool IsSameChromeInstance(pid_t pid);
140 138
141 // Extract the process's pid from a symbol link path and if it is on 139 // Extract the process's pid from a symbol link path and if it is on
142 // the same host, kill the process, unlink the lock file and return true. 140 // the same host, kill the process, unlink the lock file and return true.
143 // If the process is part of the same chrome instance, unlink the lock file 141 // If the process is part of the same chrome instance, unlink the lock file
144 // and return true without killing it. 142 // and return true without killing it.
145 // If the process is on a different host, return false. 143 // If the process is on a different host, return false.
(...skipping 18 matching lines...) Expand all
164 // Path in file system to the cookie file. 162 // Path in file system to the cookie file.
165 base::FilePath cookie_path_; 163 base::FilePath cookie_path_;
166 164
167 // Temporary directory to hold the socket. 165 // Temporary directory to hold the socket.
168 base::ScopedTempDir socket_dir_; 166 base::ScopedTempDir socket_dir_;
169 167
170 // Helper class for linux specific messages. LinuxWatcher is ref counted 168 // Helper class for linux specific messages. LinuxWatcher is ref counted
171 // because it posts messages between threads. 169 // because it posts messages between threads.
172 class LinuxWatcher; 170 class LinuxWatcher;
173 scoped_refptr<LinuxWatcher> watcher_; 171 scoped_refptr<LinuxWatcher> watcher_;
174 #elif defined(OS_MACOSX)
175 // Path in file system to the lock.
176 base::FilePath lock_path_;
177
178 // File descriptor associated with the lockfile, valid between
179 // |Create()| and |Cleanup()|. Two instances cannot have a lock on
180 // the same file at the same time.
181 int lock_fd_;
182 #endif 172 #endif
183 173
184 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); 174 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton);
185 }; 175 };
186 176
187 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ 177 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698