[M120][Tizen][Onscreen] Fix build errors for TV profile
[platform/framework/web/chromium-efl.git] / chrome / browser / process_singleton_startup_lock.cc
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.
4
5 #include "chrome/browser/process_singleton_startup_lock.h"
6
7 #include "base/check_op.h"
8 #include "base/functional/bind.h"
9
10 ProcessSingletonStartupLock::ProcessSingletonStartupLock(
11     const ProcessSingleton::NotificationCallback& original_callback)
12     : locked_(true),
13       original_callback_(original_callback) {}
14
15 ProcessSingletonStartupLock::~ProcessSingletonStartupLock() {
16   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
17 }
18
19 ProcessSingleton::NotificationCallback
20 ProcessSingletonStartupLock::AsNotificationCallback() {
21   return base::BindRepeating(
22       &ProcessSingletonStartupLock::NotificationCallbackImpl,
23       base::Unretained(this));
24 }
25
26 void ProcessSingletonStartupLock::Unlock() {
27   DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
28   locked_ = false;
29
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())
37       continue;
38     original_callback_.Run(base::CommandLine(it->first), it->second);
39     replayed_messages.insert(*it);
40   }
41   saved_startup_messages_.clear();
42 }
43
44 bool ProcessSingletonStartupLock::NotificationCallbackImpl(
45     const base::CommandLine& command_line,
46     const base::FilePath& current_directory) {
47   if (locked_) {
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));
52     return true;
53   } else {
54     return original_callback_.Run(command_line, current_directory);
55   }
56 }