| 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 #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/location.h" | 12 #include "base/location.h" |
| 13 #include "base/sequenced_task_runner.h" | 13 #include "base/sequenced_task_runner.h" |
| 14 #include "chrome/browser/chromeos/policy/device_local_account.h" | 14 #include "chrome/browser/chromeos/policy/device_local_account.h" |
| 15 #include "chrome/browser/chromeos/policy/device_status_collector.h" | 15 #include "chrome/browser/chromeos/policy/device_status_collector.h" |
| 16 #include "chromeos/settings/cros_settings_names.h" | 16 #include "chromeos/settings/cros_settings_names.h" |
| 17 #include "chromeos/settings/cros_settings_provider.h" | 17 #include "chromeos/settings/cros_settings_provider.h" |
| 18 #include "components/policy/core/common/cloud/cloud_policy_client.h" | 18 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
| 19 #include "components/policy/core/common/cloud/device_management_service.h" | 19 #include "components/policy/core/common/cloud/device_management_service.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/media_request_state.h" | 21 #include "content/public/browser/media_request_state.h" |
| 22 #include "content/public/common/media_stream_request.h" | 22 #include "content/public/common/media_stream_request.h" |
| 23 #include "ui/base/user_activity/user_activity_detector.h" | 23 #include "ui/base/user_activity/user_activity_detector.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 // Minimum delay between two consecutive uploads |
| 26 const int kMinUploadDelayMs = 60 * 1000; // 60 seconds | 27 const int kMinUploadDelayMs = 60 * 1000; // 60 seconds |
| 28 // Minimum delay after scheduling an upload |
| 29 const int kMinUploadScheduleDelayMs = 60 * 1000; // 60 seconds |
| 27 } // namespace | 30 } // namespace |
| 28 | 31 |
| 29 namespace policy { | 32 namespace policy { |
| 30 | 33 |
| 31 const int64_t StatusUploader::kDefaultUploadDelayMs = | 34 const int64_t StatusUploader::kDefaultUploadDelayMs = |
| 32 3 * 60 * 60 * 1000; // 3 hours | 35 3 * 60 * 60 * 1000; // 3 hours |
| 33 | 36 |
| 34 StatusUploader::StatusUploader( | 37 StatusUploader::StatusUploader( |
| 35 CloudPolicyClient* client, | 38 CloudPolicyClient* client, |
| 36 std::unique_ptr<DeviceStatusCollector> collector, | 39 std::unique_ptr<DeviceStatusCollector> collector, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 60 // server. | 63 // server. |
| 61 upload_frequency_observer_ = | 64 upload_frequency_observer_ = |
| 62 chromeos::CrosSettings::Get()->AddSettingsObserver( | 65 chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 63 chromeos::kReportUploadFrequency, | 66 chromeos::kReportUploadFrequency, |
| 64 base::Bind(&StatusUploader::RefreshUploadFrequency, | 67 base::Bind(&StatusUploader::RefreshUploadFrequency, |
| 65 base::Unretained(this))); | 68 base::Unretained(this))); |
| 66 | 69 |
| 67 // Update the upload frequency from settings. | 70 // Update the upload frequency from settings. |
| 68 RefreshUploadFrequency(); | 71 RefreshUploadFrequency(); |
| 69 | 72 |
| 70 // Immediately schedule our next status upload (last_upload_ is set to the | 73 // Schedule our next status upload in a minute (last_upload_ is set to the |
| 71 // start of the epoch, so this will trigger an update in the immediate | 74 // start of the epoch, so this will trigger an update in |
| 72 // future). | 75 // kMinUploadScheduleDelayMs from now). |
| 73 ScheduleNextStatusUpload(); | 76 ScheduleNextStatusUpload(); |
| 74 } | 77 } |
| 75 | 78 |
| 76 StatusUploader::~StatusUploader() { | 79 StatusUploader::~StatusUploader() { |
| 77 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); | 80 MediaCaptureDevicesDispatcher::GetInstance()->RemoveObserver(this); |
| 78 } | 81 } |
| 79 | 82 |
| 80 void StatusUploader::ScheduleNextStatusUpload() { | 83 void StatusUploader::ScheduleNextStatusUpload() { |
| 81 // Calculate when to fire off the next update (if it should have already | 84 // Calculate when to fire off the next update (if it should have already |
| 82 // happened, this yields a TimeDelta of 0). | 85 // happened, this yields a TimeDelta of kMinUploadScheduleDelayMs). |
| 83 base::TimeDelta delay = std::max( | 86 base::TimeDelta delay = std::max( |
| 84 (last_upload_ + upload_frequency_) - base::Time::NowFromSystemTime(), | 87 (last_upload_ + upload_frequency_) - base::Time::NowFromSystemTime(), |
| 85 base::TimeDelta()); | 88 base::TimeDelta::FromMilliseconds(kMinUploadScheduleDelayMs)); |
| 86 upload_callback_.Reset(base::Bind(&StatusUploader::UploadStatus, | 89 upload_callback_.Reset(base::Bind(&StatusUploader::UploadStatus, |
| 87 base::Unretained(this))); | 90 base::Unretained(this))); |
| 88 task_runner_->PostDelayedTask(FROM_HERE, upload_callback_.callback(), delay); | 91 task_runner_->PostDelayedTask(FROM_HERE, upload_callback_.callback(), delay); |
| 89 } | 92 } |
| 90 | 93 |
| 91 void StatusUploader::RefreshUploadFrequency() { | 94 void StatusUploader::RefreshUploadFrequency() { |
| 92 // Attempt to fetch the current value of the reporting settings. | 95 // Attempt to fetch the current value of the reporting settings. |
| 93 // If trusted values are not available, register this function to be called | 96 // If trusted values are not available, register this function to be called |
| 94 // back when they are available. | 97 // back when they are available. |
| 95 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); | 98 chromeos::CrosSettings* settings = chromeos::CrosSettings::Get(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 106 if (settings->GetInteger(chromeos::kReportUploadFrequency, &frequency)) { | 109 if (settings->GetInteger(chromeos::kReportUploadFrequency, &frequency)) { |
| 107 LOG(WARNING) << "Changing status upload frequency from " | 110 LOG(WARNING) << "Changing status upload frequency from " |
| 108 << upload_frequency_ << " to " | 111 << upload_frequency_ << " to " |
| 109 << base::TimeDelta::FromMilliseconds(frequency); | 112 << base::TimeDelta::FromMilliseconds(frequency); |
| 110 upload_frequency_ = base::TimeDelta::FromMilliseconds( | 113 upload_frequency_ = base::TimeDelta::FromMilliseconds( |
| 111 std::max(kMinUploadDelayMs, frequency)); | 114 std::max(kMinUploadDelayMs, frequency)); |
| 112 } | 115 } |
| 113 | 116 |
| 114 // Schedule a new upload with the new frequency - only do this if we've | 117 // Schedule a new upload with the new frequency - only do this if we've |
| 115 // already performed the initial upload, because we want the initial upload | 118 // already performed the initial upload, because we want the initial upload |
| 116 // to happen immediately on startup and not get cancelled by settings changes. | 119 // to happen in a minute after startup and not get cancelled by settings |
| 120 // changes. |
| 117 if (!last_upload_.is_null()) | 121 if (!last_upload_.is_null()) |
| 118 ScheduleNextStatusUpload(); | 122 ScheduleNextStatusUpload(); |
| 119 } | 123 } |
| 120 | 124 |
| 121 bool StatusUploader::IsSessionDataUploadAllowed() { | 125 bool StatusUploader::IsSessionDataUploadAllowed() { |
| 122 // Check if we're in an auto-launched kiosk session. | 126 // Check if we're in an auto-launched kiosk session. |
| 123 std::unique_ptr<DeviceLocalAccount> account = | 127 std::unique_ptr<DeviceLocalAccount> account = |
| 124 collector_->GetAutoLaunchedKioskSessionInfo(); | 128 collector_->GetAutoLaunchedKioskSessionInfo(); |
| 125 if (!account) | 129 if (!account) |
| 126 return false; | 130 return false; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 | 185 |
| 182 // If the upload was successful, tell the collector so it can clear its cache | 186 // If the upload was successful, tell the collector so it can clear its cache |
| 183 // of pending items. | 187 // of pending items. |
| 184 if (success) | 188 if (success) |
| 185 collector_->OnSubmittedSuccessfully(); | 189 collector_->OnSubmittedSuccessfully(); |
| 186 | 190 |
| 187 ScheduleNextStatusUpload(); | 191 ScheduleNextStatusUpload(); |
| 188 } | 192 } |
| 189 | 193 |
| 190 } // namespace policy | 194 } // namespace policy |
| OLD | NEW |