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

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

Issue 981223004: Add test for ProcessSingleton hung rendezvous case. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Gab's remaining comments. Created 5 years, 9 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
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 PROCESS_NOTIFIED, 54 PROCESS_NOTIFIED,
55 PROFILE_IN_USE, 55 PROFILE_IN_USE,
56 LOCK_ERROR, 56 LOCK_ERROR,
57 }; 57 };
58 58
59 // Implement this callback to handle notifications from other processes. The 59 // Implement this callback to handle notifications from other processes. The
60 // callback will receive the command line and directory with which the other 60 // callback will receive the command line and directory with which the other
61 // Chrome process was launched. Return true if the command line will be 61 // Chrome process was launched. Return true if the command line will be
62 // handled within the current browser instance or false if the remote process 62 // handled within the current browser instance or false if the remote process
63 // should handle it (i.e., because the current process is shutting down). 63 // should handle it (i.e., because the current process is shutting down).
64 typedef base::Callback<bool( 64 using NotificationCallback =
65 const base::CommandLine& command_line, 65 base::Callback<bool(const base::CommandLine& command_line,
66 const base::FilePath& current_directory)> NotificationCallback; 66 const base::FilePath& current_directory)>;
67 67
68 ProcessSingleton(const base::FilePath& user_data_dir, 68 ProcessSingleton(const base::FilePath& user_data_dir,
69 const NotificationCallback& notification_callback); 69 const NotificationCallback& notification_callback);
70 ~ProcessSingleton(); 70 ~ProcessSingleton();
71 71
72 // Notify another process, if available. Otherwise sets ourselves as the 72 // Notify another process, if available. Otherwise sets ourselves as the
73 // singleton instance. Returns PROCESS_NONE if we became the singleton 73 // singleton instance. Returns PROCESS_NONE if we became the singleton
74 // instance. Callers are guaranteed to either have notified an existing 74 // instance. Callers are guaranteed to either have notified an existing
75 // process or have grabbed the singleton (unless the profile is locked by an 75 // process or have grabbed the singleton (unless the profile is locked by an
76 // unreachable process). 76 // unreachable process).
77 // TODO(brettw): Make the implementation of this method non-platform-specific 77 // TODO(brettw): Make the implementation of this method non-platform-specific
78 // by making Linux re-use the Windows implementation. 78 // by making Linux re-use the Windows implementation.
79 NotifyResult NotifyOtherProcessOrCreate(); 79 NotifyResult NotifyOtherProcessOrCreate();
80 80
81 // Sets ourself up as the singleton instance. Returns true on success. If 81 // Sets ourself up as the singleton instance. Returns true on success. If
82 // false is returned, we are not the singleton instance and the caller must 82 // false is returned, we are not the singleton instance and the caller must
83 // exit. 83 // exit.
84 // NOTE: Most callers should generally prefer NotifyOtherProcessOrCreate() to 84 // NOTE: Most callers should generally prefer NotifyOtherProcessOrCreate() to
85 // this method, only callers for whom failure is preferred to notifying 85 // this method, only callers for whom failure is preferred to notifying
86 // another process should call this directly. 86 // another process should call this directly.
87 bool Create(); 87 bool Create();
88 88
89 // Clear any lock state during shutdown. 89 // Clear any lock state during shutdown.
90 void Cleanup(); 90 void Cleanup();
91 91
92 #if defined(OS_POSIX) && !defined(OS_ANDROID) 92 #if defined(OS_POSIX) && !defined(OS_ANDROID)
93 static void DisablePromptForTesting(); 93 static void DisablePromptForTesting();
94 #endif 94 #endif
95 #if defined(OS_WIN)
96 // Called to query whether to kill a hung browser process that has visible
97 // windows. Return true to allow killing the hung process.
98 using ShouldKillRemoteProcessCallback = base::Callback<bool()>;
99 void OverrideShouldKillRemoteProcessCallbackForTesting(
100 const ShouldKillRemoteProcessCallback& display_dialog_callback);
101 #endif
95 102
96 protected: 103 protected:
97 // Notify another process, if available. 104 // Notify another process, if available.
98 // Returns true if another process was found and notified, false if we should 105 // Returns true if another process was found and notified, false if we should
99 // continue with the current process. 106 // continue with the current process.
100 // On Windows, Create() has to be called before this. 107 // On Windows, Create() has to be called before this.
101 NotifyResult NotifyOtherProcess(); 108 NotifyResult NotifyOtherProcess();
102 109
103 #if defined(OS_POSIX) && !defined(OS_ANDROID) 110 #if defined(OS_POSIX) && !defined(OS_ANDROID)
104 // Exposed for testing. We use a timeout on Linux, and in tests we want 111 // Exposed for testing. We use a timeout on Linux, and in tests we want
(...skipping 16 matching lines...) Expand all
121 NotificationCallback notification_callback_; // Handler for notifications. 128 NotificationCallback notification_callback_; // Handler for notifications.
122 129
123 #if defined(OS_WIN) 130 #if defined(OS_WIN)
124 bool EscapeVirtualization(const base::FilePath& user_data_dir); 131 bool EscapeVirtualization(const base::FilePath& user_data_dir);
125 132
126 HWND remote_window_; // The HWND_MESSAGE of another browser. 133 HWND remote_window_; // The HWND_MESSAGE of another browser.
127 base::win::MessageWindow window_; // The message-only window. 134 base::win::MessageWindow window_; // The message-only window.
128 bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment. 135 bool is_virtualized_; // Stuck inside Microsoft Softricity VM environment.
129 HANDLE lock_file_; 136 HANDLE lock_file_;
130 base::FilePath user_data_dir_; 137 base::FilePath user_data_dir_;
138 ShouldKillRemoteProcessCallback should_kill_remote_process_callback_;
131 #elif defined(OS_POSIX) && !defined(OS_ANDROID) 139 #elif defined(OS_POSIX) && !defined(OS_ANDROID)
132 // Return true if the given pid is one of our child processes. 140 // Return true if the given pid is one of our child processes.
133 // Assumes that the current pid is the root of all pids of the current 141 // Assumes that the current pid is the root of all pids of the current
134 // instance. 142 // instance.
135 bool IsSameChromeInstance(pid_t pid); 143 bool IsSameChromeInstance(pid_t pid);
136 144
137 // Extract the process's pid from a symbol link path and if it is on 145 // Extract the process's pid from a symbol link path and if it is on
138 // the same host, kill the process, unlink the lock file and return true. 146 // the same host, kill the process, unlink the lock file and return true.
139 // If the process is part of the same chrome instance, unlink the lock file 147 // If the process is part of the same chrome instance, unlink the lock file
140 // and return true without killing it. 148 // and return true without killing it.
(...skipping 25 matching lines...) Expand all
166 // Helper class for linux specific messages. LinuxWatcher is ref counted 174 // Helper class for linux specific messages. LinuxWatcher is ref counted
167 // because it posts messages between threads. 175 // because it posts messages between threads.
168 class LinuxWatcher; 176 class LinuxWatcher;
169 scoped_refptr<LinuxWatcher> watcher_; 177 scoped_refptr<LinuxWatcher> watcher_;
170 #endif 178 #endif
171 179
172 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); 180 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton);
173 }; 181 };
174 182
175 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ 183 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698