Chromium Code Reviews| 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) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 // Chrome process was launched. Return true if the command line will be | 60 // Chrome process was launched. Return true if the command line will be |
| 61 // handled within the current browser instance or false if the remote process | 61 // handled within the current browser instance or false if the remote process |
| 62 // should handle it (i.e., because the current process is shutting down). | 62 // should handle it (i.e., because the current process is shutting down). |
| 63 typedef base::Callback< | 63 typedef base::Callback< |
| 64 bool(const CommandLine& command_line, const FilePath& current_directory)> | 64 bool(const CommandLine& command_line, const FilePath& current_directory)> |
| 65 NotificationCallback; | 65 NotificationCallback; |
| 66 | 66 |
| 67 explicit ProcessSingleton(const FilePath& user_data_dir); | 67 explicit ProcessSingleton(const FilePath& user_data_dir); |
| 68 ~ProcessSingleton(); | 68 ~ProcessSingleton(); |
| 69 | 69 |
| 70 // Notify another process, if available. | |
| 71 // Returns true if another process was found and notified, false if we | |
| 72 // should continue with this process. | |
| 73 // Windows code roughly based on Mozilla. | |
| 74 // | |
| 75 // TODO(brettw): this will not handle all cases. If two process start up too | |
| 76 // close to each other, the Create() might not yet have happened for the | |
| 77 // first one, so this function won't find it. | |
| 78 NotifyResult NotifyOtherProcess(); | |
| 79 | |
| 80 // Notify another process, if available. Otherwise sets ourselves as the | 70 // Notify another process, if available. Otherwise sets ourselves as the |
| 81 // singleton instance and stores the provided callback for notification from | 71 // singleton instance and stores the provided callback for notification from |
| 82 // future processes. Returns PROCESS_NONE if we became the singleton | 72 // future processes. Returns PROCESS_NONE if we became the singleton |
| 83 // instance. | 73 // instance. |
| 84 NotifyResult NotifyOtherProcessOrCreate( | 74 NotifyResult NotifyOtherProcessOrCreate( |
| 85 const NotificationCallback& notification_callback); | 75 const NotificationCallback& notification_callback); |
| 86 | 76 |
| 87 #if defined(OS_LINUX) || defined(OS_OPENBSD) | |
| 88 // Exposed for testing. We use a timeout on Linux, and in tests we want | |
| 89 // this timeout to be short. | |
| 90 NotifyResult NotifyOtherProcessWithTimeout(const CommandLine& command_line, | |
| 91 int timeout_seconds, | |
| 92 bool kill_unresponsive); | |
| 93 NotifyResult NotifyOtherProcessWithTimeoutOrCreate( | |
| 94 const CommandLine& command_line, | |
| 95 const NotificationCallback& notification_callback, | |
| 96 int timeout_seconds); | |
| 97 void OverrideCurrentPidForTesting(base::ProcessId pid); | |
| 98 void OverrideKillCallbackForTesting(const base::Callback<void(int)>& callback) ; | |
| 99 static void DisablePromptForTesting(); | |
| 100 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) | |
| 101 | |
| 102 // Sets ourself up as the singleton instance. Returns true on success. If | |
| 103 // false is returned, we are not the singleton instance and the caller must | |
| 104 // exit. Otherwise, stores the provided callback for notification from | |
| 105 // future processes. | |
| 106 bool Create( | |
| 107 const NotificationCallback& notification_callback); | |
| 108 | |
| 109 // Clear any lock state during shutdown. | 77 // Clear any lock state during shutdown. |
| 110 void Cleanup(); | 78 void Cleanup(); |
| 111 | 79 |
| 112 // Blocks the dispatch of CopyData messages. foreground_window refers | 80 // Blocks the dispatch of CopyData messages. foreground_window refers |
| 113 // to the window that should be set to the foreground if a CopyData message | 81 // to the window that should be set to the foreground if a CopyData message |
| 114 // is received while the ProcessSingleton is locked. | 82 // is received while the ProcessSingleton is locked. |
| 115 void Lock(gfx::NativeWindow foreground_window) { | 83 void Lock(gfx::NativeWindow foreground_window) { |
| 116 DCHECK(CalledOnValidThread()); | 84 DCHECK(CalledOnValidThread()); |
| 117 locked_ = true; | 85 locked_ = true; |
| 118 foreground_window_ = foreground_window; | 86 foreground_window_ = foreground_window; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 130 | 98 |
| 131 bool locked() { | 99 bool locked() { |
| 132 DCHECK(CalledOnValidThread()); | 100 DCHECK(CalledOnValidThread()); |
| 133 return locked_; | 101 return locked_; |
| 134 } | 102 } |
| 135 | 103 |
| 136 #if defined(OS_WIN) | 104 #if defined(OS_WIN) |
| 137 LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | 105 LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); |
| 138 #endif | 106 #endif |
| 139 | 107 |
| 108 #if defined(OS_LINUX) || defined(OS_OPENBSD) | |
| 109 static void DisablePromptForTesting(); | |
| 110 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) | |
| 111 | |
| 112 protected: | |
| 113 // Notify another process, if available. | |
| 114 // Returns true if another process was found and notified, false if we | |
| 115 // should continue with this process. | |
| 116 // Windows code roughly based on Mozilla. | |
| 117 // | |
| 118 // TODO(brettw): this will not handle all cases. If two process start up too | |
|
robertshield
2012/11/30 21:21:52
nit: processes
gab
2012/11/30 21:35:36
Done.
| |
| 119 // close to each other, the Create() might not yet have happened for the | |
| 120 // first one, so this function won't find it. | |
| 121 virtual NotifyResult NotifyOtherProcess(); | |
| 122 | |
| 123 // Sets ourself up as the singleton instance. Returns true on success. If | |
| 124 // false is returned, we are not the singleton instance and the caller must | |
| 125 // exit. Otherwise, stores the provided callback for notification from | |
| 126 // future processes. | |
| 127 virtual bool Create( | |
| 128 const NotificationCallback& notification_callback); | |
| 129 | |
| 130 #if defined(OS_LINUX) || defined(OS_OPENBSD) | |
| 131 // Exposed for testing. We use a timeout on Linux, and in tests we want | |
| 132 // this timeout to be short. | |
| 133 virtual NotifyResult NotifyOtherProcessWithTimeout( | |
| 134 const CommandLine& command_line, | |
| 135 int timeout_seconds, | |
| 136 bool kill_unresponsive); | |
| 137 virtual NotifyResult NotifyOtherProcessWithTimeoutOrCreate( | |
| 138 const CommandLine& command_line, | |
| 139 const NotificationCallback& notification_callback, | |
| 140 int timeout_seconds); | |
| 141 virtual void OverrideCurrentPidForTesting(base::ProcessId pid); | |
| 142 virtual void OverrideKillCallbackForTesting( | |
| 143 const base::Callback<void(int)>& callback); | |
| 144 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) | |
| 145 | |
| 140 private: | 146 private: |
| 141 typedef std::pair<CommandLine::StringVector, FilePath> DelayedStartupMessage; | 147 typedef std::pair<CommandLine::StringVector, FilePath> DelayedStartupMessage; |
| 142 | 148 |
| 143 #if !defined(OS_MACOSX) | 149 #if !defined(OS_MACOSX) |
| 144 // Timeout for the current browser process to respond. 20 seconds should be | 150 // Timeout for the current browser process to respond. 20 seconds should be |
| 145 // enough. It's only used in Windows and Linux implementations. | 151 // enough. It's only used in Windows and Linux implementations. |
| 146 static const int kTimeoutInSeconds = 20; | 152 static const int kTimeoutInSeconds = 20; |
| 147 #endif | 153 #endif |
| 148 | 154 |
| 149 bool locked_; | 155 bool locked_; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 #endif | 216 #endif |
| 211 | 217 |
| 212 // If messages are received in the locked state, the corresponding command | 218 // If messages are received in the locked state, the corresponding command |
| 213 // lines are saved here to be replayed later. | 219 // lines are saved here to be replayed later. |
| 214 std::vector<DelayedStartupMessage> saved_startup_messages_; | 220 std::vector<DelayedStartupMessage> saved_startup_messages_; |
| 215 | 221 |
| 216 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); | 222 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); |
| 217 }; | 223 }; |
| 218 | 224 |
| 219 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ | 225 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ |
| OLD | NEW |