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..68934db25339fc6b8c0c4f264f7efa587d0f7833 |
--- /dev/null |
+++ b/chrome/browser/chromeos/policy/system_log_delegate.cc |
@@ -0,0 +1,81 @@ |
+// 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 { |
+ |
+SystemLogDelegate::SystemLogDelegate() : weak_ptr_factory_(this) { |
+} |
+ |
+SystemLogDelegate::~SystemLogDelegate() { |
+} |
+ |
+void SystemLogDelegate::LoadSystemLogs( |
+ const SystemLogUploadJob::LogUploadCallback& upload_callback) { |
+ SystemLogUploadJob::SystemLogs* system_logs = |
+ new SystemLogUploadJob::SystemLogs(); |
+ // Run ReadFiles() in the thread that interacts with the file system |
+ // and return to the current thread. |
Polina Bondarenko
2015/07/03 13:34:19
The weak ptr is not thread safe, it should not be
|
+ content::BrowserThread::PostTaskAndReply( |
+ content::BrowserThread::FILE, FROM_HERE, |
+ base::Bind(&SystemLogDelegate::ReadFiles, weak_ptr_factory_.GetWeakPtr(), |
+ system_logs), |
+ base::Bind(upload_callback, base::Owned(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))); |
+} |
+ |
+void SystemLogDelegate::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; |
+ } |
+ } |
+} |
+ |
+} // namespace policy |