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