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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 std::unique_ptr<policy::UploadJob> SystemLogDelegate::CreateUploadJob( | 94 std::unique_ptr<policy::UploadJob> SystemLogDelegate::CreateUploadJob( |
95 const GURL& upload_url, | 95 const GURL& upload_url, |
96 policy::UploadJob::Delegate* delegate) { | 96 policy::UploadJob::Delegate* delegate) { |
97 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service = | 97 chromeos::DeviceOAuth2TokenService* device_oauth2_token_service = |
98 chromeos::DeviceOAuth2TokenServiceFactory::Get(); | 98 chromeos::DeviceOAuth2TokenServiceFactory::Get(); |
99 | 99 |
100 scoped_refptr<net::URLRequestContextGetter> system_request_context = | 100 scoped_refptr<net::URLRequestContextGetter> system_request_context = |
101 g_browser_process->system_request_context(); | 101 g_browser_process->system_request_context(); |
102 std::string robot_account_id = | 102 std::string robot_account_id = |
103 device_oauth2_token_service->GetRobotAccountId(); | 103 device_oauth2_token_service->GetRobotAccountId(); |
104 | |
105 LOG(WARNING) << "Creating upload job for system log"; | |
104 return std::unique_ptr<policy::UploadJob>(new policy::UploadJobImpl( | 106 return std::unique_ptr<policy::UploadJob>(new policy::UploadJobImpl( |
105 upload_url, robot_account_id, device_oauth2_token_service, | 107 upload_url, robot_account_id, device_oauth2_token_service, |
106 system_request_context, delegate, | 108 system_request_context, delegate, |
107 base::WrapUnique( | 109 base::WrapUnique( |
108 new policy::UploadJobImpl::RandomMimeBoundaryGenerator))); | 110 new policy::UploadJobImpl::RandomMimeBoundaryGenerator))); |
109 } | 111 } |
110 | 112 |
111 // Returns the system log upload frequency. | 113 // Returns the system log upload frequency. |
112 base::TimeDelta GetUploadFrequency() { | 114 base::TimeDelta GetUploadFrequency() { |
113 base::TimeDelta upload_frequency(base::TimeDelta::FromMilliseconds( | 115 base::TimeDelta upload_frequency(base::TimeDelta::FromMilliseconds( |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 | 181 |
180 // Immediately schedule the next system log upload (last_upload_attempt_ is | 182 // Immediately schedule the next system log upload (last_upload_attempt_ is |
181 // set to the start of the epoch, so this will trigger an update upload in the | 183 // set to the start of the epoch, so this will trigger an update upload in the |
182 // immediate future). | 184 // immediate future). |
183 ScheduleNextSystemLogUpload(upload_frequency_); | 185 ScheduleNextSystemLogUpload(upload_frequency_); |
184 } | 186 } |
185 | 187 |
186 SystemLogUploader::~SystemLogUploader() {} | 188 SystemLogUploader::~SystemLogUploader() {} |
187 | 189 |
188 void SystemLogUploader::OnSuccess() { | 190 void SystemLogUploader::OnSuccess() { |
191 LOG(WARNING) << "Upload successful."; | |
189 upload_job_.reset(); | 192 upload_job_.reset(); |
190 last_upload_attempt_ = base::Time::NowFromSystemTime(); | 193 last_upload_attempt_ = base::Time::NowFromSystemTime(); |
191 retry_count_ = 0; | 194 retry_count_ = 0; |
192 | 195 |
193 // On successful log upload schedule the next log upload after | 196 // On successful log upload schedule the next log upload after |
194 // upload_frequency_ time from now. | 197 // upload_frequency_ time from now. |
195 ScheduleNextSystemLogUpload(upload_frequency_); | 198 ScheduleNextSystemLogUpload(upload_frequency_); |
196 } | 199 } |
197 | 200 |
198 void SystemLogUploader::OnFailure(UploadJob::ErrorCode error_code) { | 201 void SystemLogUploader::OnFailure(UploadJob::ErrorCode error_code) { |
199 upload_job_.reset(); | 202 upload_job_.reset(); |
200 last_upload_attempt_ = base::Time::NowFromSystemTime(); | 203 last_upload_attempt_ = base::Time::NowFromSystemTime(); |
201 | 204 |
202 // If we have hit the maximum number of retries, terminate this upload | 205 // If we have hit the maximum number of retries, terminate this upload |
203 // attempt and schedule the next one using the normal delay. Otherwise, retry | 206 // attempt and schedule the next one using the normal delay. Otherwise, retry |
204 // uploading after kErrorUploadDelayMs milliseconds. | 207 // uploading after kErrorUploadDelayMs milliseconds. |
205 if (retry_count_++ < kMaxNumRetries) { | 208 if (retry_count_++ < kMaxNumRetries) { |
209 LOG(ERROR) << "Upload failed, retrying later."; | |
Andrew T Wilson (Slow)
2016/05/04 14:43:23
Log the error code.
Marton Hunyady
2016/05/09 13:48:15
Done.
| |
206 ScheduleNextSystemLogUpload( | 210 ScheduleNextSystemLogUpload( |
207 base::TimeDelta::FromMilliseconds(kErrorUploadDelayMs)); | 211 base::TimeDelta::FromMilliseconds(kErrorUploadDelayMs)); |
208 } else { | 212 } else { |
209 // No more retries. | 213 // No more retries. |
Andrew T Wilson (Slow)
2016/05/04 14:43:23
Log error code (unless it's logged elsewhere)
Marton Hunyady
2016/05/09 13:48:15
Done.
| |
214 LOG(ERROR) << "Upload failed, no more retries."; | |
210 retry_count_ = 0; | 215 retry_count_ = 0; |
211 ScheduleNextSystemLogUpload(upload_frequency_); | 216 ScheduleNextSystemLogUpload(upload_frequency_); |
212 } | 217 } |
213 } | 218 } |
214 | 219 |
215 // static | 220 // static |
216 std::string SystemLogUploader::RemoveSensitiveData( | 221 std::string SystemLogUploader::RemoveSensitiveData( |
217 feedback::AnonymizerTool* const anonymizer, | 222 feedback::AnonymizerTool* const anonymizer, |
218 const std::string& data) { | 223 const std::string& data) { |
219 return anonymizer->Anonymize(data); | 224 return anonymizer->Anonymize(data); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 base::TimeDelta()); | 291 base::TimeDelta()); |
287 // Ensure that we never have more than one pending delayed task. | 292 // Ensure that we never have more than one pending delayed task. |
288 weak_factory_.InvalidateWeakPtrs(); | 293 weak_factory_.InvalidateWeakPtrs(); |
289 task_runner_->PostDelayedTask(FROM_HERE, | 294 task_runner_->PostDelayedTask(FROM_HERE, |
290 base::Bind(&SystemLogUploader::StartLogUpload, | 295 base::Bind(&SystemLogUploader::StartLogUpload, |
291 weak_factory_.GetWeakPtr()), | 296 weak_factory_.GetWeakPtr()), |
292 delay); | 297 delay); |
293 } | 298 } |
294 | 299 |
295 } // namespace policy | 300 } // namespace policy |
OLD | NEW |