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 #include "chrome/browser/process_singleton_startup_lock.h"
7 #include "base/check_op.h"
8 #include "base/functional/bind.h"
10 ProcessSingletonStartupLock::ProcessSingletonStartupLock(
11 const ProcessSingleton::NotificationCallback& original_callback)
13 original_callback_(original_callback) {}
15 ProcessSingletonStartupLock::~ProcessSingletonStartupLock() {
16 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
19 ProcessSingleton::NotificationCallback
20 ProcessSingletonStartupLock::AsNotificationCallback() {
21 return base::BindRepeating(
22 &ProcessSingletonStartupLock::NotificationCallbackImpl,
23 base::Unretained(this));
26 void ProcessSingletonStartupLock::Unlock() {
27 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
30 // Replay the command lines of the messages which were received while the
31 // ProcessSingleton was locked. Only replay each message once.
32 std::set<DelayedStartupMessage> replayed_messages;
33 for (std::vector<DelayedStartupMessage>::const_iterator it =
34 saved_startup_messages_.begin();
35 it != saved_startup_messages_.end(); ++it) {
36 if (replayed_messages.find(*it) != replayed_messages.end())
38 original_callback_.Run(base::CommandLine(it->first), it->second);
39 replayed_messages.insert(*it);
41 saved_startup_messages_.clear();
44 bool ProcessSingletonStartupLock::NotificationCallbackImpl(
45 const base::CommandLine& command_line,
46 const base::FilePath& current_directory) {
48 // If locked, it means we are not ready to process this message because
49 // we are probably in a first run critical phase.
50 saved_startup_messages_.push_back(
51 std::make_pair(command_line.argv(), current_directory));
54 return original_callback_.Run(command_line, current_directory);