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

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: Fixed comments. 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 SystemLogDelegate::SystemLogDelegate() : weak_ptr_factory_(this) {
34 }
35
36 SystemLogDelegate::~SystemLogDelegate() {
37 }
38
39 void SystemLogDelegate::LoadSystemLogs(
40 const SystemLogUploadJob::LogUploadCallback& upload_callback) {
41 SystemLogUploadJob::SystemLogs* system_logs =
42 new SystemLogUploadJob::SystemLogs();
43 // Run ReadFiles() in the thread that interacts with the file system
44 // 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
45 content::BrowserThread::PostTaskAndReply(
46 content::BrowserThread::FILE, FROM_HERE,
47 base::Bind(&SystemLogDelegate::ReadFiles, weak_ptr_factory_.GetWeakPtr(),
48 system_logs),
49 base::Bind(upload_callback, base::Owned(system_logs)));
50 }
51
52 scoped_ptr<UploadJob> SystemLogDelegate::CreateUploadJob(
53 const GURL& upload_url,
54 UploadJob::Delegate* delegate) {
55 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service =
56 chromeos::DeviceOAuth2TokenServiceFactory::Get();
57
58 scoped_refptr<net::URLRequestContextGetter> system_request_context =
59 g_browser_process->system_request_context();
60 std::string robot_account_id =
61 device_oauth2_token_service->GetRobotAccountId();
62 return scoped_ptr<UploadJob>(new UploadJobImpl(
63 upload_url, robot_account_id, device_oauth2_token_service,
64 system_request_context, delegate,
65 make_scoped_ptr(new UploadJobImpl::RandomMimeBoundaryGenerator)));
66 }
67
68 void SystemLogDelegate::ReadFiles(SystemLogUploadJob::SystemLogs* system_logs) {
69 for (auto const file_path : kSystemLogFileNames) {
70 if (!base::PathExists(base::FilePath(file_path)))
71 continue;
72 system_logs->push_back(std::make_pair(file_path, std::string()));
73 if (!base::ReadFileToString(base::FilePath(file_path),
74 &(system_logs->back().second))) {
75 LOG(ERROR) << "Failed to read the system log file from the disk "
76 << file_path << std::endl;
77 }
78 }
79 }
80
81 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/system_log_delegate.h ('k') | chrome/browser/chromeos/policy/system_log_upload_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698