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

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

Issue 196413016: Move CommandLine to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | 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 14 matching lines...) Expand all
25 #include "ui/gfx/native_widget_types.h" 25 #include "ui/gfx/native_widget_types.h"
26 26
27 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 27 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
28 #include "base/files/scoped_temp_dir.h" 28 #include "base/files/scoped_temp_dir.h"
29 #endif 29 #endif
30 30
31 #if defined(OS_WIN) 31 #if defined(OS_WIN)
32 #include "base/win/message_window.h" 32 #include "base/win/message_window.h"
33 #endif // defined(OS_WIN) 33 #endif // defined(OS_WIN)
34 34
35 namespace base {
35 class CommandLine; 36 class CommandLine;
37 }
36 38
37 // ProcessSingleton ---------------------------------------------------------- 39 // ProcessSingleton ----------------------------------------------------------
38 // 40 //
39 // This class allows different browser processes to communicate with 41 // This class allows different browser processes to communicate with
40 // each other. It is named according to the user data directory, so 42 // each other. It is named according to the user data directory, so
41 // we can be sure that no more than one copy of the application can be 43 // we can be sure that no more than one copy of the application can be
42 // running at once with a given data directory. 44 // running at once with a given data directory.
43 // 45 //
44 // Implementation notes: 46 // Implementation notes:
45 // - the Windows implementation uses an invisible global message window; 47 // - the Windows implementation uses an invisible global message window;
46 // - the Linux implementation uses a Unix domain socket in the user data dir. 48 // - the Linux implementation uses a Unix domain socket in the user data dir.
47 49
48 class ProcessSingleton : public base::NonThreadSafe { 50 class ProcessSingleton : public base::NonThreadSafe {
49 public: 51 public:
50 enum NotifyResult { 52 enum NotifyResult {
51 PROCESS_NONE, 53 PROCESS_NONE,
52 PROCESS_NOTIFIED, 54 PROCESS_NOTIFIED,
53 PROFILE_IN_USE, 55 PROFILE_IN_USE,
54 LOCK_ERROR, 56 LOCK_ERROR,
55 }; 57 };
56 58
57 // Implement this callback to handle notifications from other processes. The 59 // Implement this callback to handle notifications from other processes. The
58 // 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
59 // 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
60 // 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
61 // 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).
62 typedef base::Callback<bool( 64 typedef base::Callback<bool(
63 const CommandLine& command_line, 65 const base::CommandLine& command_line,
64 const base::FilePath& current_directory)> NotificationCallback; 66 const base::FilePath& current_directory)> NotificationCallback;
65 67
66 ProcessSingleton(const base::FilePath& user_data_dir, 68 ProcessSingleton(const base::FilePath& user_data_dir,
67 const NotificationCallback& notification_callback); 69 const NotificationCallback& notification_callback);
68 ~ProcessSingleton(); 70 ~ProcessSingleton();
69 71
70 // Notify another process, if available. Otherwise sets ourselves as the 72 // Notify another process, if available. Otherwise sets ourselves as the
71 // singleton instance. Returns PROCESS_NONE if we became the singleton 73 // singleton instance. Returns PROCESS_NONE if we became the singleton
72 // instance. Callers are guaranteed to either have notified an existing 74 // instance. Callers are guaranteed to either have notified an existing
73 // 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
(...skipping 20 matching lines...) Expand all
94 protected: 96 protected:
95 // Notify another process, if available. 97 // Notify another process, if available.
96 // Returns true if another process was found and notified, false if we should 98 // Returns true if another process was found and notified, false if we should
97 // continue with the current process. 99 // continue with the current process.
98 // On Windows, Create() has to be called before this. 100 // On Windows, Create() has to be called before this.
99 NotifyResult NotifyOtherProcess(); 101 NotifyResult NotifyOtherProcess();
100 102
101 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) 103 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID)
102 // Exposed for testing. We use a timeout on Linux, and in tests we want 104 // Exposed for testing. We use a timeout on Linux, and in tests we want
103 // this timeout to be short. 105 // this timeout to be short.
104 NotifyResult NotifyOtherProcessWithTimeout(const CommandLine& command_line, 106 NotifyResult NotifyOtherProcessWithTimeout(
105 int timeout_seconds, 107 const base::CommandLine& command_line,
106 bool kill_unresponsive); 108 int timeout_seconds,
109 bool kill_unresponsive);
107 NotifyResult NotifyOtherProcessWithTimeoutOrCreate( 110 NotifyResult NotifyOtherProcessWithTimeoutOrCreate(
108 const CommandLine& command_line, 111 const base::CommandLine& command_line,
109 int timeout_seconds); 112 int timeout_seconds);
110 void OverrideCurrentPidForTesting(base::ProcessId pid); 113 void OverrideCurrentPidForTesting(base::ProcessId pid);
111 void OverrideKillCallbackForTesting( 114 void OverrideKillCallbackForTesting(
112 const base::Callback<void(int)>& callback); 115 const base::Callback<void(int)>& callback);
113 #endif 116 #endif
114 117
115 private: 118 private:
116 #if !defined(OS_MACOSX) 119 #if !defined(OS_MACOSX)
117 // Timeout for the current browser process to respond. 20 seconds should be 120 // Timeout for the current browser process to respond. 20 seconds should be
118 // enough. It's only used in Windows and Linux implementations. 121 // enough. It's only used in Windows and Linux implementations.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // File descriptor associated with the lockfile, valid between 178 // File descriptor associated with the lockfile, valid between
176 // |Create()| and |Cleanup()|. Two instances cannot have a lock on 179 // |Create()| and |Cleanup()|. Two instances cannot have a lock on
177 // the same file at the same time. 180 // the same file at the same time.
178 int lock_fd_; 181 int lock_fd_;
179 #endif 182 #endif
180 183
181 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); 184 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton);
182 }; 185 };
183 186
184 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ 187 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_dialog_cloud.h ('k') | chrome/browser/process_singleton_modal_dialog_lock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698