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

Unified Diff: chrome/browser/chromeos/system/commandline_fetcher.cc

Issue 10827130: Refactoring the SysInfoProvider. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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
Index: chrome/browser/chromeos/system/commandline_fetcher.cc
diff --git a/chrome/browser/chromeos/system/commandline_fetcher.cc b/chrome/browser/chromeos/system/commandline_fetcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2e14e47ceabbb4f6bdde9c1860a9528e79b4a45d
--- /dev/null
+++ b/chrome/browser/chromeos/system/commandline_fetcher.cc
@@ -0,0 +1,51 @@
+// Copyright (c) 2012 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 "chrome/browser/chromeos/system/commandline_fetcher.h"
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/string_util.h"
+
+namespace chromeos {
+namespace system {
+
+void CommandLineFetcher::Fetch(SysLogsFetcherCallback request)
+{
+ FilePath temp_filename;
+ SysInfoResponse* response = new SysInfoResponse;
+ if (!file_util::CreateTemporaryFile(&temp_filename))
rkc1 2012/08/04 01:15:05 Change this to use base::GetAppOutput.
tudalex(Chromium) 2012/08/05 01:15:12 Done.
+ {
+ request.Run(response);
+ return;
+ }
+ std::string cmd = command_ + " >> " +
+ temp_filename.value();
+
+ // Ignore the return value - if the script execution didn't work
+ // stderr won't go into the output file anyway.
+ if (::system(cmd.c_str()) == -1)
+ LOG(WARNING) << "Command " << cmd << " failed to run";
+ // Read logs from the temp file
+ std::string data;
+ bool read_success = file_util::ReadFileToString(temp_filename,
+ &data);
+ // if we were using an internal temp file, the user does not need the
+ // logs to stay past the ReadFile call - delete the file
+ if (!read_success)
+ {
+ request.Run(response);
+ return;
+ }
+ file_util::Delete(temp_filename, false);
+ (*response)[key_] = data;
+ request.Run(response);
+}
+
+} // namespace system
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698