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

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

Issue 1923943003: Add logging to remote commands (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Syslog logging in upload_job_impl Created 4 years, 6 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"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/chromeos/logging.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"
15 #include "base/sys_info.h"
14 #include "chrome/browser/chromeos/policy/device_local_account.h" 16 #include "chrome/browser/chromeos/policy/device_local_account.h"
15 #include "chrome/browser/chromeos/policy/device_status_collector.h" 17 #include "chrome/browser/chromeos/policy/device_status_collector.h"
16 #include "chromeos/settings/cros_settings_names.h" 18 #include "chromeos/settings/cros_settings_names.h"
17 #include "chromeos/settings/cros_settings_provider.h" 19 #include "chromeos/settings/cros_settings_provider.h"
18 #include "components/policy/core/common/cloud/cloud_policy_client.h" 20 #include "components/policy/core/common/cloud/cloud_policy_client.h"
19 #include "components/policy/core/common/cloud/device_management_service.h" 21 #include "components/policy/core/common/cloud/device_management_service.h"
20 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/media_request_state.h" 23 #include "content/public/browser/media_request_state.h"
22 #include "content/public/common/media_stream_request.h" 24 #include "content/public/common/media_stream_request.h"
23 #include "ui/base/user_activity/user_activity_detector.h" 25 #include "ui/base/user_activity/user_activity_detector.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 base::Bind(&StatusUploader::RefreshUploadFrequency, 102 base::Bind(&StatusUploader::RefreshUploadFrequency,
101 weak_factory_.GetWeakPtr()))) { 103 weak_factory_.GetWeakPtr()))) {
102 return; 104 return;
103 } 105 }
104 106
105 // CrosSettings are trusted - update our cached upload_frequency (we cache the 107 // CrosSettings are trusted - update our cached upload_frequency (we cache the
106 // value because CrosSettings can become untrusted at arbitrary times and we 108 // value because CrosSettings can become untrusted at arbitrary times and we
107 // want to use the last trusted value). 109 // want to use the last trusted value).
108 int frequency; 110 int frequency;
109 if (settings->GetInteger(chromeos::kReportUploadFrequency, &frequency)) { 111 if (settings->GetInteger(chromeos::kReportUploadFrequency, &frequency)) {
110 LOG(WARNING) << "Changing status upload frequency from " 112 CHROMEOS_SYSLOG(WARNING) << "Changing status upload frequency from "
111 << upload_frequency_ << " to " 113 << upload_frequency_ << " to "
112 << base::TimeDelta::FromMilliseconds(frequency); 114 << base::TimeDelta::FromMilliseconds(frequency);
113 upload_frequency_ = base::TimeDelta::FromMilliseconds( 115 upload_frequency_ = base::TimeDelta::FromMilliseconds(
114 std::max(kMinUploadDelayMs, frequency)); 116 std::max(kMinUploadDelayMs, frequency));
115 } 117 }
116 118
117 // Schedule a new upload with the new frequency - only do this if we've 119 // Schedule a new upload with the new frequency - only do this if we've
118 // already performed the initial upload, because we want the initial upload 120 // already performed the initial upload, because we want the initial upload
119 // to happen in a minute after startup and not get cancelled by settings 121 // to happen in a minute after startup and not get cancelled by settings
120 // changes. 122 // changes.
121 if (!last_upload_.is_null()) 123 if (!last_upload_.is_null())
122 ScheduleNextStatusUpload(); 124 ScheduleNextStatusUpload();
123 } 125 }
124 126
125 bool StatusUploader::IsSessionDataUploadAllowed() { 127 bool StatusUploader::IsSessionDataUploadAllowed() {
126 // Check if we're in an auto-launched kiosk session. 128 // Check if we're in an auto-launched kiosk session.
127 std::unique_ptr<DeviceLocalAccount> account = 129 std::unique_ptr<DeviceLocalAccount> account =
128 collector_->GetAutoLaunchedKioskSessionInfo(); 130 collector_->GetAutoLaunchedKioskSessionInfo();
129 if (!account) 131 if (!account) {
132 CHROMEOS_SYSLOG(WARNING)
133 << "Not a kiosk session, data upload is not allowed.";
130 return false; 134 return false;
135 }
131 136
132 // Check if there has been any user input. 137 // Check if there has been any user input.
133 if (!ui::UserActivityDetector::Get()->last_activity_time().is_null()) 138 base::TimeTicks last_activity_time =
139 ui::UserActivityDetector::Get()->last_activity_time();
140 std::string last_activity_name =
141 ui::UserActivityDetector::Get()->last_activity_name();
142 if (!last_activity_time.is_null()) {
143 CHROMEOS_SYSLOG(WARNING)
144 << "User input " << last_activity_name << " detected "
145 << (base::TimeTicks::Now() - last_activity_time) << " ago ("
146 << (base::SysInfo::Uptime() -
147 (base::TimeTicks::Now() - last_activity_time))
148 << " after last boot), data upload is not allowed.";
134 return false; 149 return false;
150 }
135 151
136 // Screenshot is allowed as long as we have not captured media. 152 // Screenshot is allowed as long as we have not captured media.
137 return !has_captured_media_; 153 if (has_captured_media_) {
154 CHROMEOS_SYSLOG(WARNING)
155 << "Media has been captured, data upload is not allowed.";
156 return false;
157 } else {
158 return true;
159 }
138 } 160 }
139 161
140 void StatusUploader::OnRequestUpdate(int render_process_id, 162 void StatusUploader::OnRequestUpdate(int render_process_id,
141 int render_frame_id, 163 int render_frame_id,
142 content::MediaStreamType stream_type, 164 content::MediaStreamType stream_type,
143 const content::MediaRequestState state) { 165 const content::MediaRequestState state) {
144 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 166 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
145 // If a video or audio capture stream is opened, set a flag so we disallow 167 // If a video or audio capture stream is opened, set a flag so we disallow
146 // upload of potentially sensitive data. 168 // upload of potentially sensitive data.
147 if (state == content::MEDIA_REQUEST_STATE_OPENING && 169 if (state == content::MEDIA_REQUEST_STATE_OPENING &&
148 (stream_type == content::MEDIA_DEVICE_AUDIO_CAPTURE || 170 (stream_type == content::MEDIA_DEVICE_AUDIO_CAPTURE ||
149 stream_type == content::MEDIA_DEVICE_VIDEO_CAPTURE)) { 171 stream_type == content::MEDIA_DEVICE_VIDEO_CAPTURE)) {
150 has_captured_media_ = true; 172 has_captured_media_ = true;
151 } 173 }
152 } 174 }
153 175
154 void StatusUploader::UploadStatus() { 176 void StatusUploader::UploadStatus() {
155 enterprise_management::DeviceStatusReportRequest device_status; 177 enterprise_management::DeviceStatusReportRequest device_status;
156 bool have_device_status = collector_->GetDeviceStatus(&device_status); 178 bool have_device_status = collector_->GetDeviceStatus(&device_status);
157 enterprise_management::SessionStatusReportRequest session_status; 179 enterprise_management::SessionStatusReportRequest session_status;
158 bool have_session_status = collector_->GetDeviceSessionStatus( 180 bool have_session_status = collector_->GetDeviceSessionStatus(
159 &session_status); 181 &session_status);
160 if (!have_device_status && !have_session_status) { 182 if (!have_device_status && !have_session_status) {
161 LOG(WARNING) << "Skipping status upload because no data to upload"; 183 CHROMEOS_SYSLOG(WARNING)
184 << "Skipping status upload because no data to upload";
162 // Don't have any status to upload - just set our timer for next time. 185 // Don't have any status to upload - just set our timer for next time.
163 last_upload_ = base::Time::NowFromSystemTime(); 186 last_upload_ = base::Time::NowFromSystemTime();
164 ScheduleNextStatusUpload(); 187 ScheduleNextStatusUpload();
165 return; 188 return;
166 } 189 }
167 190
168 LOG(WARNING) << "Starting status upload: have_device_status = " 191 CHROMEOS_SYSLOG(WARNING) << "Starting status upload: have_device_status = "
169 << have_device_status; 192 << have_device_status;
170 client_->UploadDeviceStatus( 193 client_->UploadDeviceStatus(
171 have_device_status ? &device_status : nullptr, 194 have_device_status ? &device_status : nullptr,
172 have_session_status ? &session_status : nullptr, 195 have_session_status ? &session_status : nullptr,
173 base::Bind(&StatusUploader::OnUploadCompleted, 196 base::Bind(&StatusUploader::OnUploadCompleted,
174 weak_factory_.GetWeakPtr())); 197 weak_factory_.GetWeakPtr()));
175 } 198 }
176 199
177 void StatusUploader::OnUploadCompleted(bool success) { 200 void StatusUploader::OnUploadCompleted(bool success) {
178 // Set the last upload time, regardless of whether the upload was successful 201 // Set the last upload time, regardless of whether the upload was successful
179 // or not (we don't change the time of the next upload based on whether this 202 // or not (we don't change the time of the next upload based on whether this
180 // upload succeeded or not - if a status upload fails, we just skip it and 203 // upload succeeded or not - if a status upload fails, we just skip it and
181 // wait until it's time to try again. 204 // wait until it's time to try again.
182 LOG_IF(ERROR, !success) << "Error uploading status: " << client_->status(); 205 CHROMEOS_SYSLOG_IF(ERROR, !success) << "Error uploading status: "
183 LOG_IF(WARNING, success) << "Status upload successful"; 206 << client_->status();
207 CHROMEOS_SYSLOG_IF(WARNING, success) << "Status upload successful";
184 last_upload_ = base::Time::NowFromSystemTime(); 208 last_upload_ = base::Time::NowFromSystemTime();
185 209
186 // If the upload was successful, tell the collector so it can clear its cache 210 // If the upload was successful, tell the collector so it can clear its cache
187 // of pending items. 211 // of pending items.
188 if (success) 212 if (success)
189 collector_->OnSubmittedSuccessfully(); 213 collector_->OnSubmittedSuccessfully();
190 214
191 ScheduleNextStatusUpload(); 215 ScheduleNextStatusUpload();
192 } 216 }
193 217
194 } // namespace policy 218 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698