Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Side by Side Diff: chrome/browser/process_singleton_lock.cc

Issue 12096114: Extract locking behaviour from ProcessSingleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: missed merge. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/process_singleton_lock.h"
6
7 #include "base/bind.h"
8 #include "base/logging.h"
9
10 ProcessSingletonLock::ProcessSingletonLock(
11 const ProcessSingleton::NotificationCallback& original_callback)
12 : locked_(true),
13 original_callback_(original_callback) {}
14
15 ProcessSingletonLock::~ProcessSingletonLock() {}
16
17 ProcessSingleton::NotificationCallback
18 ProcessSingletonLock::AsNotificationCallback() {
gab 2013/03/27 18:03:26 nit: indent 4 spaces
erikwright (departed) 2013/03/28 03:16:34 I believe the current incarnation to be correct pe
grt (UTC plus 2) 2013/04/04 15:17:18 @gab's right: 4-space indent here; see https://gro
19 return base::Bind(&ProcessSingletonLock::NotificationCallbackImpl,
20 base::Unretained(this));
21 }
22
23 void ProcessSingletonLock::Unlock() {
24 DCHECK(CalledOnValidThread());
25 locked_ = false;
26
27 // Replay the command lines of the messages which were received while the
28 // ProcessSingleton was locked. Only replay each message once.
29 std::set<DelayedStartupMessage> replayed_messages;
30 for (std::vector<DelayedStartupMessage>::const_iterator it =
31 saved_startup_messages_.begin();
32 it != saved_startup_messages_.end(); ++it) {
33 if (replayed_messages.find(*it) !=
34 replayed_messages.end())
gab 2013/03/27 18:03:26 nit: indent 4 more spaces.
erikwright (departed) 2013/03/28 03:16:34 n/a.
35 continue;
36 original_callback_.Run(CommandLine(it->first), it->second);
37 replayed_messages.insert(*it);
38 }
39 saved_startup_messages_.clear();
40 }
41
42 bool ProcessSingletonLock::NotificationCallbackImpl(
43 const CommandLine& command_line,
44 const base::FilePath& current_directory) {
45 if (locked_) {
46 // If locked, it means we are not ready to process this message because
47 // we are probably in a first run critical phase.
48 saved_startup_messages_.push_back(
49 std::make_pair(command_line.argv(), current_directory));
50 return true;
51 } else {
52 return original_callback_.Run(command_line, current_directory);
53 }
54 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698