OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_LOCK_H_ | 5 #ifndef CHROME_BROWSER_PROCESS_SINGLETON_LOCK_H_ |
6 #define CHROME_BROWSER_PROCESS_SINGLETON_LOCK_H_ | 6 #define CHROME_BROWSER_PROCESS_SINGLETON_LOCK_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | |
13 #include "base/command_line.h" | 12 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
15 #include "base/threading/non_thread_safe.h" | 14 #include "base/threading/non_thread_safe.h" |
16 #include "chrome/browser/process_singleton.h" | 15 #include "chrome/browser/process_singleton.h" |
17 | 16 |
| 17 class OperationOutput; |
| 18 |
18 // Implements a ProcessSingleton::NotificationCallback that can queue up | 19 // Implements a ProcessSingleton::NotificationCallback that can queue up |
19 // command-line invocations during startup and execute them when startup | 20 // command-line invocations during startup and execute them when startup |
20 // completes. The object starts in a locked state. |Unlock()| must be called | 21 // completes. The object starts in a locked state. |Unlock()| must be called |
21 // when the process is prepared to handle command-line invocations. | 22 // when the process is prepared to handle command-line invocations. |
22 // | 23 // |
23 // Once unlocked, notifications are forwarded to a wrapped NotificationCallback. | 24 // Once unlocked, notifications are forwarded to a wrapped NotificationCallback. |
24 class ProcessSingletonLock : public base::NonThreadSafe { | 25 class ProcessSingletonLock : public base::NonThreadSafe { |
25 public: | 26 public: |
26 explicit ProcessSingletonLock( | 27 typedef base::Callback<bool(const CommandLine& command_line, |
27 const ProcessSingleton::NotificationCallback& original_callback); | 28 const base::FilePath& current_directory, |
| 29 scoped_ptr<OperationOutput> operation_output)> |
| 30 OperationCallback; |
| 31 |
| 32 explicit ProcessSingletonLock(const OperationCallback& operation_callback); |
28 ~ProcessSingletonLock(); | 33 ~ProcessSingletonLock(); |
29 | 34 |
30 // Returns the callback that should be supplied to ProcessSingleton. | 35 // Returns the callback that should be supplied to ProcessSingleton. |
31 // The callback is only valid during the lifetime of the ProcessSingletonLock | 36 // The callback is only valid during the lifetime of the ProcessSingletonLock |
32 // instance. | 37 // instance. |
33 ProcessSingleton::NotificationCallback AsNotificationCallback(); | 38 ProcessSingleton::NotificationCallback AsNotificationCallback(); |
34 | 39 |
35 // Executes previously queued command-line invocations and allows future | 40 // Executes previously queued command-line invocations and allows future |
36 // invocations to be executed immediately. | 41 // invocations to be executed immediately. |
37 void Unlock(); | 42 void Unlock(); |
38 | 43 |
39 bool locked() { return locked_; } | 44 bool locked() { return locked_; } |
40 | 45 |
41 private: | 46 private: |
42 typedef std::pair<CommandLine::StringVector, base::FilePath> | 47 struct DelayedStartupMessage { |
43 DelayedStartupMessage; | 48 DelayedStartupMessage(const CommandLine::StringVector& argv, |
| 49 const base::FilePath& current_directory, |
| 50 OperationOutput* operation_output); |
| 51 ~DelayedStartupMessage(); |
| 52 |
| 53 CommandLine::StringVector argv_; |
| 54 base::FilePath current_directory_; |
| 55 OperationOutput* operation_output_; |
| 56 }; |
44 | 57 |
45 bool NotificationCallbackImpl(const CommandLine& command_line, | 58 bool NotificationCallbackImpl(const CommandLine& command_line, |
46 const base::FilePath& current_directory); | 59 const base::FilePath& current_directory); |
47 | 60 |
48 bool locked_; | 61 bool locked_; |
49 std::vector<DelayedStartupMessage> saved_startup_messages_; | 62 std::vector<DelayedStartupMessage> saved_startup_messages_; |
50 ProcessSingleton::NotificationCallback original_callback_; | 63 OperationCallback operation_callback_; |
51 | 64 |
52 DISALLOW_COPY_AND_ASSIGN(ProcessSingletonLock); | 65 DISALLOW_COPY_AND_ASSIGN(ProcessSingletonLock); |
53 }; | 66 }; |
54 | 67 |
55 #endif // CHROME_BROWSER_PROCESS_SINGLETON_LOCK_H_ | 68 #endif // CHROME_BROWSER_PROCESS_SINGLETON_LOCK_H_ |
OLD | NEW |