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

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

Issue 12096114: Extract locking behaviour from ProcessSingleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Restrict chrome_process_singleton_unittest to WIN for now. Created 7 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)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // false is returned, we are not the singleton instance and the caller must 77 // false is returned, we are not the singleton instance and the caller must
78 // exit. 78 // exit.
79 // NOTE: Most callers should generally prefer NotifyOtherProcessOrCreate() to 79 // NOTE: Most callers should generally prefer NotifyOtherProcessOrCreate() to
80 // this method, only callers for whom failure is prefered to notifying another 80 // this method, only callers for whom failure is prefered to notifying another
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 // Blocks the dispatch of CopyData messages. foreground_window refers
88 // to the window that should be set to the foreground if a CopyData message
89 // is received while the ProcessSingleton is locked.
90 void Lock(gfx::NativeWindow foreground_window) {
91 DCHECK(CalledOnValidThread());
92 locked_ = true;
93 foreground_window_ = foreground_window;
94 }
95
96 // Changes the foreground window without changing the locked state.
97 void SetActiveModalDialog(gfx::NativeWindow foreground_window) {
98 DCHECK(CalledOnValidThread());
99 foreground_window_ = foreground_window;
100 }
101
102 // Allows the dispatch of CopyData messages and replays the messages which
103 // were received when the ProcessSingleton was locked.
104 void Unlock();
105
106 bool locked() {
107 DCHECK(CalledOnValidThread());
108 return locked_;
109 }
110
111 #if defined(OS_WIN) 87 #if defined(OS_WIN)
112 LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); 88 LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
113 #endif 89 #endif
114 90
115 #if defined(OS_LINUX) || defined(OS_OPENBSD) 91 #if defined(OS_LINUX) || defined(OS_OPENBSD)
116 static void DisablePromptForTesting(); 92 static void DisablePromptForTesting();
117 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) 93 #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
118 94
119 protected: 95 protected:
120 // Notify another process, if available. 96 // Notify another process, if available.
(...skipping 10 matching lines...) Expand all
131 bool kill_unresponsive); 107 bool kill_unresponsive);
132 NotifyResult NotifyOtherProcessWithTimeoutOrCreate( 108 NotifyResult NotifyOtherProcessWithTimeoutOrCreate(
133 const CommandLine& command_line, 109 const CommandLine& command_line,
134 int timeout_seconds); 110 int timeout_seconds);
135 void OverrideCurrentPidForTesting(base::ProcessId pid); 111 void OverrideCurrentPidForTesting(base::ProcessId pid);
136 void OverrideKillCallbackForTesting( 112 void OverrideKillCallbackForTesting(
137 const base::Callback<void(int)>& callback); 113 const base::Callback<void(int)>& callback);
138 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) 114 #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
139 115
140 private: 116 private:
141 typedef std::pair<CommandLine::StringVector,
142 base::FilePath> DelayedStartupMessage;
143
144 #if !defined(OS_MACOSX) 117 #if !defined(OS_MACOSX)
145 // 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
146 // enough. It's only used in Windows and Linux implementations. 119 // enough. It's only used in Windows and Linux implementations.
147 static const int kTimeoutInSeconds = 20; 120 static const int kTimeoutInSeconds = 20;
148 #endif 121 #endif
149 122
150 bool locked_;
151 gfx::NativeWindow foreground_window_;
152 NotificationCallback notification_callback_; // Handler for notifications. 123 NotificationCallback notification_callback_; // Handler for notifications.
153 124
154 #if defined(OS_WIN) 125 #if defined(OS_WIN)
155 // This ugly behemoth handles startup commands sent from another process. 126 // This ugly behemoth handles startup commands sent from another process.
156 LRESULT OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds); 127 LRESULT OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds);
157 128
158 bool EscapeVirtualization(const base::FilePath& user_data_dir); 129 bool EscapeVirtualization(const base::FilePath& user_data_dir);
159 130
160 virtual void DoSetForegroundWindow(HWND target_window);
161
162 HWND remote_window_; // The HWND_MESSAGE of another browser. 131 HWND remote_window_; // The HWND_MESSAGE of another browser.
163 HWND window_; // The HWND_MESSAGE window. 132 HWND window_; // The HWND_MESSAGE window.
164 bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment. 133 bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment.
165 HANDLE lock_file_; 134 HANDLE lock_file_;
166 base::FilePath user_data_dir_; 135 base::FilePath user_data_dir_;
167 #elif defined(OS_LINUX) || defined(OS_OPENBSD) 136 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
168 // 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.
169 // 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
170 // instance. 139 // instance.
171 bool IsSameChromeInstance(pid_t pid); 140 bool IsSameChromeInstance(pid_t pid);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 #elif defined(OS_MACOSX) 175 #elif defined(OS_MACOSX)
207 // Path in file system to the lock. 176 // Path in file system to the lock.
208 base::FilePath lock_path_; 177 base::FilePath lock_path_;
209 178
210 // File descriptor associated with the lockfile, valid between 179 // File descriptor associated with the lockfile, valid between
211 // |Create()| and |Cleanup()|. Two instances cannot have a lock on 180 // |Create()| and |Cleanup()|. Two instances cannot have a lock on
212 // the same file at the same time. 181 // the same file at the same time.
213 int lock_fd_; 182 int lock_fd_;
214 #endif 183 #endif
215 184
216 // If messages are received in the locked state, the corresponding command
217 // lines are saved here to be replayed later.
218 std::vector<DelayedStartupMessage> saved_startup_messages_;
219
220 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); 185 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton);
221 }; 186 };
222 187
223 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ 188 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698