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

Unified Diff: apps/app_host/test_operation.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: Forgotten review responses. Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « apps/app_host/operation_launcher.cc ('k') | apps/apps.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: apps/app_host/test_operation.cc
diff --git a/apps/app_host/test_operation.cc b/apps/app_host/test_operation.cc
new file mode 100644
index 0000000000000000000000000000000000000000..37f2cf28821b2ddd1b2ebb4023434df4f278aa04
--- /dev/null
+++ b/apps/app_host/test_operation.cc
@@ -0,0 +1,87 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <windows.h>
+
+#include "base/at_exit.h"
+#include "base/command_line.h"
+#include "base/process_util.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/win/scoped_handle.h"
+#include "chrome/browser/operation_output.h"
+#include "chrome/common/chrome_switches.h"
+
+const char kDelegateWait[] = "delegate-wait";
+const char kWait[] = "wait";
+const char kOutputLength[] = "output-length";
+const char kExitCode[] = "exit-code";
+
+int APIENTRY wWinMain(HINSTANCE, HINSTANCE, wchar_t*, int) {
+ base::AtExitManager exit_manager;
+ base::win::ScopedHandle child_ready_event(::CreateEvent(
+ NULL, TRUE, FALSE, L"Local\\AppHostTestOperationChildReady"));
+ if (!child_ready_event)
+ return 1;
+
+ // Initialize the commandline singleton from the environment.
+ CommandLine::Init(0, NULL);
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch("delegate")) {
+ CommandLine child_command_line(command_line->GetProgram());
+ const char* forwarded_switches[] = {
+ switches::kTaskRemoteProcessId,
+ switches::kTaskOutputHandle,
+ switches::kTaskResultHandle,
+ kWait,
+ kOutputLength,
+ kExitCode};
+ child_command_line.CopySwitchesFrom(
+ *command_line, forwarded_switches, arraysize(forwarded_switches));
+ if (!base::LaunchProcess(child_command_line, base::LaunchOptions(), NULL))
+ return 1;
+ if (command_line->HasSwitch(kDelegateWait)) {
+ base::win::ScopedHandle delegate_wait_event(
+ ::CreateEvent(NULL, TRUE, FALSE,
+ L"Local\\AppHostTestOperationDelegateWait"));
+ if (::WaitForSingleObject(delegate_wait_event, 10000) != WAIT_OBJECT_0)
+ return 1;
+ }
+ } else {
+ scoped_ptr<OperationOutput> operation_output =
+ OperationOutput::Create(*command_line);
+ if (!operation_output)
+ return 1;
+ if (!::SetEvent(child_ready_event))
+ return 1;
+ if (command_line->HasSwitch(kWait)) {
+ base::win::ScopedHandle child_wait_event(::CreateEvent(
+ NULL, TRUE, FALSE, L"Local\\AppHostTestOperationChildWait"));
+ if (::WaitForSingleObject(child_wait_event, 10000) != WAIT_OBJECT_0)
+ return 1;
+ }
+
+ std::string output_length_string = command_line->GetSwitchValueASCII(
+ kOutputLength);
+ std::string exit_code_string = command_line->GetSwitchValueASCII(
+ kExitCode);
+ unsigned output_length = 0;
+ unsigned exit_code = 0;
+ if (!base::StringToUint(output_length_string,
+ reinterpret_cast<unsigned*>(&output_length)) ||
+ !base::StringToUint(output_length_string,
+ reinterpret_cast<unsigned*>(&output_length))) {
+ return 1;
+ }
+ std::vector<char> buffer(output_length);
+ for (size_t i = 0; i < buffer.size(); ++i) {
+ buffer[i] = '0' + i % 10;
+ }
+ if (!operation_output->Write(&buffer[0], buffer.size()))
+ return 1;
+ if (!OperationOutput::Complete(operation_output.Pass(), exit_code))
+ return 1;
+ }
+
+ return 0;
+}
« no previous file with comments | « apps/app_host/operation_launcher.cc ('k') | apps/apps.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698