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_POSIX) && !defined(OS_ANDROID) | 27 #if defined(OS_POSIX) && (!defined(OS_ANDROID) || defined(USE_AURA)) |
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 Loading... |
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 preferred to notifying | 85 // this method, only callers for whom failure is preferred to notifying |
86 // another process should call this directly. | 86 // another 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_ANDROID) | 92 #if defined(OS_POSIX) && (!defined(OS_ANDROID) || defined(USE_AURA)) |
93 static void DisablePromptForTesting(); | 93 static void DisablePromptForTesting(); |
94 #endif | 94 #endif |
95 #if defined(OS_WIN) | 95 #if defined(OS_WIN) |
96 // Called to query whether to kill a hung browser process that has visible | 96 // Called to query whether to kill a hung browser process that has visible |
97 // windows. Return true to allow killing the hung process. | 97 // windows. Return true to allow killing the hung process. |
98 using ShouldKillRemoteProcessCallback = base::Callback<bool()>; | 98 using ShouldKillRemoteProcessCallback = base::Callback<bool()>; |
99 void OverrideShouldKillRemoteProcessCallbackForTesting( | 99 void OverrideShouldKillRemoteProcessCallbackForTesting( |
100 const ShouldKillRemoteProcessCallback& display_dialog_callback); | 100 const ShouldKillRemoteProcessCallback& display_dialog_callback); |
101 #endif | 101 #endif |
102 | 102 |
103 protected: | 103 protected: |
104 // Notify another process, if available. | 104 // Notify another process, if available. |
105 // Returns true if another process was found and notified, false if we should | 105 // Returns true if another process was found and notified, false if we should |
106 // continue with the current process. | 106 // continue with the current process. |
107 // On Windows, Create() has to be called before this. | 107 // On Windows, Create() has to be called before this. |
108 NotifyResult NotifyOtherProcess(); | 108 NotifyResult NotifyOtherProcess(); |
109 | 109 |
110 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 110 #if defined(OS_POSIX) && (!defined(OS_ANDROID) || defined(USE_AURA)) |
111 // Exposed for testing. We use a timeout on Linux, and in tests we want | 111 // Exposed for testing. We use a timeout on Linux, and in tests we want |
112 // this timeout to be short. | 112 // this timeout to be short. |
113 NotifyResult NotifyOtherProcessWithTimeout( | 113 NotifyResult NotifyOtherProcessWithTimeout( |
114 const base::CommandLine& command_line, | 114 const base::CommandLine& command_line, |
115 int retry_attempts, | 115 int retry_attempts, |
116 const base::TimeDelta& timeout, | 116 const base::TimeDelta& timeout, |
117 bool kill_unresponsive); | 117 bool kill_unresponsive); |
118 NotifyResult NotifyOtherProcessWithTimeoutOrCreate( | 118 NotifyResult NotifyOtherProcessWithTimeoutOrCreate( |
119 const base::CommandLine& command_line, | 119 const base::CommandLine& command_line, |
120 int retry_attempts, | 120 int retry_attempts, |
121 const base::TimeDelta& timeout); | 121 const base::TimeDelta& timeout); |
122 void OverrideCurrentPidForTesting(base::ProcessId pid); | 122 void OverrideCurrentPidForTesting(base::ProcessId pid); |
123 void OverrideKillCallbackForTesting( | 123 void OverrideKillCallbackForTesting( |
124 const base::Callback<void(int)>& callback); | 124 const base::Callback<void(int)>& callback); |
125 #endif | 125 #endif |
126 | 126 |
127 private: | 127 private: |
128 NotificationCallback notification_callback_; // Handler for notifications. | 128 NotificationCallback notification_callback_; // Handler for notifications. |
129 | 129 |
130 #if defined(OS_WIN) | 130 #if defined(OS_WIN) |
131 bool EscapeVirtualization(const base::FilePath& user_data_dir); | 131 bool EscapeVirtualization(const base::FilePath& user_data_dir); |
132 | 132 |
133 HWND remote_window_; // The HWND_MESSAGE of another browser. | 133 HWND remote_window_; // The HWND_MESSAGE of another browser. |
134 base::win::MessageWindow window_; // The message-only window. | 134 base::win::MessageWindow window_; // The message-only window. |
135 bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment. | 135 bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment. |
136 HANDLE lock_file_; | 136 HANDLE lock_file_; |
137 base::FilePath user_data_dir_; | 137 base::FilePath user_data_dir_; |
138 ShouldKillRemoteProcessCallback should_kill_remote_process_callback_; | 138 ShouldKillRemoteProcessCallback should_kill_remote_process_callback_; |
139 #elif defined(OS_POSIX) && !defined(OS_ANDROID) | 139 #elif defined(OS_POSIX) && (!defined(OS_ANDROID) || defined(USE_AURA)) |
140 // Return true if the given pid is one of our child processes. | 140 // Return true if the given pid is one of our child processes. |
141 // Assumes that the current pid is the root of all pids of the current | 141 // Assumes that the current pid is the root of all pids of the current |
142 // instance. | 142 // instance. |
143 bool IsSameChromeInstance(pid_t pid); | 143 bool IsSameChromeInstance(pid_t pid); |
144 | 144 |
145 // Extract the process's pid from a symbol link path and if it is on | 145 // Extract the process's pid from a symbol link path and if it is on |
146 // the same host, kill the process, unlink the lock file and return true. | 146 // the same host, kill the process, unlink the lock file and return true. |
147 // If the process is part of the same chrome instance, unlink the lock file | 147 // If the process is part of the same chrome instance, unlink the lock file |
148 // and return true without killing it. | 148 // and return true without killing it. |
149 // If the process is on a different host, return false. | 149 // If the process is on a different host, return false. |
(...skipping 24 matching lines...) Expand all Loading... |
174 // Helper class for linux specific messages. LinuxWatcher is ref counted | 174 // Helper class for linux specific messages. LinuxWatcher is ref counted |
175 // because it posts messages between threads. | 175 // because it posts messages between threads. |
176 class LinuxWatcher; | 176 class LinuxWatcher; |
177 scoped_refptr<LinuxWatcher> watcher_; | 177 scoped_refptr<LinuxWatcher> watcher_; |
178 #endif | 178 #endif |
179 | 179 |
180 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); | 180 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); |
181 }; | 181 }; |
182 | 182 |
183 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ | 183 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ |
OLD | NEW |