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

Side by Side Diff: chrome/browser/chromeos/policy/status_uploader.cc

Issue 2765463002: Remote fetch device status (attributes and logs) command (Closed)
Patch Set: 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 <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 66 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 77 // 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 78 // start of the epoch, so this will trigger an update in
79 // kMinUploadScheduleDelayMs from now). 79 // kMinUploadScheduleDelayMs from now).
80 ScheduleNextStatusUpload(); 80 ScheduleNextStatusUpload();
81 } 81 }
82 82
83 StatusUploader::~StatusUploader() { 83 StatusUploader::~StatusUploader() {
84 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); 84 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this);
85 } 85 }
86 86
87 void StatusUploader::ScheduleNextStatusUpload() { 87 void StatusUploader::ScheduleNextStatusUpload(bool immediately) {
88 // Calculate when to fire off the next update (if it should have already 88 // Calculate when to fire off the next update (if it should have already
89 // happened, this yields a TimeDelta of kMinUploadScheduleDelayMs). 89 // happened, this yields a TimeDelta of kMinUploadScheduleDelayMs).
90 base::TimeDelta delay = std::max( 90 base::TimeDelta delay = std::max(
91 (last_upload_ + upload_frequency_) - base::Time::NowFromSystemTime(), 91 (last_upload_ + upload_frequency_) - base::Time::NowFromSystemTime(),
92 base::TimeDelta::FromMilliseconds(kMinUploadScheduleDelayMs)); 92 base::TimeDelta::FromMilliseconds(kMinUploadScheduleDelayMs));
93 // If we want an immediate status upload, set delay to 0.
94 if (immediately)
95 delay = base::TimeDelta();
93 upload_callback_.Reset(base::Bind(&StatusUploader::UploadStatus, 96 upload_callback_.Reset(base::Bind(&StatusUploader::UploadStatus,
Andrew T Wilson (Slow) 2017/03/20 16:33:10 My main concern here is that we could have a statu
Ivan Šandrk 2017/03/20 17:48:53 I think it should actually be safe, but I haven't
94 base::Unretained(this))); 97 base::Unretained(this)));
95 task_runner_->PostDelayedTask(FROM_HERE, upload_callback_.callback(), delay); 98 task_runner_->PostDelayedTask(FROM_HERE, upload_callback_.callback(), delay);
96 } 99 }
97 100
98 void StatusUploader::RefreshUploadFrequency() { 101 void StatusUploader::RefreshUploadFrequency() {
99 // Attempt to fetch the current value of the reporting settings. 102 // Attempt to fetch the current value of the reporting settings.
100 // If trusted values are not available, register this function to be called 103 // If trusted values are not available, register this function to be called
101 // back when they are available. 104 // back when they are available.
102 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); 105 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get();
103 if (chromeos::CrosSettingsProvider::TRUSTED != settings->PrepareTrustedValues( 106 if (chromeos::CrosSettingsProvider::TRUSTED != settings->PrepareTrustedValues(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
166 // If a video or audio capture stream is opened, set a flag so we disallow 169 // If a video or audio capture stream is opened, set a flag so we disallow
167 // upload of potentially sensitive data. 170 // upload of potentially sensitive data.
168 if (state == content::MEDIA_REQUEST_STATE_OPENING && 171 if (state == content::MEDIA_REQUEST_STATE_OPENING &&
169 (stream_type == content::MEDIA_DEVICE_AUDIO_CAPTURE || 172 (stream_type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
170 stream_type == content::MEDIA_DEVICE_VIDEO_CAPTURE)) { 173 stream_type == content::MEDIA_DEVICE_VIDEO_CAPTURE)) {
171 has_captured_media_ = true; 174 has_captured_media_ = true;
172 } 175 }
173 } 176 }
174 177
178 void StatusUploader::ScheduleNextStatusUploadImmediately() {
179 ScheduleNextStatusUpload(true);
180 }
181
175 void StatusUploader::UploadStatus() { 182 void StatusUploader::UploadStatus() {
176 // Gather status in the background. 183 // Gather status in the background.
177 collector_->GetDeviceAndSessionStatusAsync(base::Bind( 184 collector_->GetDeviceAndSessionStatusAsync(base::Bind(
178 &StatusUploader::OnStatusReceived, weak_factory_.GetWeakPtr())); 185 &StatusUploader::OnStatusReceived, weak_factory_.GetWeakPtr()));
179 } 186 }
180 187
181 void StatusUploader::OnStatusReceived( 188 void StatusUploader::OnStatusReceived(
182 std::unique_ptr<em::DeviceStatusReportRequest> device_status, 189 std::unique_ptr<em::DeviceStatusReportRequest> device_status,
183 std::unique_ptr<em::SessionStatusReportRequest> session_status) { 190 std::unique_ptr<em::SessionStatusReportRequest> session_status) {
184 bool have_device_status = device_status != nullptr; 191 bool have_device_status = device_status != nullptr;
(...skipping 27 matching lines...) Expand all
212 219
213 // If the upload was successful, tell the collector so it can clear its cache 220 // If the upload was successful, tell the collector so it can clear its cache
214 // of pending items. 221 // of pending items.
215 if (success) 222 if (success)
216 collector_->OnSubmittedSuccessfully(); 223 collector_->OnSubmittedSuccessfully();
217 224
218 ScheduleNextStatusUpload(); 225 ScheduleNextStatusUpload();
219 } 226 }
220 227
221 } // namespace policy 228 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698