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

Side by Side 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 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 "chrome/browser/chromeos/policy/status_uploader.h" 5 #include "chrome/browser/chromeos/policy/status_uploader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string>
8 #include <utility> 9 #include <utility>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
12 #include "base/location.h" 13 #include "base/location.h"
13 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
14 #include "base/sys_info.h" 15 #include "base/sys_info.h"
15 #include "base/syslog_logging.h" 16 #include "base/syslog_logging.h"
16 #include "chrome/browser/chromeos/policy/device_local_account.h" 17 #include "chrome/browser/chromeos/policy/device_local_account.h"
17 #include "chrome/browser/chromeos/policy/device_status_collector.h" 18 #include "chrome/browser/chromeos/policy/device_status_collector.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // Schedule our next status upload in a minute (last_upload_ is set to the 78 // Schedule our next status upload in a minute (last_upload_ is set to the
78 // start of the epoch, so this will trigger an update in 79 // start of the epoch, so this will trigger an update in
79 // kMinUploadScheduleDelayMs from now). 80 // kMinUploadScheduleDelayMs from now).
80 ScheduleNextStatusUpload(); 81 ScheduleNextStatusUpload();
81 } 82 }
82 83
83 StatusUploader::~StatusUploader() { 84 StatusUploader::~StatusUploader() {
84 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); 85 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this);
85 } 86 }
86 87
87 void StatusUploader::ScheduleNextStatusUpload() { 88 void StatusUploader::ScheduleNextStatusUpload(bool immediately) {
89 // Don't schedule a new status upload if there's a status upload in progress
90 // (it will be scheduled once the current one completes).
91 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.
92 return;
93
88 // Calculate when to fire off the next update (if it should have already 94 // Calculate when to fire off the next update (if it should have already
89 // happened, this yields a TimeDelta of kMinUploadScheduleDelayMs). 95 // happened, this yields a TimeDelta of kMinUploadScheduleDelayMs).
90 base::TimeDelta delay = std::max( 96 base::TimeDelta delay = std::max(
91 (last_upload_ + upload_frequency_) - base::Time::NowFromSystemTime(), 97 (last_upload_ + upload_frequency_) - base::Time::NowFromSystemTime(),
92 base::TimeDelta::FromMilliseconds(kMinUploadScheduleDelayMs)); 98 base::TimeDelta::FromMilliseconds(kMinUploadScheduleDelayMs));
99 // If we want an immediate status upload, set delay to 0.
100 if (immediately)
101 delay = base::TimeDelta();
102
93 upload_callback_.Reset(base::Bind(&StatusUploader::UploadStatus, 103 upload_callback_.Reset(base::Bind(&StatusUploader::UploadStatus,
94 base::Unretained(this))); 104 base::Unretained(this)));
95 task_runner_->PostDelayedTask(FROM_HERE, upload_callback_.callback(), delay); 105 task_runner_->PostDelayedTask(FROM_HERE, upload_callback_.callback(), delay);
96 } 106 }
97 107
98 void StatusUploader::RefreshUploadFrequency() { 108 void StatusUploader::RefreshUploadFrequency() {
99 // Attempt to fetch the current value of the reporting settings. 109 // Attempt to fetch the current value of the reporting settings.
100 // If trusted values are not available, register this function to be called 110 // If trusted values are not available, register this function to be called
101 // back when they are available. 111 // back when they are available.
102 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); 112 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 175 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
166 // If a video or audio capture stream is opened, set a flag so we disallow 176 // If a video or audio capture stream is opened, set a flag so we disallow
167 // upload of potentially sensitive data. 177 // upload of potentially sensitive data.
168 if (state == content::MEDIA_REQUEST_STATE_OPENING && 178 if (state == content::MEDIA_REQUEST_STATE_OPENING &&
169 (stream_type == content::MEDIA_DEVICE_AUDIO_CAPTURE || 179 (stream_type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
170 stream_type == content::MEDIA_DEVICE_VIDEO_CAPTURE)) { 180 stream_type == content::MEDIA_DEVICE_VIDEO_CAPTURE)) {
171 has_captured_media_ = true; 181 has_captured_media_ = true;
172 } 182 }
173 } 183 }
174 184
185 void StatusUploader::ScheduleNextStatusUploadImmediately() {
186 ScheduleNextStatusUpload(true);
187 }
188
175 void StatusUploader::UploadStatus() { 189 void StatusUploader::UploadStatus() {
190 status_upload_in_progress_ = true;
176 // Gather status in the background. 191 // Gather status in the background.
177 collector_->GetDeviceAndSessionStatusAsync(base::Bind( 192 collector_->GetDeviceAndSessionStatusAsync(base::Bind(
178 &StatusUploader::OnStatusReceived, weak_factory_.GetWeakPtr())); 193 &StatusUploader::OnStatusReceived, weak_factory_.GetWeakPtr()));
179 } 194 }
180 195
181 void StatusUploader::OnStatusReceived( 196 void StatusUploader::OnStatusReceived(
182 std::unique_ptr<em::DeviceStatusReportRequest> device_status, 197 std::unique_ptr<em::DeviceStatusReportRequest> device_status,
183 std::unique_ptr<em::SessionStatusReportRequest> session_status) { 198 std::unique_ptr<em::SessionStatusReportRequest> session_status) {
184 bool have_device_status = device_status != nullptr; 199 bool have_device_status = device_status != nullptr;
185 bool have_session_status = session_status != nullptr; 200 bool have_session_status = session_status != nullptr;
186 if (!have_device_status && !have_session_status) { 201 if (!have_device_status && !have_session_status) {
187 SYSLOG(INFO) << "Skipping status upload because no data to upload"; 202 SYSLOG(INFO) << "Skipping status upload because no data to upload";
188 // Don't have any status to upload - just set our timer for next time. 203 // Don't have any status to upload - just set our timer for next time.
189 last_upload_ = base::Time::NowFromSystemTime(); 204 last_upload_ = base::Time::NowFromSystemTime();
205 status_upload_in_progress_ = false;
190 ScheduleNextStatusUpload(); 206 ScheduleNextStatusUpload();
191 return; 207 return;
192 } 208 }
193 209
194 SYSLOG(INFO) << "Starting status upload: have_device_status = " 210 SYSLOG(INFO) << "Starting status upload: have_device_status = "
195 << have_device_status; 211 << have_device_status;
196 client_->UploadDeviceStatus(device_status.get(), session_status.get(), 212 client_->UploadDeviceStatus(device_status.get(), session_status.get(),
197 base::Bind(&StatusUploader::OnUploadCompleted, 213 base::Bind(&StatusUploader::OnUploadCompleted,
198 weak_factory_.GetWeakPtr())); 214 weak_factory_.GetWeakPtr()));
199 } 215 }
200 216
201 void StatusUploader::OnUploadCompleted(bool success) { 217 void StatusUploader::OnUploadCompleted(bool success) {
202 // Set the last upload time, regardless of whether the upload was successful 218 // Set the last upload time, regardless of whether the upload was successful
203 // or not (we don't change the time of the next upload based on whether this 219 // or not (we don't change the time of the next upload based on whether this
204 // upload succeeded or not - if a status upload fails, we just skip it and 220 // upload succeeded or not - if a status upload fails, we just skip it and
205 // wait until it's time to try again. 221 // wait until it's time to try again.
206 if (success) { 222 if (success) {
207 SYSLOG(INFO) << "Status upload successful"; 223 SYSLOG(INFO) << "Status upload successful";
208 } else { 224 } else {
209 SYSLOG(ERROR) << "Error uploading status: " << client_->status(); 225 SYSLOG(ERROR) << "Error uploading status: " << client_->status();
210 } 226 }
211 last_upload_ = base::Time::NowFromSystemTime(); 227 last_upload_ = base::Time::NowFromSystemTime();
228 status_upload_in_progress_ = false;
212 229
213 // If the upload was successful, tell the collector so it can clear its cache 230 // If the upload was successful, tell the collector so it can clear its cache
214 // of pending items. 231 // of pending items.
215 if (success) 232 if (success)
216 collector_->OnSubmittedSuccessfully(); 233 collector_->OnSubmittedSuccessfully();
217 234
218 ScheduleNextStatusUpload(); 235 ScheduleNextStatusUpload();
219 } 236 }
220 237
221 } // namespace policy 238 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698