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

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: Moved SystemLogUploadJob creation to DeviceCloudPolicyManager. 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 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 "chrome/browser/chromeos/policy/system_log_delegate.h"
6
7 #include "base/bind.h"
8 #include "base/files/file_util.h"
9 #include "base/task_runner_util.h"
10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
12 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h"
13 #include "chrome/browser/chromeos/policy/upload_job_impl.h"
14 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
15 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
16 #include "content/public/browser/browser_thread.h"
17
18 namespace {
19 // File names of uploading system logs.
Andrew T Wilson (Slow) 2015/06/29 15:06:08 nit: filenames of system logs to upload Put a not
Polina Bondarenko 2015/07/02 15:28:03 Done.
20 const char* const kSystemLogFileNames[] = {"/var/log/bios_info.txt",
21 "/var/log/chrome/chrome",
22 "/var/log/eventlog.txt",
23 "/var/log/messages",
24 "/var/log/net.log",
25 "/var/log/platform_info.txt",
26 "/var/log/ui/ui.LATEST",
27 "/var/log/update_engine.log"};
28 } // namespace
29
30 namespace policy {
31
32 SystemLogDelegate::SystemLogDelegate() : weak_ptr_factory_(this) {
33 }
34
35 SystemLogDelegate::~SystemLogDelegate() {
36 }
37
38 void SystemLogDelegate::LoadSystemLogs(
39 const SystemLogUploadJob::LogUploadCallback& upload_callback) {
40 base::PostTaskAndReplyWithResult(
41 content::BrowserThread::GetBlockingPool(), FROM_HERE,
42 base::Bind(&SystemLogDelegate::ReadFiles, base::Unretained(this)),
Andrew T Wilson (Slow) 2015/06/29 15:06:08 Why are you using base::Unretained() instead of th
Polina Bondarenko 2015/07/02 15:28:03 The weak ptr can't be used here, because there is
43 upload_callback);
44 }
45
46 std::map<std::string, std::string> SystemLogDelegate::ReadFiles() {
47 std::map<std::string, std::string> system_logs;
48 for (auto const file_path : kSystemLogFileNames) {
49 if (!base::PathExists(base::FilePath(file_path)))
50 continue;
51 system_logs[file_path] = std::string();
52 if (!base::ReadFileToString(base::FilePath(file_path),
53 &system_logs[file_path])) {
54 LOG(ERROR) << "Failed to read system log file from disk " << file_path
55 << std::endl;
56 }
57 }
58 return system_logs;
59 }
60
61 scoped_ptr<UploadJob> SystemLogDelegate::CreateUploadJob(
62 const GURL& upload_url,
63 UploadJob::Delegate* delegate) {
64 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service =
65 chromeos::DeviceOAuth2TokenServiceFactory::Get();
66
67 scoped_refptr<net::URLRequestContextGetter> system_request_context =
68 g_browser_process->system_request_context();
69 std::string robot_account_id =
70 device_oauth2_token_service->GetRobotAccountId();
71 return scoped_ptr<UploadJob>(new UploadJobImpl(
72 upload_url, robot_account_id, device_oauth2_token_service,
73 system_request_context, delegate,
74 make_scoped_ptr(new UploadJobImpl::RandomMimeBoundaryGenerator)));
75 }
76
77 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698