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

Side by Side Diff: chrome/browser/chromeos/policy/system_log_delegate.cc

Issue 1216643002: Added unittests for SystemLogUploader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed according to the main log uploader CL. Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/task_runner_util.h" 8 #include "base/task_runner_util.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/policy/system_log_delegate.h" 11 #include "chrome/browser/chromeos/policy/system_log_delegate.h"
12 #include "chrome/browser/chromeos/policy/upload_job_impl.h" 12 #include "chrome/browser/chromeos/policy/upload_job_impl.h"
13 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 13 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
14 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 14 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 16
17 namespace { 17 namespace {
18 18
19 // File names of system logs to upload. 19 // The file names of the system logs to upload.
20 // Note: do not add anything to this list without checking for PII in the file. 20 // Note: do not add anything to this list without checking for PII in the file.
21 const char* const kSystemLogFileNames[] = {"/var/log/bios_info.txt", 21 const char* const kSystemLogFileNames[] = {"/var/log/bios_info.txt",
22 "/var/log/chrome/chrome", 22 "/var/log/chrome/chrome",
23 "/var/log/eventlog.txt", 23 "/var/log/eventlog.txt",
24 "/var/log/messages", 24 "/var/log/messages",
25 "/var/log/net.log", 25 "/var/log/net.log",
26 "/var/log/platform_info.txt", 26 "/var/log/platform_info.txt",
27 "/var/log/ui/ui.LATEST", 27 "/var/log/ui/ui.LATEST",
28 "/var/log/update_engine.log"}; 28 "/var/log/update_engine.log"};
29 } // namespace 29 } // namespace
30 30
31 namespace policy { 31 namespace policy {
32 32
33 SystemLogDelegate::SystemLogDelegate() : weak_ptr_factory_(this) { 33 SystemLogDelegate::SystemLogDelegate() : weak_ptr_factory_(this) {
34 } 34 }
35 35
36 SystemLogDelegate::~SystemLogDelegate() { 36 SystemLogDelegate::~SystemLogDelegate() {
37 } 37 }
38 38
39 void SystemLogDelegate::LoadSystemLogs( 39 void SystemLogDelegate::LoadSystemLogs(
40 const SystemLogUploadJob::LogUploadCallback& upload_callback) { 40 const SystemLogUploadJob::LogUploadCallback& upload_callback) {
41 SystemLogUploadJob::SystemLogs* system_logs = 41 SystemLogUploadJob::SystemLogs* system_logs =
42 new SystemLogUploadJob::SystemLogs(); 42 new SystemLogUploadJob::SystemLogs();
43 // Run ReadFiles() in the thread that interacts with the file system 43 // Run ReadFiles() in the thread that interacts with the file system
44 // and return to current thread. 44 // and return to the current thread.
45 content::BrowserThread::PostTaskAndReply( 45 content::BrowserThread::PostTaskAndReply(
46 content::BrowserThread::FILE, FROM_HERE, 46 content::BrowserThread::FILE, FROM_HERE,
47 base::Bind(&SystemLogDelegate::ReadFiles, weak_ptr_factory_.GetWeakPtr(), 47 base::Bind(&SystemLogDelegate::ReadFiles, weak_ptr_factory_.GetWeakPtr(),
48 system_logs), 48 system_logs),
49 base::Bind(upload_callback, base::Owned(system_logs))); 49 base::Bind(upload_callback, base::Owned(system_logs)));
50 } 50 }
51 51
52 scoped_ptr<UploadJob> SystemLogDelegate::CreateUploadJob( 52 scoped_ptr<UploadJob> SystemLogDelegate::CreateUploadJob(
53 const GURL& upload_url, 53 const GURL& upload_url,
54 UploadJob::Delegate* delegate) { 54 UploadJob::Delegate* delegate) {
(...skipping 10 matching lines...) Expand all
65 make_scoped_ptr(new UploadJobImpl::RandomMimeBoundaryGenerator))); 65 make_scoped_ptr(new UploadJobImpl::RandomMimeBoundaryGenerator)));
66 } 66 }
67 67
68 void SystemLogDelegate::ReadFiles(SystemLogUploadJob::SystemLogs* system_logs) { 68 void SystemLogDelegate::ReadFiles(SystemLogUploadJob::SystemLogs* system_logs) {
69 for (auto const file_path : kSystemLogFileNames) { 69 for (auto const file_path : kSystemLogFileNames) {
70 if (!base::PathExists(base::FilePath(file_path))) 70 if (!base::PathExists(base::FilePath(file_path)))
71 continue; 71 continue;
72 system_logs->push_back(std::make_pair(file_path, std::string())); 72 system_logs->push_back(std::make_pair(file_path, std::string()));
73 if (!base::ReadFileToString(base::FilePath(file_path), 73 if (!base::ReadFileToString(base::FilePath(file_path),
74 &(system_logs->back().second))) { 74 &(system_logs->back().second))) {
75 LOG(ERROR) << "Failed to read system log file from disk " << file_path 75 LOG(ERROR) << "Failed to read the system log file from the disk "
76 << std::endl; 76 << file_path << std::endl;
77 } 77 }
78 } 78 }
79 } 79 }
80 80
81 } // namespace policy 81 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698