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

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: Added FileReader - helper class that reads files thread safely. 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..4b57faa4663c7104e8fce217aaf4137f0ea5de01
--- /dev/null
+++ b/chrome/browser/chromeos/policy/system_log_delegate.cc
@@ -0,0 +1,107 @@
+// 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 "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/files/file_util.h"
+#include "base/task_runner_util.h"
+#include "base/thread_task_runner_handle.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/policy/system_log_delegate.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 {
+
+// The file names of the system logs to upload.
+// Note: do not add anything to this list without checking for PII in the file.
+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 {
+
+// FileReader - helper class that thread safely reads files from the disk.
+class FileReader : public base::RefCountedThreadSafe<FileReader> {
+ public:
+ base::CancelableTaskTracker::TaskId StartRead(
+ const SystemLogUploadJob::LogUploadCallback& upload_callback,
+ base::CancelableTaskTracker* tracker);
+
+ private:
+ friend class base::RefCountedThreadSafe<FileReader>;
+ ~FileReader() {}
+
+ // Reads the system log files as binary files, stores the files as pairs
+ // (file name, data) in the external structure to pass it to the
+ // |upload_callback|.
+ void ReadFiles(SystemLogUploadJob::SystemLogs* system_logs);
+};
+
+base::CancelableTaskTracker::TaskId FileReader::StartRead(
+ const SystemLogUploadJob::LogUploadCallback& upload_callback,
+ base::CancelableTaskTracker* tracker) {
+ // Owned by reply callback posted below.
Andrew T Wilson (Slow) 2015/07/03 15:40:47 Can you add some DCHECKs() for which thread you ex
Polina Bondarenko 2015/07/08 10:07:23 Done.
+ SystemLogUploadJob::SystemLogs* system_logs =
+ new SystemLogUploadJob::SystemLogs();
+
+ // Run ReadFiles() in the thread that interacts with the file
+ // system and return to the current thread.
+ return tracker->PostTaskAndReply(
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::FILE).get(),
+ FROM_HERE, base::Bind(&FileReader::ReadFiles, this, system_logs),
+ base::Bind(upload_callback, base::Owned(system_logs)));
+}
+
+void FileReader::ReadFiles(SystemLogUploadJob::SystemLogs* system_logs) {
+ for (auto const file_path : kSystemLogFileNames) {
+ if (!base::PathExists(base::FilePath(file_path)))
+ continue;
+ system_logs->push_back(std::make_pair(file_path, std::string()));
+ if (!base::ReadFileToString(base::FilePath(file_path),
+ &(system_logs->back().second))) {
+ LOG(ERROR) << "Failed to read the system log file from the disk "
+ << file_path << std::endl;
+ }
+ }
+}
+
+SystemLogDelegate::SystemLogDelegate()
+ : file_reader_(new FileReader()), weak_ptr_factory_(this) {
+}
+
+SystemLogDelegate::~SystemLogDelegate() {
+}
+
+void SystemLogDelegate::LoadSystemLogs(
+ const SystemLogUploadJob::LogUploadCallback& upload_callback) {
+ file_reader_->StartRead(upload_callback, &tracker_);
+}
+
+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