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

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

Issue 2412963003: Replace CHROMEOS_SYSLOG logs with SYSLOG logs so remote command related (Closed)
Patch Set: Created 4 years, 2 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 (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <utility> 5 #include <utility>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/chromeos/logging.h"
10 #include "base/command_line.h" 9 #include "base/command_line.h"
11 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
12 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
13 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
14 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/syslog_logging.h"
15 #include "base/task_runner_util.h" 15 #include "base/task_runner_util.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chromeos/policy/upload_job_impl.h" 17 #include "chrome/browser/chromeos/policy/upload_job_impl.h"
18 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 18 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
19 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 19 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "components/feedback/anonymizer_tool.h" 21 #include "components/feedback/anonymizer_tool.h"
22 #include "components/policy/core/browser/browser_policy_connector.h" 22 #include "components/policy/core/browser/browser_policy_connector.h"
23 #include "content/public/browser/browser_thread.h" 23 #include "content/public/browser/browser_thread.h"
24 #include "net/http/http_request_headers.h" 24 #include "net/http/http_request_headers.h"
(...skipping 19 matching lines...) Expand all
44 // as pairs (file name, data) and returns. Called on blocking thread. 44 // as pairs (file name, data) and returns. Called on blocking thread.
45 std::unique_ptr<policy::SystemLogUploader::SystemLogs> ReadFiles() { 45 std::unique_ptr<policy::SystemLogUploader::SystemLogs> ReadFiles() {
46 std::unique_ptr<policy::SystemLogUploader::SystemLogs> system_logs( 46 std::unique_ptr<policy::SystemLogUploader::SystemLogs> system_logs(
47 new policy::SystemLogUploader::SystemLogs()); 47 new policy::SystemLogUploader::SystemLogs());
48 feedback::AnonymizerTool anonymizer; 48 feedback::AnonymizerTool anonymizer;
49 for (auto* file_path : kSystemLogFileNames) { 49 for (auto* file_path : kSystemLogFileNames) {
50 if (!base::PathExists(base::FilePath(file_path))) 50 if (!base::PathExists(base::FilePath(file_path)))
51 continue; 51 continue;
52 std::string data = std::string(); 52 std::string data = std::string();
53 if (!base::ReadFileToString(base::FilePath(file_path), &data)) { 53 if (!base::ReadFileToString(base::FilePath(file_path), &data)) {
54 CHROMEOS_SYSLOG(ERROR) 54 SYSLOG(ERROR) << "Failed to read the system log file from the disk "
55 << "Failed to read the system log file from the disk " << file_path 55 << file_path << std::endl;
56 << std::endl;
57 } 56 }
58 system_logs->push_back(std::make_pair( 57 system_logs->push_back(std::make_pair(
59 file_path, 58 file_path,
60 policy::SystemLogUploader::RemoveSensitiveData(&anonymizer, data))); 59 policy::SystemLogUploader::RemoveSensitiveData(&anonymizer, data)));
61 } 60 }
62 return system_logs; 61 return system_logs;
63 } 62 }
64 63
65 // An implementation of the |SystemLogUploader::Delegate|, that is used to 64 // An implementation of the |SystemLogUploader::Delegate|, that is used to
66 // create an upload job and load system logs from the disk. 65 // create an upload job and load system logs from the disk.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 const GURL& upload_url, 102 const GURL& upload_url,
104 policy::UploadJob::Delegate* delegate) { 103 policy::UploadJob::Delegate* delegate) {
105 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service = 104 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service =
106 chromeos::DeviceOAuth2TokenServiceFactory::Get(); 105 chromeos::DeviceOAuth2TokenServiceFactory::Get();
107 106
108 scoped_refptr<net::URLRequestContextGetter> system_request_context = 107 scoped_refptr<net::URLRequestContextGetter> system_request_context =
109 g_browser_process->system_request_context(); 108 g_browser_process->system_request_context();
110 std::string robot_account_id = 109 std::string robot_account_id =
111 device_oauth2_token_service->GetRobotAccountId(); 110 device_oauth2_token_service->GetRobotAccountId();
112 111
113 CHROMEOS_SYSLOG(WARNING) << "Creating upload job for system log"; 112 SYSLOG(INFO) << "Creating upload job for system log";
114 return std::unique_ptr<policy::UploadJob>(new policy::UploadJobImpl( 113 return std::unique_ptr<policy::UploadJob>(new policy::UploadJobImpl(
115 upload_url, robot_account_id, device_oauth2_token_service, 114 upload_url, robot_account_id, device_oauth2_token_service,
116 system_request_context, delegate, 115 system_request_context, delegate,
117 base::WrapUnique(new policy::UploadJobImpl::RandomMimeBoundaryGenerator), 116 base::WrapUnique(new policy::UploadJobImpl::RandomMimeBoundaryGenerator),
118 task_runner_)); 117 task_runner_));
119 } 118 }
120 119
121 // Returns the system log upload frequency. 120 // Returns the system log upload frequency.
122 base::TimeDelta GetUploadFrequency() { 121 base::TimeDelta GetUploadFrequency() {
123 base::TimeDelta upload_frequency(base::TimeDelta::FromMilliseconds( 122 base::TimeDelta upload_frequency(base::TimeDelta::FromMilliseconds(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 188
190 // Immediately schedule the next system log upload (last_upload_attempt_ is 189 // Immediately schedule the next system log upload (last_upload_attempt_ is
191 // set to the start of the epoch, so this will trigger an update upload in the 190 // set to the start of the epoch, so this will trigger an update upload in the
192 // immediate future). 191 // immediate future).
193 ScheduleNextSystemLogUpload(upload_frequency_); 192 ScheduleNextSystemLogUpload(upload_frequency_);
194 } 193 }
195 194
196 SystemLogUploader::~SystemLogUploader() {} 195 SystemLogUploader::~SystemLogUploader() {}
197 196
198 void SystemLogUploader::OnSuccess() { 197 void SystemLogUploader::OnSuccess() {
199 CHROMEOS_SYSLOG(WARNING) << "Upload successful."; 198 SYSLOG(INFO) << "Upload successful.";
200 upload_job_.reset(); 199 upload_job_.reset();
201 last_upload_attempt_ = base::Time::NowFromSystemTime(); 200 last_upload_attempt_ = base::Time::NowFromSystemTime();
202 retry_count_ = 0; 201 retry_count_ = 0;
203 202
204 // On successful log upload schedule the next log upload after 203 // On successful log upload schedule the next log upload after
205 // upload_frequency_ time from now. 204 // upload_frequency_ time from now.
206 ScheduleNextSystemLogUpload(upload_frequency_); 205 ScheduleNextSystemLogUpload(upload_frequency_);
207 } 206 }
208 207
209 void SystemLogUploader::OnFailure(UploadJob::ErrorCode error_code) { 208 void SystemLogUploader::OnFailure(UploadJob::ErrorCode error_code) {
210 upload_job_.reset(); 209 upload_job_.reset();
211 last_upload_attempt_ = base::Time::NowFromSystemTime(); 210 last_upload_attempt_ = base::Time::NowFromSystemTime();
212 211
213 // If we have hit the maximum number of retries, terminate this upload 212 // If we have hit the maximum number of retries, terminate this upload
214 // attempt and schedule the next one using the normal delay. Otherwise, retry 213 // attempt and schedule the next one using the normal delay. Otherwise, retry
215 // uploading after kErrorUploadDelayMs milliseconds. 214 // uploading after kErrorUploadDelayMs milliseconds.
216 if (retry_count_++ < kMaxNumRetries) { 215 if (retry_count_++ < kMaxNumRetries) {
217 CHROMEOS_SYSLOG(ERROR) << "Upload failed with error code " << error_code 216 SYSLOG(ERROR) << "Upload failed with error code " << error_code
218 << ", retrying later."; 217 << ", retrying later.";
219 ScheduleNextSystemLogUpload( 218 ScheduleNextSystemLogUpload(
220 base::TimeDelta::FromMilliseconds(kErrorUploadDelayMs)); 219 base::TimeDelta::FromMilliseconds(kErrorUploadDelayMs));
221 } else { 220 } else {
222 // No more retries. 221 // No more retries.
223 CHROMEOS_SYSLOG(ERROR) << "Upload failed with error code " << error_code 222 SYSLOG(ERROR) << "Upload failed with error code " << error_code
224 << ", no more retries."; 223 << ", no more retries.";
225 retry_count_ = 0; 224 retry_count_ = 0;
226 ScheduleNextSystemLogUpload(upload_frequency_); 225 ScheduleNextSystemLogUpload(upload_frequency_);
227 } 226 }
228 } 227 }
229 228
230 // static 229 // static
231 std::string SystemLogUploader::RemoveSensitiveData( 230 std::string SystemLogUploader::RemoveSensitiveData(
232 feedback::AnonymizerTool* const anonymizer, 231 feedback::AnonymizerTool* const anonymizer,
233 const std::string& data) { 232 const std::string& data) {
234 return anonymizer->Anonymize(data); 233 return anonymizer->Anonymize(data);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 base::TimeDelta()); 300 base::TimeDelta());
302 // Ensure that we never have more than one pending delayed task. 301 // Ensure that we never have more than one pending delayed task.
303 weak_factory_.InvalidateWeakPtrs(); 302 weak_factory_.InvalidateWeakPtrs();
304 task_runner_->PostDelayedTask(FROM_HERE, 303 task_runner_->PostDelayedTask(FROM_HERE,
305 base::Bind(&SystemLogUploader::StartLogUpload, 304 base::Bind(&SystemLogUploader::StartLogUpload,
306 weak_factory_.GetWeakPtr()), 305 weak_factory_.GetWeakPtr()),
307 delay); 306 delay);
308 } 307 }
309 308
310 } // namespace policy 309 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698