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

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

Issue 11099053: Refactor ProcessSingleton to allow a Desktop process to activate Metro Chrome cleanly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge up to r170957 Created 8 years 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)
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/file_path.h" 20 #include "base/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_POSIX)
28 #include "base/file_path.h"
29 #endif // defined(OS_POSIX)
30
31 #if defined(OS_LINUX) || defined(OS_OPENBSD) 27 #if defined(OS_LINUX) || defined(OS_OPENBSD)
32 #include "base/files/scoped_temp_dir.h" 28 #include "base/files/scoped_temp_dir.h"
33 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) 29 #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
34 30
35 class CommandLine; 31 class CommandLine;
36 class FilePath;
37 32
38 // ProcessSingleton ---------------------------------------------------------- 33 // ProcessSingleton ----------------------------------------------------------
39 // 34 //
40 // This class allows different browser processes to communicate with 35 // This class allows different browser processes to communicate with
41 // 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
42 // 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
43 // running at once with a given data directory. 38 // running at once with a given data directory.
44 // 39 //
45 // Implementation notes: 40 // Implementation notes:
46 // - the Windows implementation uses an invisible global message window; 41 // - the Windows implementation uses an invisible global message window;
(...skipping 16 matching lines...) Expand all
63 typedef base::Callback< 58 typedef base::Callback<
64 bool(const CommandLine& command_line, const FilePath& current_directory)> 59 bool(const CommandLine& command_line, const FilePath& current_directory)>
65 NotificationCallback; 60 NotificationCallback;
66 61
67 explicit ProcessSingleton(const FilePath& user_data_dir); 62 explicit ProcessSingleton(const FilePath& user_data_dir);
68 ~ProcessSingleton(); 63 ~ProcessSingleton();
69 64
70 // Notify another process, if available. Otherwise sets ourselves as the 65 // Notify another process, if available. Otherwise sets ourselves as the
71 // singleton instance and stores the provided callback for notification from 66 // singleton instance and stores the provided callback for notification from
72 // future processes. Returns PROCESS_NONE if we became the singleton 67 // future processes. Returns PROCESS_NONE if we became the singleton
73 // instance. 68 // instance. Callers are guaranteed to either have notified an existing
69 // process or have grabbed the singleton (unless the profile is locked by an
70 // unreachable process).
71 // TODO(brettw): Make the implementation of this method non-platform-specific
72 // by making Linux re-use the Windows implementation.
74 NotifyResult NotifyOtherProcessOrCreate( 73 NotifyResult NotifyOtherProcessOrCreate(
75 const NotificationCallback& notification_callback); 74 const NotificationCallback& notification_callback);
76 75
77 // Sets ourself up as the singleton instance. Returns true on success. If 76 // Sets ourself up as the singleton instance. Returns true on success. If
78 // 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
79 // exit. Otherwise, stores the provided callback for notification from 78 // exit. Otherwise, stores the provided callback for notification from
80 // future processes. 79 // future processes.
81 // NOTE: Most callers should generally prefer NotifyOtherProcessOrCreate() to 80 // NOTE: Most callers should generally prefer NotifyOtherProcessOrCreate() to
82 // this method, only callers for whom failure is prefered to notifying another 81 // this method, only callers for whom failure is prefered to notifying another
83 // process should call this directly. 82 // process should call this directly.
(...skipping 29 matching lines...) Expand all
113 #if defined(OS_WIN) 112 #if defined(OS_WIN)
114 LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); 113 LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
115 #endif 114 #endif
116 115
117 #if defined(OS_LINUX) || defined(OS_OPENBSD) 116 #if defined(OS_LINUX) || defined(OS_OPENBSD)
118 static void DisablePromptForTesting(); 117 static void DisablePromptForTesting();
119 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) 118 #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
120 119
121 protected: 120 protected:
122 // Notify another process, if available. 121 // Notify another process, if available.
123 // Returns true if another process was found and notified, false if we 122 // Returns true if another process was found and notified, false if we should
124 // should continue with this process. 123 // continue with the current process.
125 // Windows code roughly based on Mozilla. 124 // On Windows, Create() has to be called before this.
126 //
127 // TODO(brettw): this will not handle all cases. If two processes start up too
128 // close to each other, the Create() might not yet have happened for the
129 // first one, so this function won't find it.
130 NotifyResult NotifyOtherProcess(); 125 NotifyResult NotifyOtherProcess();
131 126
132 #if defined(OS_LINUX) || defined(OS_OPENBSD) 127 #if defined(OS_LINUX) || defined(OS_OPENBSD)
133 // Exposed for testing. We use a timeout on Linux, and in tests we want 128 // Exposed for testing. We use a timeout on Linux, and in tests we want
134 // this timeout to be short. 129 // this timeout to be short.
135 NotifyResult NotifyOtherProcessWithTimeout(const CommandLine& command_line, 130 NotifyResult NotifyOtherProcessWithTimeout(const CommandLine& command_line,
136 int timeout_seconds, 131 int timeout_seconds,
137 bool kill_unresponsive); 132 bool kill_unresponsive);
138 NotifyResult NotifyOtherProcessWithTimeoutOrCreate( 133 NotifyResult NotifyOtherProcessWithTimeoutOrCreate(
139 const CommandLine& command_line, 134 const CommandLine& command_line,
(...skipping 20 matching lines...) Expand all
160 #if defined(OS_WIN) 155 #if defined(OS_WIN)
161 // This ugly behemoth handles startup commands sent from another process. 156 // This ugly behemoth handles startup commands sent from another process.
162 LRESULT OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds); 157 LRESULT OnCopyData(HWND hwnd, const COPYDATASTRUCT* cds);
163 158
164 bool EscapeVirtualization(const FilePath& user_data_dir); 159 bool EscapeVirtualization(const FilePath& user_data_dir);
165 160
166 HWND remote_window_; // The HWND_MESSAGE of another browser. 161 HWND remote_window_; // The HWND_MESSAGE of another browser.
167 HWND window_; // The HWND_MESSAGE window. 162 HWND window_; // The HWND_MESSAGE window.
168 bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment. 163 bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment.
169 HANDLE lock_file_; 164 HANDLE lock_file_;
165 FilePath user_data_dir_;
170 #elif defined(OS_LINUX) || defined(OS_OPENBSD) 166 #elif defined(OS_LINUX) || defined(OS_OPENBSD)
171 // Return true if the given pid is one of our child processes. 167 // Return true if the given pid is one of our child processes.
172 // Assumes that the current pid is the root of all pids of the current 168 // Assumes that the current pid is the root of all pids of the current
173 // instance. 169 // instance.
174 bool IsSameChromeInstance(pid_t pid); 170 bool IsSameChromeInstance(pid_t pid);
175 171
176 // Extract the process's pid from a symbol link path and if it is on 172 // Extract the process's pid from a symbol link path and if it is on
177 // the same host, kill the process, unlink the lock file and return true. 173 // the same host, kill the process, unlink the lock file and return true.
178 // If the process is part of the same chrome instance, unlink the lock file 174 // If the process is part of the same chrome instance, unlink the lock file
179 // and return true without killing it. 175 // and return true without killing it.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 #endif 213 #endif
218 214
219 // If messages are received in the locked state, the corresponding command 215 // If messages are received in the locked state, the corresponding command
220 // lines are saved here to be replayed later. 216 // lines are saved here to be replayed later.
221 std::vector<DelayedStartupMessage> saved_startup_messages_; 217 std::vector<DelayedStartupMessage> saved_startup_messages_;
222 218
223 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); 219 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton);
224 }; 220 };
225 221
226 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ 222 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/process_singleton_win.cc » ('j') | chrome/browser/process_singleton_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698