OLD | NEW |
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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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< | 64 typedef base::Callback< |
65 bool(const CommandLine& command_line, const FilePath& current_directory)> | 65 bool(const CommandLine& command_line, const FilePath& current_directory)> |
66 NotificationCallback; | 66 NotificationCallback; |
67 | 67 |
68 explicit ProcessSingleton(const FilePath& user_data_dir); | 68 explicit ProcessSingleton(const FilePath& user_data_dir); |
69 ~ProcessSingleton(); | 69 virtual ~ProcessSingleton(); |
70 | 70 |
71 // Notify another process, if available. | 71 // Notify another process, if available. |
72 // Returns true if another process was found and notified, false if we | 72 // Returns true if another process was found and notified, false if we |
73 // should continue with this process. | 73 // should continue with this process. |
74 // Windows code roughly based on Mozilla. | 74 // Windows code roughly based on Mozilla. |
75 // | 75 // |
76 // TODO(brettw): this will not handle all cases. If two process start up too | 76 // TODO(brettw): this will not handle all cases. If two process start up too |
77 // close to each other, the Create() might not yet have happened for the | 77 // close to each other, the Create() might not yet have happened for the |
78 // first one, so this function won't find it. | 78 // first one, so this function won't find it. |
79 NotifyResult NotifyOtherProcess(); | 79 NotifyResult NotifyOtherProcess(); |
80 | 80 |
81 // Notify another process, if available. Otherwise sets ourselves as the | 81 // Notify another process, if available. Otherwise sets ourselves as the |
82 // singleton instance and stores the provided callback for notification from | 82 // singleton instance and stores the provided callback for notification from |
83 // future processes. Returns PROCESS_NONE if we became the singleton | 83 // future processes. Returns PROCESS_NONE if we became the singleton |
84 // instance. | 84 // instance. |
85 NotifyResult NotifyOtherProcessOrCreate( | 85 virtual NotifyResult NotifyOtherProcessOrCreate( |
86 const NotificationCallback& notification_callback); | 86 const NotificationCallback& notification_callback); |
87 | 87 |
88 #if defined(OS_LINUX) || defined(OS_OPENBSD) | 88 #if defined(OS_LINUX) || defined(OS_OPENBSD) |
89 // Exposed for testing. We use a timeout on Linux, and in tests we want | 89 // Exposed for testing. We use a timeout on Linux, and in tests we want |
90 // this timeout to be short. | 90 // this timeout to be short. |
91 NotifyResult NotifyOtherProcessWithTimeout(const CommandLine& command_line, | 91 NotifyResult NotifyOtherProcessWithTimeout(const CommandLine& command_line, |
92 int timeout_seconds, | 92 int timeout_seconds, |
93 bool kill_unresponsive); | 93 bool kill_unresponsive); |
94 NotifyResult NotifyOtherProcessWithTimeoutOrCreate( | 94 NotifyResult NotifyOtherProcessWithTimeoutOrCreate( |
95 const CommandLine& command_line, | 95 const CommandLine& command_line, |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 #endif | 221 #endif |
222 | 222 |
223 // If messages are received in the locked state, the corresponding command | 223 // If messages are received in the locked state, the corresponding command |
224 // lines are saved here to be replayed later. | 224 // lines are saved here to be replayed later. |
225 std::vector<DelayedStartupMessage> saved_startup_messages_; | 225 std::vector<DelayedStartupMessage> saved_startup_messages_; |
226 | 226 |
227 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); | 227 DISALLOW_COPY_AND_ASSIGN(ProcessSingleton); |
228 }; | 228 }; |
229 | 229 |
230 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ | 230 #endif // CHROME_BROWSER_PROCESS_SINGLETON_H_ |
OLD | NEW |