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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_STATUS_UPLOADER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_STATUS_UPLOADER_H_
8 #include "base/cancelable_callback.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/time/time.h"
13 #include "chrome/browser/chromeos/settings/cros_settings.h"
14 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
15 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
16 #include "policy/proto/device_management_backend.pb.h"
19 class SequencedTaskRunner
;
24 class CloudPolicyClient
;
25 class DeviceStatusCollector
;
27 // Class responsible for periodically uploading device status from the
28 // passed DeviceStatusCollector.
29 class StatusUploader
: public MediaCaptureDevicesDispatcher::Observer
{
32 static const int64 kDefaultUploadDelayMs
;
34 // Constructor. |client| must be registered and must stay
35 // valid and registered through the lifetime of this StatusUploader
38 CloudPolicyClient
* client
,
39 scoped_ptr
<DeviceStatusCollector
> collector
,
40 const scoped_refptr
<base::SequencedTaskRunner
>& task_runner
);
42 ~StatusUploader() override
;
44 // Returns the time of the last successful upload, or Time(0) if no upload
46 base::Time
last_upload() const { return last_upload_
; }
48 // Returns true if session data upload (screenshots, logs, etc) is allowed.
49 // This checks to ensure that the current session is a kiosk session, and
50 // that no user input (keyboard, mouse, touch, audio/video) has been received.
51 bool IsSessionDataUploadAllowed();
53 // MediaCaptureDevicesDispatcher::Observer implementation
54 void OnRequestUpdate(int render_process_id
,
56 content::MediaStreamType stream_type
,
57 const content::MediaRequestState state
) override
;
60 // Callback invoked periodically to upload the device status from the
61 // DeviceStatusCollector.
64 // Invoked once a status upload has completed.
65 void OnUploadCompleted(bool success
);
67 // Helper method that figures out when the next status upload should
69 void ScheduleNextStatusUpload();
71 // Updates the upload frequency from settings and schedules a new upload
73 void RefreshUploadFrequency();
75 // CloudPolicyClient used to issue requests to the server.
76 CloudPolicyClient
* client_
;
78 // DeviceStatusCollector that provides status for uploading.
79 scoped_ptr
<DeviceStatusCollector
> collector_
;
81 // TaskRunner used for scheduling upload tasks.
82 const scoped_refptr
<base::SequencedTaskRunner
> task_runner_
;
84 // How long to wait between status uploads.
85 base::TimeDelta upload_frequency_
;
87 // Observer to changes in the upload frequency.
88 scoped_ptr
<chromeos::CrosSettings::ObserverSubscription
>
89 upload_frequency_observer_
;
91 // The time the last upload was performed.
92 base::Time last_upload_
;
94 // Callback invoked via a delay to upload device status.
95 base::CancelableClosure upload_callback_
;
97 // True if there has been any captured media in this session.
98 bool has_captured_media_
;
100 // Note: This should remain the last member so it'll be destroyed and
101 // invalidate the weak pointers before any other members are destroyed.
102 base::WeakPtrFactory
<StatusUploader
> weak_factory_
;
104 DISALLOW_COPY_AND_ASSIGN(StatusUploader
);
107 } // namespace policy
109 #endif // CHROME_BROWSER_CHROMEOS_POLICY_STATUS_UPLOADER_H_