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

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

Issue 11415237: Move many ProcessSingleton methods to "protected" visibility as an upcoming refactoring of ProcessS… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase on master 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)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 #if defined(OS_WIN) 77 #if defined(OS_WIN)
103 // Used in specific cases to let us know that there is an existing instance 78 // Used in specific cases to let us know that there is an existing instance
104 // of Chrome running with this profile. In general, you should not use this 79 // of Chrome running with this profile. In general, you should not use this
105 // function. Instead consider using NotifyOtherProcessOrCreate(). 80 // function. Instead consider using NotifyOtherProcessOrCreate().
106 // For non profile-specific method, use 81 // For non profile-specific method, use
107 // browser_util::IsBrowserAlreadyRunning(). 82 // browser_util::IsBrowserAlreadyRunning().
108 bool FoundOtherProcessWindow() const { 83 bool FoundOtherProcessWindow() const {
109 return (NULL != remote_window_); 84 return (NULL != remote_window_);
110 } 85 }
111 #endif // defined(OS_WIN) 86 #endif // defined(OS_WIN)
112 87
113 // Sets ourself up as the singleton instance. Returns true on success. If
114 // false is returned, we are not the singleton instance and the caller must
115 // exit. Otherwise, stores the provided callback for notification from
116 // future processes.
117 bool Create(
118 const NotificationCallback& notification_callback);
119
120 // Clear any lock state during shutdown. 88 // Clear any lock state during shutdown.
121 void Cleanup(); 89 void Cleanup();
122 90
123 // Blocks the dispatch of CopyData messages. foreground_window refers 91 // Blocks the dispatch of CopyData messages. foreground_window refers
124 // to the window that should be set to the foreground if a CopyData message 92 // to the window that should be set to the foreground if a CopyData message
125 // is received while the ProcessSingleton is locked. 93 // is received while the ProcessSingleton is locked.
126 void Lock(gfx::NativeWindow foreground_window) { 94 void Lock(gfx::NativeWindow foreground_window) {
127 DCHECK(CalledOnValidThread()); 95 DCHECK(CalledOnValidThread());
128 locked_ = true; 96 locked_ = true;
129 foreground_window_ = foreground_window; 97 foreground_window_ = foreground_window;
(...skipping 11 matching lines...) Expand all
141 109
142 bool locked() { 110 bool locked() {
143 DCHECK(CalledOnValidThread()); 111 DCHECK(CalledOnValidThread());
144 return locked_; 112 return locked_;
145 } 113 }
146 114
147 #if defined(OS_WIN) 115 #if defined(OS_WIN)
148 LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); 116 LRESULT WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
149 #endif 117 #endif
150 118
119 #if defined(OS_LINUX) || defined(OS_OPENBSD)
120 static void DisablePromptForTesting();
121 #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
122
123 protected:
124 // Notify another process, if available.
125 // Returns true if another process was found and notified, false if we
126 // should continue with this process.
127 // Windows code roughly based on Mozilla.
128 //
129 // TODO(brettw): this will not handle all cases. If two processes start up too
130 // close to each other, the Create() might not yet have happened for the
131 // first one, so this function won't find it.
132 virtual NotifyResult NotifyOtherProcess();
133
134 // Sets ourself up as the singleton instance. Returns true on success. If
135 // false is returned, we are not the singleton instance and the caller must
136 // exit. Otherwise, stores the provided callback for notification from
137 // future processes.
138 virtual bool Create(
139 const NotificationCallback& notification_callback);
140
141 #if defined(OS_LINUX) || defined(OS_OPENBSD)
142 // Exposed for testing. We use a timeout on Linux, and in tests we want
143 // this timeout to be short.
144 virtual NotifyResult NotifyOtherProcessWithTimeout(
145 const CommandLine& command_line,
146 int timeout_seconds,
147 bool kill_unresponsive);
148 virtual NotifyResult NotifyOtherProcessWithTimeoutOrCreate(
149 const CommandLine& command_line,
150 const NotificationCallback& notification_callback,
151 int timeout_seconds);
152 virtual void OverrideCurrentPidForTesting(base::ProcessId pid);
153 virtual void OverrideKillCallbackForTesting(
154 const base::Callback<void(int)>& callback);
155 #endif // defined(OS_LINUX) || defined(OS_OPENBSD)
156
151 private: 157 private:
152 typedef std::pair<CommandLine::StringVector, FilePath> DelayedStartupMessage; 158 typedef std::pair<CommandLine::StringVector, FilePath> DelayedStartupMessage;
153 159
154 #if !defined(OS_MACOSX) 160 #if !defined(OS_MACOSX)
155 // Timeout for the current browser process to respond. 20 seconds should be 161 // Timeout for the current browser process to respond. 20 seconds should be
156 // enough. It's only used in Windows and Linux implementations. 162 // enough. It's only used in Windows and Linux implementations.
157 static const int kTimeoutInSeconds = 20; 163 static const int kTimeoutInSeconds = 20;
158 #endif 164 #endif
159 165
160 bool locked_; 166 bool locked_;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 #endif 227 #endif
222 228
223 // If messages are received in the locked state, the corresponding command 229 // If messages are received in the locked state, the corresponding command
224 // lines are saved here to be replayed later. 230 // lines are saved here to be replayed later.
225 std::vector<DelayedStartupMessage> saved_startup_messages_; 231 std::vector<DelayedStartupMessage> saved_startup_messages_;
226 232
227 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); 233 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton);
228 }; 234 };
229 235
230 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ 236 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/process_singleton_linux.cc » ('j') | chrome/browser/process_singleton_linux_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698