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