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

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

Issue 2765463002: Remote fetch device status (attributes and logs) command (Closed)
Patch Set: Also added log fetching to command 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/status_uploader.cc
diff --git a/chrome/browser/chromeos/policy/status_uploader.cc b/chrome/browser/chromeos/policy/status_uploader.cc
index 0c42579c80b2a9cfca3f18b12147f6e9412bf4cc..15d485cd9c0ebbcd3884edaa8ba7a2cbe7914d36 100644
--- a/chrome/browser/chromeos/policy/status_uploader.cc
+++ b/chrome/browser/chromeos/policy/status_uploader.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/policy/status_uploader.h"
#include <algorithm>
+#include <string>
#include <utility>
#include "base/bind.h"
@@ -84,12 +85,21 @@ StatusUploader::~StatusUploader() {
MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this);
}
-void StatusUploader::ScheduleNextStatusUpload() {
+void StatusUploader::ScheduleNextStatusUpload(bool immediately) {
+ // Don't schedule a new status upload if there's a status upload in progress
+ // (it will be scheduled once the current one completes).
+ if (status_upload_in_progress_)
Andrew T Wilson (Slow) 2017/03/21 18:03:42 Log something here, as this is a weird exceptional
Ivan Šandrk 2017/03/22 20:20:01 Done.
+ return;
+
// Calculate when to fire off the next update (if it should have already
// happened, this yields a TimeDelta of kMinUploadScheduleDelayMs).
base::TimeDelta delay = std::max(
(last_upload_ + upload_frequency_) - base::Time::NowFromSystemTime(),
base::TimeDelta::FromMilliseconds(kMinUploadScheduleDelayMs));
+ // If we want an immediate status upload, set delay to 0.
+ if (immediately)
+ delay = base::TimeDelta();
+
upload_callback_.Reset(base::Bind(&StatusUploader::UploadStatus,
base::Unretained(this)));
task_runner_->PostDelayedTask(FROM_HERE, upload_callback_.callback(), delay);
@@ -172,7 +182,12 @@ void StatusUploader::OnRequestUpdate(int render_process_id,
}
}
+void StatusUploader::ScheduleNextStatusUploadImmediately() {
+ ScheduleNextStatusUpload(true);
+}
+
void StatusUploader::UploadStatus() {
+ status_upload_in_progress_ = true;
// Gather status in the background.
collector_->GetDeviceAndSessionStatusAsync(base::Bind(
&StatusUploader::OnStatusReceived, weak_factory_.GetWeakPtr()));
@@ -187,6 +202,7 @@ void StatusUploader::OnStatusReceived(
SYSLOG(INFO) << "Skipping status upload because no data to upload";
// Don't have any status to upload - just set our timer for next time.
last_upload_ = base::Time::NowFromSystemTime();
+ status_upload_in_progress_ = false;
ScheduleNextStatusUpload();
return;
}
@@ -209,6 +225,7 @@ void StatusUploader::OnUploadCompleted(bool success) {
SYSLOG(ERROR) << "Error uploading status: " << client_->status();
}
last_upload_ = base::Time::NowFromSystemTime();
+ status_upload_in_progress_ = false;
// If the upload was successful, tell the collector so it can clear its cache
// of pending items.

Powered by Google App Engine
This is Rietveld 408576698