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

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

Issue 845313008: Refactored device status uploading out of policy fetch infrastructure. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback. Created 5 years, 10 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
(Empty)
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_STATUS_UPLOADER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_STATUS_UPLOADER_H_
7
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/prefs/pref_member.h"
13 #include "base/time/time.h"
14 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
15 #include "policy/proto/device_management_backend.pb.h"
16
17 namespace base {
18 class PrefService;
19 class SequencedTaskRunner;
20 }
21
22 namespace policy {
23
24 class CloudPolicyClient;
25 class DeviceManagementRequestJob;
26 class DeviceStatusCollector;
27
28 // Class responsible for periodically uploading device status from the
29 // passed DeviceStatusCollector.
30 class StatusUploader {
31 public:
32 // Refresh constants.
33 static const int64 kDefaultUploadDelayMs;
34
35 // Constructor. |client| must be registered and must stay
36 // valid and registered through the lifetime of this StatusUploader
37 // object.
38 StatusUploader(
39 PrefService* local_state,
40 CloudPolicyClient* client,
41 scoped_ptr<DeviceStatusCollector> collector,
42 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
43
44 ~StatusUploader();
45
46 // Returns the time of the last successful upload, or Time(0) if no upload
47 // has ever happened.
48 base::Time last_upload() const { return last_upload_; }
49
50 private:
51 // Callback invoked periodically to upload the device status from the
52 // DeviceStatusCollector.
53 void UploadStatus();
54
55 // Invoked once a status upload has completed.
56 void OnUploadCompleted(bool success);
57
58 // Helper method that figures out when the next status upload should
59 // be scheduled.
60 void ScheduleNextStatusUpload();
61
62 // CloudPolicyClient used to issue requests to the server.
63 CloudPolicyClient* client_;
64
65 // The job associated with any ongoing requests to the cloud. We currently
66 // only support a single active request at a time.
67 scoped_ptr<DeviceManagementRequestJob> request_job_;
68
69 // DeviceStatusCollector that provides status for uploading.
70 scoped_ptr<DeviceStatusCollector> collector_;
71
72 // TaskRunner used for scheduling upload tasks.
73 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
74
75 // Pref item that specifies what our upload delay is currently.
76 scoped_ptr<IntegerPrefMember> upload_delay_;
77
78 // The time the last upload was performed.
79 base::Time last_upload_;
80
81 // Callback invoked via a delay to upload device status.
82 base::CancelableClosure upload_callback_;
83
84 // Note: This should remain the last member so it'll be destroyed and
85 // invalidate the weak pointers before any other members are destroyed.
86 base::WeakPtrFactory<StatusUploader> weak_factory_;
87
88 DISALLOW_COPY_AND_ASSIGN(StatusUploader);
89 };
90
91 } // namespace policy
92
93 #endif // CHROME_BROWSER_CHROMEOS_POLICY_STATUS_UPLOADER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/device_status_collector.cc ('k') | chrome/browser/chromeos/policy/status_uploader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698