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

Side by Side 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, 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/bind.h"
6 #include "base/bind_helpers.h"
7 #include "base/files/file_util.h"
8 #include "base/task_runner_util.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/policy/system_log_delegate.h"
12 #include "chrome/browser/chromeos/policy/upload_job_impl.h"
13 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
14 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
15 #include "content/public/browser/browser_thread.h"
16
17 namespace {
18
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.
21 const char* const kSystemLogFileNames[] = {"/var/log/bios_info.txt",
22 "/var/log/chrome/chrome",
23 "/var/log/eventlog.txt",
24 "/var/log/messages",
25 "/var/log/net.log",
26 "/var/log/platform_info.txt",
27 "/var/log/ui/ui.LATEST",
28 "/var/log/update_engine.log"};
29 } // namespace
30
31 namespace policy {
32
33 // FileReader - helper class that thread safely reads files from the disk.
34 class FileReader : public base::RefCountedThreadSafe<FileReader> {
35 public:
36 base::CancelableTaskTracker::TaskId StartRead(
37 const SystemLogUploadJob::LogUploadCallback& upload_callback,
38 base::CancelableTaskTracker* tracker);
39
40 private:
41 friend class base::RefCountedThreadSafe<FileReader>;
42 ~FileReader() {}
43
44 // Reads the system log files as binary files, stores the files as pairs
45 // (file name, data) in the external structure to pass it to the
46 // |upload_callback|.
47 void ReadFiles(SystemLogUploadJob::SystemLogs* system_logs);
48 };
49
50 base::CancelableTaskTracker::TaskId FileReader::StartRead(
51 const SystemLogUploadJob::LogUploadCallback& upload_callback,
52 base::CancelableTaskTracker* tracker) {
53 // 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.
54 SystemLogUploadJob::SystemLogs* system_logs =
55 new SystemLogUploadJob::SystemLogs();
56
57 // Run ReadFiles() in the thread that interacts with the file
58 // system and return to the current thread.
59 return tracker->PostTaskAndReply(
60 content::BrowserThread::GetMessageLoopProxyForThread(
61 content::BrowserThread::FILE).get(),
62 FROM_HERE, base::Bind(&FileReader::ReadFiles, this, system_logs),
63 base::Bind(upload_callback, base::Owned(system_logs)));
64 }
65
66 void FileReader::ReadFiles(SystemLogUploadJob::SystemLogs* system_logs) {
67 for (auto const file_path : kSystemLogFileNames) {
68 if (!base::PathExists(base::FilePath(file_path)))
69 continue;
70 system_logs->push_back(std::make_pair(file_path, std::string()));
71 if (!base::ReadFileToString(base::FilePath(file_path),
72 &(system_logs->back().second))) {
73 LOG(ERROR) << "Failed to read the system log file from the disk "
74 << file_path << std::endl;
75 }
76 }
77 }
78
79 SystemLogDelegate::SystemLogDelegate()
80 : file_reader_(new FileReader()), weak_ptr_factory_(this) {
81 }
82
83 SystemLogDelegate::~SystemLogDelegate() {
84 }
85
86 void SystemLogDelegate::LoadSystemLogs(
87 const SystemLogUploadJob::LogUploadCallback& upload_callback) {
88 file_reader_->StartRead(upload_callback, &tracker_);
89 }
90
91 scoped_ptr<UploadJob> SystemLogDelegate::CreateUploadJob(
92 const GURL& upload_url,
93 UploadJob::Delegate* delegate) {
94 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service =
95 chromeos::DeviceOAuth2TokenServiceFactory::Get();
96
97 scoped_refptr<net::URLRequestContextGetter> system_request_context =
98 g_browser_process->system_request_context();
99 std::string robot_account_id =
100 device_oauth2_token_service->GetRobotAccountId();
101 return scoped_ptr<UploadJob>(new UploadJobImpl(
102 upload_url, robot_account_id, device_oauth2_token_service,
103 system_request_context, delegate,
104 make_scoped_ptr(new UploadJobImpl::RandomMimeBoundaryGenerator)));
105 }
106
107 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698