1 // Copyright 2013 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_PROCESS_SINGLETON_STARTUP_LOCK_H_
6 #define CHROME_BROWSER_PROCESS_SINGLETON_STARTUP_LOCK_H_
12 #include "base/command_line.h"
13 #include "base/files/file_path.h"
14 #include "base/sequence_checker.h"
15 #include "chrome/browser/process_singleton.h"
17 // Provides a ProcessSingleton::NotificationCallback that can queue up
18 // command-line invocations during startup and execute them when startup
21 // The object starts in a locked state. |Unlock()| must be called
22 // when the process is prepared to handle command-line invocations.
24 // Once unlocked, notifications are forwarded to a wrapped NotificationCallback.
25 class ProcessSingletonStartupLock {
27 explicit ProcessSingletonStartupLock(
28 const ProcessSingleton::NotificationCallback& original_callback);
30 ProcessSingletonStartupLock(const ProcessSingletonStartupLock&) = delete;
31 ProcessSingletonStartupLock& operator=(const ProcessSingletonStartupLock&) =
34 ~ProcessSingletonStartupLock();
36 // Returns the ProcessSingleton::NotificationCallback.
37 // The callback is only valid during the lifetime of the
38 // ProcessSingletonStartupLock instance.
39 ProcessSingleton::NotificationCallback AsNotificationCallback();
41 // Executes previously queued command-line invocations and allows future
42 // invocations to be executed immediately.
45 bool locked() { return locked_; }
48 typedef std::pair<base::CommandLine::StringVector, base::FilePath>
49 DelayedStartupMessage;
51 bool NotificationCallbackImpl(const base::CommandLine& command_line,
52 const base::FilePath& current_directory);
55 std::vector<DelayedStartupMessage> saved_startup_messages_;
56 ProcessSingleton::NotificationCallback original_callback_;
58 SEQUENCE_CHECKER(sequence_checker_);
61 #endif // CHROME_BROWSER_PROCESS_SINGLETON_STARTUP_LOCK_H_