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

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

Issue 2383763002: Report ARC status asynchronously via DeviceStatusCollector (Closed)
Patch Set: Restructure AndroidStatusFetcher Created 4 years, 2 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_DEVICE_STATUS_COLLECTOR_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_STATUS_COLLECTOR_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_STATUS_COLLECTOR_H_ 6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_STATUS_COLLECTOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <deque> 10 #include <deque>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <utility>
13 #include <vector> 14 #include <vector>
14 15
15 #include "base/callback_forward.h" 16 #include "base/callback_forward.h"
16 #include "base/callback_list.h" 17 #include "base/callback_list.h"
17 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
18 #include "base/macros.h" 19 #include "base/macros.h"
19 #include "base/memory/weak_ptr.h" 20 #include "base/memory/weak_ptr.h"
20 #include "base/sequenced_task_runner.h" 21 #include "base/sequenced_task_runner.h"
21 #include "base/task/cancelable_task_tracker.h" 22 #include "base/task/cancelable_task_tracker.h"
22 #include "base/threading/thread_checker.h" 23 #include "base/threading/thread_checker.h"
23 #include "base/time/time.h" 24 #include "base/time/time.h"
24 #include "base/timer/timer.h" 25 #include "base/timer/timer.h"
25 26
26 #include "chrome/browser/chromeos/settings/cros_settings.h" 27 #include "chrome/browser/chromeos/settings/cros_settings.h"
27 #include "chromeos/system/version_loader.h" 28 #include "chromeos/system/version_loader.h"
28 #include "components/policy/proto/device_management_backend.pb.h" 29 #include "components/policy/proto/device_management_backend.pb.h"
30 #include "mojo/public/cpp/bindings/string.h"
29 #include "ui/base/idle/idle.h" 31 #include "ui/base/idle/idle.h"
30 32
31 namespace chromeos { 33 namespace chromeos {
32 class CrosSettings; 34 class CrosSettings;
33 namespace system { 35 namespace system {
34 class StatisticsProvider; 36 class StatisticsProvider;
35 } 37 }
36 } 38 }
37 39
38 namespace content { 40 namespace content {
(...skipping 22 matching lines...) Expand all
61 // 63 //
62 // The format of this line from /proc/stat is: 64 // The format of this line from /proc/stat is:
63 // cpu user_time nice_time system_time idle_time 65 // cpu user_time nice_time system_time idle_time
64 using CPUStatisticsFetcher = base::Callback<std::string(void)>; 66 using CPUStatisticsFetcher = base::Callback<std::string(void)>;
65 67
66 // Reads CPU temperatures from /sys/class/hwmon/hwmon*/temp*_input and 68 // Reads CPU temperatures from /sys/class/hwmon/hwmon*/temp*_input and
67 // appropriate labels from /sys/class/hwmon/hwmon*/temp*_label. 69 // appropriate labels from /sys/class/hwmon/hwmon*/temp*_label.
68 using CPUTempFetcher = 70 using CPUTempFetcher =
69 base::Callback<std::vector<enterprise_management::CPUTempInfo>()>; 71 base::Callback<std::vector<enterprise_management::CPUTempInfo>()>;
70 72
73 // Is passed into asynchronous mojo interface for communicating with Android.
74 using AndroidStatusReceiver =
ljusten (tachyonic) 2016/10/05 16:10:42 Whoa, double callback all the way!!
phweiss 2016/10/05 16:33:39 Acknowledged.
75 base::Callback<void(mojo::String, mojo::String)>;
76 // Calls the enterprise reporting mojo interface, passing over the
77 // AndroidStatusReceiver.
78 using AndroidStatusFetcher = base::Callback<bool(AndroidStatusReceiver)>;
ljusten (tachyonic) 2016/10/05 16:10:42 Can you use const AndroidStatusReceiver & to preve
phweiss 2016/10/05 16:33:39 Done.
79
71 // Called in the UI thread after the device and session status have been 80 // Called in the UI thread after the device and session status have been
72 // collected asynchronously in GetDeviceAndSessionStatusAsync. Null pointers 81 // collected asynchronously in GetDeviceAndSessionStatusAsync. Null pointers
73 // indicate errors or that device or session status reporting is disabled. 82 // indicate errors or that device or session status reporting is disabled.
74 using StatusCallback = base::Callback<void( 83 using StatusCallback = base::Callback<void(
75 std::unique_ptr<enterprise_management::DeviceStatusReportRequest>, 84 std::unique_ptr<enterprise_management::DeviceStatusReportRequest>,
76 std::unique_ptr<enterprise_management::SessionStatusReportRequest>)>; 85 std::unique_ptr<enterprise_management::SessionStatusReportRequest>)>;
77 86
78 // Constructor. Callers can inject their own VolumeInfoFetcher, 87 // Constructor. Callers can inject their own VolumeInfoFetcher,
79 // CPUStatisticsFetcher and CPUTempFetcher. These callbacks are executed on 88 // CPUStatisticsFetcher and CPUTempFetcher. These callbacks are executed on
80 // Blocking Pool. A null callback can be passed for either parameter, to use 89 // Blocking Pool. A null callback can be passed for either parameter, to use
81 // the default implementation. 90 // the default implementation.
82 DeviceStatusCollector( 91 DeviceStatusCollector(PrefService* local_state,
83 PrefService* local_state, 92 chromeos::system::StatisticsProvider* provider,
84 chromeos::system::StatisticsProvider* provider, 93 const VolumeInfoFetcher& volume_info_fetcher,
85 const VolumeInfoFetcher& volume_info_fetcher, 94 const CPUStatisticsFetcher& cpu_statistics_fetcher,
86 const CPUStatisticsFetcher& cpu_statistics_fetcher, 95 const CPUTempFetcher& cpu_temp_fetcher,
87 const CPUTempFetcher& cpu_temp_fetcher); 96 const AndroidStatusFetcher& android_status_fetcher_);
88 virtual ~DeviceStatusCollector(); 97 virtual ~DeviceStatusCollector();
89 98
90 // Gathers device and session status information and calls the passed response 99 // Gathers device and session status information and calls the passed response
91 // callback. Null pointers passed into the response indicate errors or that 100 // callback. Null pointers passed into the response indicate errors or that
92 // device or session status reporting is disabled. 101 // device or session status reporting is disabled.
93 virtual void GetDeviceAndSessionStatusAsync(const StatusCallback& response); 102 virtual void GetDeviceAndSessionStatusAsync(const StatusCallback& response);
94 103
95 // Called after the status information has successfully been submitted to 104 // Called after the status information has successfully been submitted to
96 // the server. 105 // the server.
97 void OnSubmittedSuccessfully(); 106 void OnSubmittedSuccessfully();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 bool GetOsUpdateStatus( 185 bool GetOsUpdateStatus(
177 enterprise_management::DeviceStatusReportRequest* status); 186 enterprise_management::DeviceStatusReportRequest* status);
178 bool GetRunningKioskApp( 187 bool GetRunningKioskApp(
179 enterprise_management::DeviceStatusReportRequest* status); 188 enterprise_management::DeviceStatusReportRequest* status);
180 189
181 // Helpers for the various portions of SESSION STATUS. Return true if they 190 // Helpers for the various portions of SESSION STATUS. Return true if they
182 // actually report any status. Functions that queue async queries take 191 // actually report any status. Functions that queue async queries take
183 // a |GetStatusState| instance. 192 // a |GetStatusState| instance.
184 bool GetAccountStatus( 193 bool GetAccountStatus(
185 enterprise_management::SessionStatusReportRequest* status); 194 enterprise_management::SessionStatusReportRequest* status);
195 bool GetAndroidStatus(
196 enterprise_management::SessionStatusReportRequest* status,
197 scoped_refptr<GetStatusState> state); // Queues async queries!
186 198
187 // Update the cached values of the reporting settings. 199 // Update the cached values of the reporting settings.
188 void UpdateReportingSettings(); 200 void UpdateReportingSettings();
189 201
190 // Callback invoked to update our cpu usage information. 202 // Callback invoked to update our cpu usage information.
191 void ReceiveCPUStatistics(const std::string& statistics); 203 void ReceiveCPUStatistics(const std::string& statistics);
192 204
193 PrefService* const local_state_; 205 PrefService* const local_state_;
194 206
195 // The last time an idle state check was performed. 207 // The last time an idle state check was performed.
(...skipping 27 matching lines...) Expand all
223 235
224 // Callback invoked to fetch information about the mounted disk volumes. 236 // Callback invoked to fetch information about the mounted disk volumes.
225 VolumeInfoFetcher volume_info_fetcher_; 237 VolumeInfoFetcher volume_info_fetcher_;
226 238
227 // Callback invoked to fetch information about cpu usage. 239 // Callback invoked to fetch information about cpu usage.
228 CPUStatisticsFetcher cpu_statistics_fetcher_; 240 CPUStatisticsFetcher cpu_statistics_fetcher_;
229 241
230 // Callback invoked to fetch information about cpu temperature. 242 // Callback invoked to fetch information about cpu temperature.
231 CPUTempFetcher cpu_temp_fetcher_; 243 CPUTempFetcher cpu_temp_fetcher_;
232 244
245 AndroidStatusFetcher android_status_fetcher_;
246
233 chromeos::system::StatisticsProvider* const statistics_provider_; 247 chromeos::system::StatisticsProvider* const statistics_provider_;
234 248
235 chromeos::CrosSettings* const cros_settings_; 249 chromeos::CrosSettings* const cros_settings_;
236 250
237 // The most recent CPU readings. 251 // The most recent CPU readings.
238 uint64_t last_cpu_active_ = 0; 252 uint64_t last_cpu_active_ = 0;
239 uint64_t last_cpu_idle_ = 0; 253 uint64_t last_cpu_idle_ = 0;
240 254
241 // Cached values of the reporting settings from the device policy. 255 // Cached values of the reporting settings from the device policy.
242 bool report_version_info_ = false; 256 bool report_version_info_ = false;
243 bool report_activity_times_ = false; 257 bool report_activity_times_ = false;
244 bool report_boot_mode_ = false; 258 bool report_boot_mode_ = false;
245 bool report_network_interfaces_ = false; 259 bool report_network_interfaces_ = false;
246 bool report_users_ = false; 260 bool report_users_ = false;
247 bool report_hardware_status_ = false; 261 bool report_hardware_status_ = false;
248 bool report_session_status_ = false; 262 bool report_session_status_ = false;
263 bool report_android_status_ = false;
249 bool report_os_update_status_ = false; 264 bool report_os_update_status_ = false;
250 bool report_running_kiosk_app_ = false; 265 bool report_running_kiosk_app_ = false;
251 266
252 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> 267 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription>
253 version_info_subscription_; 268 version_info_subscription_;
254 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> 269 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription>
255 activity_times_subscription_; 270 activity_times_subscription_;
256 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> 271 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription>
257 boot_mode_subscription_; 272 boot_mode_subscription_;
258 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> 273 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription>
(...skipping 14 matching lines...) Expand all
273 base::ThreadChecker thread_checker_; 288 base::ThreadChecker thread_checker_;
274 289
275 base::WeakPtrFactory<DeviceStatusCollector> weak_factory_; 290 base::WeakPtrFactory<DeviceStatusCollector> weak_factory_;
276 291
277 DISALLOW_COPY_AND_ASSIGN(DeviceStatusCollector); 292 DISALLOW_COPY_AND_ASSIGN(DeviceStatusCollector);
278 }; 293 };
279 294
280 } // namespace policy 295 } // namespace policy
281 296
282 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_STATUS_COLLECTOR_H_ 297 #endif // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_STATUS_COLLECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698