| 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 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_STATUS_UPLOADER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_STATUS_UPLOADER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_STATUS_UPLOADER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_STATUS_UPLOADER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> |
| 11 |
| 10 #include "base/cancelable_callback.h" | 12 #include "base/cancelable_callback.h" |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 17 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | 18 #include "chrome/browser/media/media_capture_devices_dispatcher.h" |
| 18 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 19 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 19 #include "policy/proto/device_management_backend.pb.h" | 20 #include "policy/proto/device_management_backend.pb.h" |
| 20 | 21 |
| 21 namespace base { | 22 namespace base { |
| 22 class SequencedTaskRunner; | 23 class SequencedTaskRunner; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace policy { | 26 namespace policy { |
| 26 | 27 |
| 27 class CloudPolicyClient; | 28 class CloudPolicyClient; |
| 28 class DeviceStatusCollector; | 29 class DeviceStatusCollector; |
| 29 | 30 |
| 30 // Class responsible for periodically uploading device status from the | 31 // Class responsible for periodically uploading device status from the |
| 31 // passed DeviceStatusCollector. | 32 // passed DeviceStatusCollector. |
| 32 class StatusUploader : public MediaCaptureDevicesDispatcher::Observer { | 33 class StatusUploader : public MediaCaptureDevicesDispatcher::Observer { |
| 33 public: | 34 public: |
| 34 // Refresh constants. | 35 // Refresh constants. |
| 35 static const int64_t kDefaultUploadDelayMs; | 36 static const int64_t kDefaultUploadDelayMs; |
| 36 | 37 |
| 37 // Constructor. |client| must be registered and must stay | 38 // Constructor. |client| must be registered and must stay |
| 38 // valid and registered through the lifetime of this StatusUploader | 39 // valid and registered through the lifetime of this StatusUploader |
| 39 // object. | 40 // object. |
| 40 StatusUploader( | 41 StatusUploader(CloudPolicyClient* client, |
| 41 CloudPolicyClient* client, | 42 std::unique_ptr<DeviceStatusCollector> collector, |
| 42 scoped_ptr<DeviceStatusCollector> collector, | 43 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 43 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | |
| 44 | 44 |
| 45 ~StatusUploader() override; | 45 ~StatusUploader() override; |
| 46 | 46 |
| 47 // Returns the time of the last successful upload, or Time(0) if no upload | 47 // Returns the time of the last successful upload, or Time(0) if no upload |
| 48 // has ever happened. | 48 // has ever happened. |
| 49 base::Time last_upload() const { return last_upload_; } | 49 base::Time last_upload() const { return last_upload_; } |
| 50 | 50 |
| 51 // Returns true if session data upload (screenshots, logs, etc) is allowed. | 51 // Returns true if session data upload (screenshots, logs, etc) is allowed. |
| 52 // This checks to ensure that the current session is a kiosk session, and | 52 // This checks to ensure that the current session is a kiosk session, and |
| 53 // that no user input (keyboard, mouse, touch, audio/video) has been received. | 53 // that no user input (keyboard, mouse, touch, audio/video) has been received. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 72 void ScheduleNextStatusUpload(); | 72 void ScheduleNextStatusUpload(); |
| 73 | 73 |
| 74 // Updates the upload frequency from settings and schedules a new upload | 74 // Updates the upload frequency from settings and schedules a new upload |
| 75 // if appropriate. | 75 // if appropriate. |
| 76 void RefreshUploadFrequency(); | 76 void RefreshUploadFrequency(); |
| 77 | 77 |
| 78 // CloudPolicyClient used to issue requests to the server. | 78 // CloudPolicyClient used to issue requests to the server. |
| 79 CloudPolicyClient* client_; | 79 CloudPolicyClient* client_; |
| 80 | 80 |
| 81 // DeviceStatusCollector that provides status for uploading. | 81 // DeviceStatusCollector that provides status for uploading. |
| 82 scoped_ptr<DeviceStatusCollector> collector_; | 82 std::unique_ptr<DeviceStatusCollector> collector_; |
| 83 | 83 |
| 84 // TaskRunner used for scheduling upload tasks. | 84 // TaskRunner used for scheduling upload tasks. |
| 85 const scoped_refptr<base::SequencedTaskRunner> task_runner_; | 85 const scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 86 | 86 |
| 87 // How long to wait between status uploads. | 87 // How long to wait between status uploads. |
| 88 base::TimeDelta upload_frequency_; | 88 base::TimeDelta upload_frequency_; |
| 89 | 89 |
| 90 // Observer to changes in the upload frequency. | 90 // Observer to changes in the upload frequency. |
| 91 scoped_ptr<chromeos::CrosSettings::ObserverSubscription> | 91 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> |
| 92 upload_frequency_observer_; | 92 upload_frequency_observer_; |
| 93 | 93 |
| 94 // The time the last upload was performed. | 94 // The time the last upload was performed. |
| 95 base::Time last_upload_; | 95 base::Time last_upload_; |
| 96 | 96 |
| 97 // Callback invoked via a delay to upload device status. | 97 // Callback invoked via a delay to upload device status. |
| 98 base::CancelableClosure upload_callback_; | 98 base::CancelableClosure upload_callback_; |
| 99 | 99 |
| 100 // True if there has been any captured media in this session. | 100 // True if there has been any captured media in this session. |
| 101 bool has_captured_media_; | 101 bool has_captured_media_; |
| 102 | 102 |
| 103 // Note: This should remain the last member so it'll be destroyed and | 103 // Note: This should remain the last member so it'll be destroyed and |
| 104 // invalidate the weak pointers before any other members are destroyed. | 104 // invalidate the weak pointers before any other members are destroyed. |
| 105 base::WeakPtrFactory<StatusUploader> weak_factory_; | 105 base::WeakPtrFactory<StatusUploader> weak_factory_; |
| 106 | 106 |
| 107 DISALLOW_COPY_AND_ASSIGN(StatusUploader); | 107 DISALLOW_COPY_AND_ASSIGN(StatusUploader); |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 } // namespace policy | 110 } // namespace policy |
| 111 | 111 |
| 112 #endif // CHROME_BROWSER_CHROMEOS_POLICY_STATUS_UPLOADER_H_ | 112 #endif // CHROME_BROWSER_CHROMEOS_POLICY_STATUS_UPLOADER_H_ |
| OLD | NEW |