OLD | NEW |
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_LINUX) || defined(OS_OPENBSD) | 27 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) && \ |
| 28 !defined(OS_NACL) |
28 #include "base/files/scoped_temp_dir.h" | 29 #include "base/files/scoped_temp_dir.h" |
29 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) | 30 #endif |
30 | 31 |
31 #if defined(OS_WIN) | 32 #if defined(OS_WIN) |
32 #include "base/win/message_window.h" | 33 #include "base/win/message_window.h" |
33 #endif // defined(OS_WIN) | 34 #endif // defined(OS_WIN) |
34 | 35 |
35 class CommandLine; | 36 class CommandLine; |
36 | 37 |
37 // ProcessSingleton ---------------------------------------------------------- | 38 // ProcessSingleton ---------------------------------------------------------- |
38 // | 39 // |
39 // This class allows different browser processes to communicate with | 40 // This class allows different browser processes to communicate with |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // 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 |
82 // exit. | 83 // exit. |
83 // NOTE: Most callers should generally prefer NotifyOtherProcessOrCreate() to | 84 // NOTE: Most callers should generally prefer NotifyOtherProcessOrCreate() to |
84 // 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 |
85 // process should call this directly. | 86 // process should call this directly. |
86 bool Create(); | 87 bool Create(); |
87 | 88 |
88 // Clear any lock state during shutdown. | 89 // Clear any lock state during shutdown. |
89 void Cleanup(); | 90 void Cleanup(); |
90 | 91 |
91 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 92 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) && \ |
| 93 !defined(OS_NACL) |
92 static void DisablePromptForTesting(); | 94 static void DisablePromptForTesting(); |
93 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) | 95 #endif |
94 | 96 |
95 protected: | 97 protected: |
96 // Notify another process, if available. | 98 // Notify another process, if available. |
97 // Returns true if another process was found and notified, false if we should | 99 // Returns true if another process was found and notified, false if we should |
98 // continue with the current process. | 100 // continue with the current process. |
99 // On Windows, Create() has to be called before this. | 101 // On Windows, Create() has to be called before this. |
100 NotifyResult NotifyOtherProcess(); | 102 NotifyResult NotifyOtherProcess(); |
101 | 103 |
102 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 104 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) && \ |
| 105 !defined(OS_NACL) |
103 // Exposed for testing. We use a timeout on Linux, and in tests we want | 106 // Exposed for testing. We use a timeout on Linux, and in tests we want |
104 // this timeout to be short. | 107 // this timeout to be short. |
105 NotifyResult NotifyOtherProcessWithTimeout(const CommandLine& command_line, | 108 NotifyResult NotifyOtherProcessWithTimeout(const CommandLine& command_line, |
106 int timeout_seconds, | 109 int timeout_seconds, |
107 bool kill_unresponsive); | 110 bool kill_unresponsive); |
108 NotifyResult NotifyOtherProcessWithTimeoutOrCreate( | 111 NotifyResult NotifyOtherProcessWithTimeoutOrCreate( |
109 const CommandLine& command_line, | 112 const CommandLine& command_line, |
110 int timeout_seconds); | 113 int timeout_seconds); |
111 void OverrideCurrentPidForTesting(base::ProcessId pid); | 114 void OverrideCurrentPidForTesting(base::ProcessId pid); |
112 void OverrideKillCallbackForTesting( | 115 void OverrideKillCallbackForTesting( |
113 const base::Callback<void(int)>& callback); | 116 const base::Callback<void(int)>& callback); |
114 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) | 117 #endif |
115 | 118 |
116 private: | 119 private: |
117 #if !defined(OS_MACOSX) | 120 #if !defined(OS_MACOSX) |
118 // Timeout for the current browser process to respond. 20 seconds should be | 121 // Timeout for the current browser process to respond. 20 seconds should be |
119 // enough. It's only used in Windows and Linux implementations. | 122 // enough. It's only used in Windows and Linux implementations. |
120 static const int kTimeoutInSeconds = 20; | 123 static const int kTimeoutInSeconds = 20; |
121 #endif | 124 #endif |
122 | 125 |
123 NotificationCallback notification_callback_; // Handler for notifications. | 126 NotificationCallback notification_callback_; // Handler for notifications. |
124 | 127 |
125 #if defined(OS_WIN) | 128 #if defined(OS_WIN) |
126 bool EscapeVirtualization(const base::FilePath& user_data_dir); | 129 bool EscapeVirtualization(const base::FilePath& user_data_dir); |
127 | 130 |
128 HWND remote_window_; // The HWND_MESSAGE of another browser. | 131 HWND remote_window_; // The HWND_MESSAGE of another browser. |
129 base::win::MessageWindow window_; // The message-only window. | 132 base::win::MessageWindow window_; // The message-only window. |
130 bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment. | 133 bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment. |
131 HANDLE lock_file_; | 134 HANDLE lock_file_; |
132 base::FilePath user_data_dir_; | 135 base::FilePath user_data_dir_; |
133 #elif defined(OS_LINUX) || defined(OS_OPENBSD) | 136 #elif defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) && \ |
| 137 !defined(OS_NACL) |
134 // Return true if the given pid is one of our child processes. | 138 // Return true if the given pid is one of our child processes. |
135 // Assumes that the current pid is the root of all pids of the current | 139 // Assumes that the current pid is the root of all pids of the current |
136 // instance. | 140 // instance. |
137 bool IsSameChromeInstance(pid_t pid); | 141 bool IsSameChromeInstance(pid_t pid); |
138 | 142 |
139 // Extract the process's pid from a symbol link path and if it is on | 143 // Extract the process's pid from a symbol link path and if it is on |
140 // the same host, kill the process, unlink the lock file and return true. | 144 // the same host, kill the process, unlink the lock file and return true. |
141 // If the process is part of the same chrome instance, unlink the lock file | 145 // If the process is part of the same chrome instance, unlink the lock file |
142 // and return true without killing it. | 146 // and return true without killing it. |
143 // If the process is on a different host, return false. | 147 // If the process is on a different host, return false. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // File descriptor associated with the lockfile, valid between | 180 // File descriptor associated with the lockfile, valid between |
177 // |Create()| and |Cleanup()|. Two instances cannot have a lock on | 181 // |Create()| and |Cleanup()|. Two instances cannot have a lock on |
178 // the same file at the same time. | 182 // the same file at the same time. |
179 int lock_fd_; | 183 int lock_fd_; |
180 #endif | 184 #endif |
181 | 185 |
182 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); | 186 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); |
183 }; | 187 }; |
184 | 188 |
185 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ | 189 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ |
OLD | NEW |