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

Unified Diff: chrome/browser/chromeos/policy/system_log_delegate.cc

Issue 1193333017: Added system log uploader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved SystemLogUploadJob creation to DeviceCloudPolicyManager. Created 5 years, 6 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/policy/system_log_delegate.cc
diff --git a/chrome/browser/chromeos/policy/system_log_delegate.cc b/chrome/browser/chromeos/policy/system_log_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1bc43808cb6086a1e615f56c7a77e2c03b8e9856
--- /dev/null
+++ b/chrome/browser/chromeos/policy/system_log_delegate.cc
@@ -0,0 +1,77 @@
+// Copyright 2015 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/policy/system_log_delegate.h"
+
+#include "base/bind.h"
+#include "base/files/file_util.h"
+#include "base/task_runner_util.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
+#include "chrome/browser/chromeos/policy/upload_job_impl.h"
+#include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
+#include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace {
+// File names of uploading system logs.
Andrew T Wilson (Slow) 2015/06/29 15:06:08 nit: filenames of system logs to upload Put a not
Polina Bondarenko 2015/07/02 15:28:03 Done.
+const char* const kSystemLogFileNames[] = {"/var/log/bios_info.txt",
+ "/var/log/chrome/chrome",
+ "/var/log/eventlog.txt",
+ "/var/log/messages",
+ "/var/log/net.log",
+ "/var/log/platform_info.txt",
+ "/var/log/ui/ui.LATEST",
+ "/var/log/update_engine.log"};
+} // namespace
+
+namespace policy {
+
+SystemLogDelegate::SystemLogDelegate() : weak_ptr_factory_(this) {
+}
+
+SystemLogDelegate::~SystemLogDelegate() {
+}
+
+void SystemLogDelegate::LoadSystemLogs(
+ const SystemLogUploadJob::LogUploadCallback& upload_callback) {
+ base::PostTaskAndReplyWithResult(
+ content::BrowserThread::GetBlockingPool(), FROM_HERE,
+ base::Bind(&SystemLogDelegate::ReadFiles, base::Unretained(this)),
Andrew T Wilson (Slow) 2015/06/29 15:06:08 Why are you using base::Unretained() instead of th
Polina Bondarenko 2015/07/02 15:28:03 The weak ptr can't be used here, because there is
+ upload_callback);
+}
+
+std::map<std::string, std::string> SystemLogDelegate::ReadFiles() {
+ std::map<std::string, std::string> system_logs;
+ for (auto const file_path : kSystemLogFileNames) {
+ if (!base::PathExists(base::FilePath(file_path)))
+ continue;
+ system_logs[file_path] = std::string();
+ if (!base::ReadFileToString(base::FilePath(file_path),
+ &system_logs[file_path])) {
+ LOG(ERROR) << "Failed to read system log file from disk " << file_path
+ << std::endl;
+ }
+ }
+ return system_logs;
+}
+
+scoped_ptr<UploadJob> SystemLogDelegate::CreateUploadJob(
+ const GURL& upload_url,
+ UploadJob::Delegate* delegate) {
+ chromeos::DeviceOAuth2TokenService* device_oauth2_token_service =
+ chromeos::DeviceOAuth2TokenServiceFactory::Get();
+
+ scoped_refptr<net::URLRequestContextGetter> system_request_context =
+ g_browser_process->system_request_context();
+ std::string robot_account_id =
+ device_oauth2_token_service->GetRobotAccountId();
+ return scoped_ptr<UploadJob>(new UploadJobImpl(
+ upload_url, robot_account_id, device_oauth2_token_service,
+ system_request_context, delegate,
+ make_scoped_ptr(new UploadJobImpl::RandomMimeBoundaryGenerator)));
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698