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

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

Issue 12674028: Report text output and exit code for command-line operations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Line endings. 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
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_lock.h" 5 #include "chrome/browser/process_singleton_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 #include "chrome/browser/operation_output.h"
9 10
10 ProcessSingletonLock::ProcessSingletonLock( 11 ProcessSingletonLock::ProcessSingletonLock(
11 const ProcessSingleton::NotificationCallback& original_callback) 12 const OperationCallback& operation_callback)
12 : locked_(true), 13 : locked_(true),
13 original_callback_(original_callback) {} 14 operation_callback_(operation_callback) {}
14 15
15 ProcessSingletonLock::~ProcessSingletonLock() {} 16 ProcessSingletonLock::~ProcessSingletonLock() {
17 for (std::vector<DelayedStartupMessage>::const_iterator it =
18 saved_startup_messages_.begin();
19 it != saved_startup_messages_.end(); ++it) {
20 if (it->operation_output_)
21 delete it->operation_output_;
22 }
23 }
16 24
17 ProcessSingleton::NotificationCallback 25 ProcessSingleton::NotificationCallback
18 ProcessSingletonLock::AsNotificationCallback() { 26 ProcessSingletonLock::AsNotificationCallback() {
19 return base::Bind(&ProcessSingletonLock::NotificationCallbackImpl, 27 return base::Bind(&ProcessSingletonLock::NotificationCallbackImpl,
20 base::Unretained(this)); 28 base::Unretained(this));
21 } 29 }
22 30
23 void ProcessSingletonLock::Unlock() { 31 void ProcessSingletonLock::Unlock() {
24 DCHECK(CalledOnValidThread()); 32 DCHECK(CalledOnValidThread());
25 locked_ = false; 33 locked_ = false;
26 34
27 // Replay the command lines of the messages which were received while the 35 // Replay the command lines of the messages which were received while the
28 // ProcessSingleton was locked. Only replay each message once. 36 // ProcessSingleton was locked. Only replay each message once.
29 std::set<DelayedStartupMessage> replayed_messages; 37 std::set<std::pair<CommandLine::StringVector,
38 base::FilePath> > replayed_messages;
30 for (std::vector<DelayedStartupMessage>::const_iterator it = 39 for (std::vector<DelayedStartupMessage>::const_iterator it =
31 saved_startup_messages_.begin(); 40 saved_startup_messages_.begin();
32 it != saved_startup_messages_.end(); ++it) { 41 it != saved_startup_messages_.end(); ++it) {
33 if (replayed_messages.find(*it) != 42 scoped_ptr<OperationOutput> operation_output(it->operation_output_);
34 replayed_messages.end()) 43 std::pair<CommandLine::StringVector, base::FilePath> pair(
44 it->argv_, it->current_directory_);
45 if (replayed_messages.find(pair) != replayed_messages.end())
35 continue; 46 continue;
36 original_callback_.Run(CommandLine(it->first), it->second); 47 operation_callback_.Run(CommandLine(it->argv_),
37 replayed_messages.insert(*it); 48 it->current_directory_,
49 operation_output.Pass());
50 replayed_messages.insert(pair);
38 } 51 }
39 saved_startup_messages_.clear(); 52 saved_startup_messages_.clear();
40 } 53 }
41 54
42 bool ProcessSingletonLock::NotificationCallbackImpl( 55 bool ProcessSingletonLock::NotificationCallbackImpl(
43 const CommandLine& command_line, 56 const CommandLine& command_line,
44 const base::FilePath& current_directory) { 57 const base::FilePath& current_directory) {
58 scoped_ptr<OperationOutput> operation_output =
59 OperationOutput::Create(command_line);
60
45 if (locked_) { 61 if (locked_) {
46 // If locked, it means we are not ready to process this message because 62 // If locked, it means we are not ready to process this message because
47 // we are probably in a first run critical phase. 63 // we are probably in a first run critical phase.
48 saved_startup_messages_.push_back( 64 saved_startup_messages_.push_back(
robertshield 2013/03/28 14:31:48 minor nit: since these are only going to be played
gab 2013/03/28 14:52:41 I thought about this too, the theory being that in
49 std::make_pair(command_line.argv(), current_directory)); 65 DelayedStartupMessage(command_line.argv(),
66 current_directory,
67 operation_output.release()));
50 return true; 68 return true;
51 } else { 69 } else {
52 return original_callback_.Run(command_line, current_directory); 70 return operation_callback_.Run(command_line,
71 current_directory,
72 operation_output.Pass());
53 } 73 }
54 } 74 }
75
76 ProcessSingletonLock::DelayedStartupMessage::DelayedStartupMessage(
77 const CommandLine::StringVector& argv,
78 const base::FilePath& current_directory,
79 OperationOutput* operation_output)
80 : argv_(argv),
81 current_directory_(current_directory),
82 operation_output_(operation_output) {
83 }
84
85 ProcessSingletonLock::DelayedStartupMessage::~DelayedStartupMessage() { }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698