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

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

Issue 1216643002: Added unittests for SystemLogUploader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed according to the main log uploader CL. 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
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "chrome/browser/chromeos/policy/system_log_delegate.h" 8 #include "chrome/browser/chromeos/policy/system_log_delegate.h"
9 #include "chrome/browser/chromeos/policy/system_log_uploader.h" 9 #include "chrome/browser/chromeos/policy/system_log_uploader.h"
10 10
11 namespace { 11 namespace policy {
12 // Determines the time between log uploads. 12 // Determines the time between log uploads.
13 const int64 kDefaultUploadDelayMs = 12 * 60 * 60 * 1000; // 12 hours 13 const int64 SystemLogUploader::kDefaultUploadDelayMs =
14 12 * 60 * 60 * 1000; // 12 hours
14 15
15 // Determines the time, measured from the time of last failed upload, 16 // Determines the time, measured from the time of last failed upload,
16 // after which the log upload is retried. 17 // after which the log upload is retried.
17 const int64 kErrorUploadDelayMs = 120 * 1000; // 120 seconds 18 const int64 SystemLogUploader::kErrorUploadDelayMs = 120 * 1000; // 120 seconds
18
19 } // namespace
20
21 namespace policy {
22 19
23 SystemLogUploader::SystemLogUploader( 20 SystemLogUploader::SystemLogUploader(
24 const scoped_refptr<base::SequencedTaskRunner>& task_runner) 21 const scoped_refptr<base::SequencedTaskRunner>& task_runner)
25 : retrying_(true), 22 : retrying_(true),
26 upload_frequency_( 23 upload_frequency_(
27 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs)), 24 base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs)),
28 last_upload_attempt_(base::Time::NowFromSystemTime()), 25 last_upload_attempt_(base::Time::NowFromSystemTime()),
29 task_runner_(task_runner), 26 task_runner_(task_runner),
30 weak_factory_(this) { 27 weak_factory_(this) {
31 upload_job_.reset(); 28 upload_job_.reset();
32 29
33 // Immediately schedule the next system log upload after upload_frequency_ 30 // Immediately schedule the next system log upload after upload_frequency_
34 // time from now. 31 // time from now.
35 ScheduleNextSystemLogUpload(upload_frequency_); 32 ScheduleNextSystemLogUpload(upload_frequency_);
36 } 33 }
37 34
38 SystemLogUploader::~SystemLogUploader() { 35 SystemLogUploader::~SystemLogUploader() {
39 upload_job_.reset(); 36 upload_job_.reset();
40 } 37 }
41 38
42 SystemLogUploadJob* SystemLogUploader::CreateSystemLogUploadJob() { 39 SystemLogUploadJob* SystemLogUploader::CreateSystemLogUploadJob() {
43 return new SystemLogUploadJob(make_scoped_ptr(new SystemLogDelegate())); 40 return new SystemLogUploadJob(make_scoped_ptr(new SystemLogDelegate()));
44 } 41 }
45 42
46 void SystemLogUploader::OnSuccess() { 43 void SystemLogUploader::OnSuccess() {
47 // On successful log upload schedule next log upload after upload_frequency_ 44 // On successful log upload schedule the next log upload after
48 // time from now. 45 // upload_frequency_ time from now.
49 upload_job_.reset(); 46 upload_job_.reset();
50 retrying_ = true; 47 retrying_ = true;
51 last_upload_attempt_ = base::Time::NowFromSystemTime(); 48 last_upload_attempt_ = base::Time::NowFromSystemTime();
52 49
53 ScheduleNextSystemLogUpload(upload_frequency_); 50 ScheduleNextSystemLogUpload(upload_frequency_);
54 } 51 }
55 52
56 void SystemLogUploader::OnFailure() { 53 void SystemLogUploader::OnFailure() {
57 // On first failure log upload try to re-upload logs after kErrorUploadDelayMs 54 // On first failure log upload try to re-upload logs after kErrorUploadDelayMs
58 // time from now. 55 // time from now.
(...skipping 22 matching lines...) Expand all
81 base::TimeDelta delay = std::max( 78 base::TimeDelta delay = std::max(
82 (last_upload_attempt_ + frequency) - base::Time::NowFromSystemTime(), 79 (last_upload_attempt_ + frequency) - base::Time::NowFromSystemTime(),
83 base::TimeDelta()); 80 base::TimeDelta());
84 task_runner_->PostDelayedTask(FROM_HERE, 81 task_runner_->PostDelayedTask(FROM_HERE,
85 base::Bind(&SystemLogUploader::StartLogUpload, 82 base::Bind(&SystemLogUploader::StartLogUpload,
86 weak_factory_.GetWeakPtr()), 83 weak_factory_.GetWeakPtr()),
87 delay); 84 delay);
88 } 85 }
89 86
90 } // namespace policy 87 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698