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..0b61357a09cee7e63b05a7772a704b5424f0222c 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,24 @@ 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_) { |
+ SYSLOG(INFO) << "In the middle of a status upload, not scheduling the next " |
+ << "one until this one finishes."; |
+ 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 +185,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 +205,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 +228,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. |