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

Unified Diff: chrome/browser/chromeos/policy/system_log_uploader.cc

Issue 1193333017: Added system log uploader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added FileReader - helper class that reads files thread safely. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/system_log_uploader.cc
diff --git a/chrome/browser/chromeos/policy/system_log_uploader.cc b/chrome/browser/chromeos/policy/system_log_uploader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..eb326b24b1a4cf4cd4a1e7ccf8d7da99e9828bf0
--- /dev/null
+++ b/chrome/browser/chromeos/policy/system_log_uploader.cc
@@ -0,0 +1,90 @@
+// Copyright (c) 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/location.h"
+#include "chrome/browser/chromeos/policy/system_log_delegate.h"
+#include "chrome/browser/chromeos/policy/system_log_uploader.h"
+
+namespace {
+// Determines the time between log uploads.
+const int64 kDefaultUploadDelayMs = 12 * 60 * 60 * 1000; // 12 hours
+
+// Determines the time, measured from the time of last failed upload,
+// after which the log upload is retried.
+const int64 kErrorUploadDelayMs = 120 * 1000; // 120 seconds
+
+} // namespace
+
+namespace policy {
+
+SystemLogUploader::SystemLogUploader(
+ const scoped_refptr<base::SequencedTaskRunner>& task_runner)
+ : retrying_(true),
+ upload_frequency_(
+ base::TimeDelta::FromMilliseconds(kDefaultUploadDelayMs)),
+ last_upload_attempt_(base::Time::NowFromSystemTime()),
+ task_runner_(task_runner),
+ weak_factory_(this) {
+ upload_job_.reset();
Andrew T Wilson (Slow) 2015/07/03 15:40:48 Why is this here? Doesn't upload_job_ start as NUL
Polina Bondarenko 2015/07/08 10:07:24 Done.
+
+ // Immediately schedule the next system log upload after upload_frequency_
+ // time from now.
+ ScheduleNextSystemLogUpload(upload_frequency_);
Andrew T Wilson (Slow) 2015/07/03 15:40:48 This means that if you have your device setup to r
Polina Bondarenko 2015/07/08 10:07:24 Sounds good, let's upload immediately.
+}
+
+SystemLogUploader::~SystemLogUploader() {
+ upload_job_.reset();
Andrew T Wilson (Slow) 2015/07/03 15:40:48 Why do this here instead of letting the default de
Polina Bondarenko 2015/07/08 10:07:23 Done.
+}
+
+SystemLogUploadJob* SystemLogUploader::CreateSystemLogUploadJob() {
+ return new SystemLogUploadJob(make_scoped_ptr(new SystemLogDelegate()));
Andrew T Wilson (Slow) 2015/07/03 15:40:48 Is SystemLogDelegate used outside this file? Shoul
Polina Bondarenko 2015/07/08 10:07:23 Yes, fixed.
+}
+
+void SystemLogUploader::OnSuccess() {
+ // On successful log upload schedule the next log upload after
+ // upload_frequency_ time from now.
+ upload_job_.reset();
+ retrying_ = true;
+ last_upload_attempt_ = base::Time::NowFromSystemTime();
+
+ ScheduleNextSystemLogUpload(upload_frequency_);
+}
+
+void SystemLogUploader::OnFailure() {
+ // On first failure log upload try to re-upload logs after kErrorUploadDelayMs
+ // time from now.
+ upload_job_.reset();
+ last_upload_attempt_ = base::Time::NowFromSystemTime();
+
+ if (retrying_) {
+ ScheduleNextSystemLogUpload(
+ base::TimeDelta::FromMilliseconds(kErrorUploadDelayMs));
+ } else {
+ ScheduleNextSystemLogUpload(upload_frequency_);
+ }
+
+ retrying_ = !retrying_;
Andrew T Wilson (Slow) 2015/07/03 15:40:48 The logic with retry is somewhat confusing. And it
Polina Bondarenko 2015/07/08 10:07:24 Done.
+}
+
+void SystemLogUploader::StartLogUpload() {
+ upload_job_.reset(CreateSystemLogUploadJob());
+ upload_job_->Run(
+ base::Bind(&SystemLogUploader::OnSuccess, weak_factory_.GetWeakPtr()),
+ base::Bind(&SystemLogUploader::OnFailure, weak_factory_.GetWeakPtr()));
+}
+
+void SystemLogUploader::ScheduleNextSystemLogUpload(base::TimeDelta frequency) {
+ // Calculate when to fire off the next update.
+ base::TimeDelta delay = std::max(
+ (last_upload_attempt_ + frequency) - base::Time::NowFromSystemTime(),
+ base::TimeDelta());
+ task_runner_->PostDelayedTask(FROM_HERE,
+ base::Bind(&SystemLogUploader::StartLogUpload,
+ weak_factory_.GetWeakPtr()),
+ delay);
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698