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