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

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

Issue 2765463002: Remote fetch device status (attributes and logs) command (Closed)
Patch Set: Addressed Drew's comments, treating StatusUploader and SystemLogUploader as one Created 3 years, 9 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
index fce6ed186bb2d712d07869f4996b1ba092029b07..38a7df2f9f315abbd8e0b378be26b55e4625b7f2 100644
--- a/chrome/browser/chromeos/policy/system_log_uploader.cc
+++ b/chrome/browser/chromeos/policy/system_log_uploader.cc
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "chrome/browser/chromeos/policy/system_log_uploader.h"
+
+#include <map>
#include <utility>
#include "base/bind.h"
@@ -22,7 +25,6 @@
#include "components/feedback/anonymizer_tool.h"
#include "components/policy/core/browser/browser_policy_connector.h"
#include "net/http/http_request_headers.h"
-#include "system_log_uploader.h"
namespace {
// The maximum number of successive retries.
@@ -200,6 +202,7 @@ void SystemLogUploader::OnSuccess() {
SYSLOG(INFO) << "Upload successful.";
upload_job_.reset();
last_upload_attempt_ = base::Time::NowFromSystemTime();
+ log_upload_in_progress_ = false;
retry_count_ = 0;
// On successful log upload schedule the next log upload after
@@ -210,6 +213,7 @@ void SystemLogUploader::OnSuccess() {
void SystemLogUploader::OnFailure(UploadJob::ErrorCode error_code) {
upload_job_.reset();
last_upload_attempt_ = base::Time::NowFromSystemTime();
+ log_upload_in_progress_ = false;
// If we have hit the maximum number of retries, terminate this upload
// attempt and schedule the next one using the normal delay. Otherwise, retry
@@ -235,6 +239,10 @@ std::string SystemLogUploader::RemoveSensitiveData(
return anonymizer->Anonymize(data);
}
+void SystemLogUploader::ScheduleNextSystemLogUploadImmediately() {
+ ScheduleNextSystemLogUpload(base::TimeDelta());
+}
+
void SystemLogUploader::RefreshUploadSettings() {
// Attempt to fetch the current value of the reporting settings.
// If trusted values are not available, register this function to be called
@@ -289,10 +297,12 @@ void SystemLogUploader::StartLogUpload() {
if (upload_enabled_) {
SYSLOG(INFO) << "Starting system log upload.";
+ log_upload_in_progress_ = true;
syslog_delegate_->LoadSystemLogs(base::Bind(
&SystemLogUploader::UploadSystemLogs, weak_factory_.GetWeakPtr()));
} else {
// If upload is disabled, schedule the next attempt after 12h.
+ SYSLOG(INFO) << "System log upload is disabled, rescheduling.";
retry_count_ = 0;
last_upload_attempt_ = base::Time::NowFromSystemTime();
ScheduleNextSystemLogUpload(upload_frequency_);
@@ -300,12 +310,21 @@ void SystemLogUploader::StartLogUpload() {
}
void SystemLogUploader::ScheduleNextSystemLogUpload(base::TimeDelta frequency) {
+ // Don't schedule a new system log upload if there's a log upload in progress
+ // (it will be scheduled once the current one completes).
+ if (log_upload_in_progress_) {
+ SYSLOG(INFO) << "In the middle of a system log upload, not scheduling the "
+ << "next one until this one finishes.";
+ return;
+ }
+
// Calculate when to fire off the next update.
base::TimeDelta delay = std::max(
(last_upload_attempt_ + frequency) - base::Time::NowFromSystemTime(),
base::TimeDelta());
SYSLOG(INFO) << "Scheduling next system log upload " << delay << " from now.";
- // Ensure that we never have more than one pending delayed task.
+ // Ensure that we never have more than one pending delayed task
+ // (InvalidateWeakPtrs() will cancel any pending log uploads).
weak_factory_.InvalidateWeakPtrs();
task_runner_->PostDelayedTask(FROM_HERE,
base::Bind(&SystemLogUploader::StartLogUpload,

Powered by Google App Engine
This is Rietveld 408576698