OLD | NEW |
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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "chrome/browser/chromeos/policy/device_local_account.h" |
13 #include "chrome/browser/chromeos/policy/device_status_collector.h" | 14 #include "chrome/browser/chromeos/policy/device_status_collector.h" |
14 #include "chromeos/settings/cros_settings_names.h" | 15 #include "chromeos/settings/cros_settings_names.h" |
15 #include "chromeos/settings/cros_settings_provider.h" | 16 #include "chromeos/settings/cros_settings_provider.h" |
16 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 17 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
17 #include "components/policy/core/common/cloud/device_management_service.h" | 18 #include "components/policy/core/common/cloud/device_management_service.h" |
| 19 #include "ui/base/user_activity/user_activity_detector.h" |
18 | 20 |
19 namespace { | 21 namespace { |
20 const int kMinUploadDelayMs = 60 * 1000; // 60 seconds | 22 const int kMinUploadDelayMs = 60 * 1000; // 60 seconds |
21 } // namespace | 23 } // namespace |
22 | 24 |
23 namespace policy { | 25 namespace policy { |
24 | 26 |
25 const int64 StatusUploader::kDefaultUploadDelayMs = | 27 const int64 StatusUploader::kDefaultUploadDelayMs = |
26 3 * 60 * 60 * 1000; // 3 hours | 28 3 * 60 * 60 * 1000; // 3 hours |
27 | 29 |
| 30 StatusUploader::StatusUploader() : weak_factory_(this) { |
| 31 } |
| 32 |
28 StatusUploader::StatusUploader( | 33 StatusUploader::StatusUploader( |
29 CloudPolicyClient* client, | 34 CloudPolicyClient* client, |
30 scoped_ptr<DeviceStatusCollector> collector, | 35 scoped_ptr<DeviceStatusCollector> collector, |
31 const scoped_refptr<base::SequencedTaskRunner>& task_runner) | 36 const scoped_refptr<base::SequencedTaskRunner>& task_runner) |
32 : client_(client), | 37 : client_(client), |
33 collector_(collector.Pass()), | 38 collector_(collector.Pass()), |
34 task_runner_(task_runner), | 39 task_runner_(task_runner), |
35 upload_frequency_(base::TimeDelta::FromMilliseconds( | 40 upload_frequency_(base::TimeDelta::FromMilliseconds( |
36 kDefaultUploadDelayMs)), | 41 kDefaultUploadDelayMs)), |
37 weak_factory_(this) { | 42 weak_factory_(this) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 std::max(kMinUploadDelayMs, frequency)); | 101 std::max(kMinUploadDelayMs, frequency)); |
97 } | 102 } |
98 | 103 |
99 // Schedule a new upload with the new frequency - only do this if we've | 104 // Schedule a new upload with the new frequency - only do this if we've |
100 // already performed the initial upload, because we want the initial upload | 105 // already performed the initial upload, because we want the initial upload |
101 // to happen immediately on startup and not get cancelled by settings changes. | 106 // to happen immediately on startup and not get cancelled by settings changes. |
102 if (!last_upload_.is_null()) | 107 if (!last_upload_.is_null()) |
103 ScheduleNextStatusUpload(); | 108 ScheduleNextStatusUpload(); |
104 } | 109 } |
105 | 110 |
| 111 bool StatusUploader::IsSessionDataUploadAllowed() { |
| 112 // Check if we're in an auto-launched kiosk session. |
| 113 scoped_ptr<DeviceLocalAccount> account = |
| 114 collector_->GetAutoLaunchedKioskSessionInfo(); |
| 115 if (!account) |
| 116 return false; |
| 117 |
| 118 // Check if there has been any user input. |
| 119 if (!ui::UserActivityDetector::Get()->last_activity_time().is_null()) |
| 120 return false; |
| 121 |
| 122 // TODO(atwilson): Check if we've captured any audio/video data |
| 123 // (http://crbug.com/487261). |
| 124 return true; |
| 125 } |
| 126 |
106 void StatusUploader::UploadStatus() { | 127 void StatusUploader::UploadStatus() { |
107 enterprise_management::DeviceStatusReportRequest device_status; | 128 enterprise_management::DeviceStatusReportRequest device_status; |
108 bool have_device_status = collector_->GetDeviceStatus(&device_status); | 129 bool have_device_status = collector_->GetDeviceStatus(&device_status); |
109 enterprise_management::SessionStatusReportRequest session_status; | 130 enterprise_management::SessionStatusReportRequest session_status; |
110 bool have_session_status = collector_->GetDeviceSessionStatus( | 131 bool have_session_status = collector_->GetDeviceSessionStatus( |
111 &session_status); | 132 &session_status); |
112 if (!have_device_status && !have_session_status) { | 133 if (!have_device_status && !have_session_status) { |
113 // Don't have any status to upload - just set our timer for next time. | 134 // Don't have any status to upload - just set our timer for next time. |
114 last_upload_ = base::Time::NowFromSystemTime(); | 135 last_upload_ = base::Time::NowFromSystemTime(); |
115 ScheduleNextStatusUpload(); | 136 ScheduleNextStatusUpload(); |
(...skipping 16 matching lines...) Expand all Loading... |
132 | 153 |
133 // If the upload was successful, tell the collector so it can clear its cache | 154 // If the upload was successful, tell the collector so it can clear its cache |
134 // of pending items. | 155 // of pending items. |
135 if (success) | 156 if (success) |
136 collector_->OnSubmittedSuccessfully(); | 157 collector_->OnSubmittedSuccessfully(); |
137 | 158 |
138 ScheduleNextStatusUpload(); | 159 ScheduleNextStatusUpload(); |
139 } | 160 } |
140 | 161 |
141 } // namespace policy | 162 } // namespace policy |
OLD | NEW |