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

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

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

Powered by Google App Engine
This is Rietveld 408576698