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

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

Issue 2383763002: Report ARC status asynchronously via DeviceStatusCollector (Closed)
Patch Set: const, include, auto, formatting 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 #include "chrome/browser/chromeos/policy/device_status_collector.h" 5 #include "chrome/browser/chromeos/policy/device_status_collector.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 30 matching lines...) Expand all
41 #include "chrome/common/pref_names.h" 41 #include "chrome/common/pref_names.h"
42 #include "chromeos/dbus/dbus_thread_manager.h" 42 #include "chromeos/dbus/dbus_thread_manager.h"
43 #include "chromeos/dbus/update_engine_client.h" 43 #include "chromeos/dbus/update_engine_client.h"
44 #include "chromeos/disks/disk_mount_manager.h" 44 #include "chromeos/disks/disk_mount_manager.h"
45 #include "chromeos/network/device_state.h" 45 #include "chromeos/network/device_state.h"
46 #include "chromeos/network/network_handler.h" 46 #include "chromeos/network/network_handler.h"
47 #include "chromeos/network/network_state.h" 47 #include "chromeos/network/network_state.h"
48 #include "chromeos/network/network_state_handler.h" 48 #include "chromeos/network/network_state_handler.h"
49 #include "chromeos/settings/cros_settings_names.h" 49 #include "chromeos/settings/cros_settings_names.h"
50 #include "chromeos/system/statistics_provider.h" 50 #include "chromeos/system/statistics_provider.h"
51 #include "components/arc/arc_bridge_service.h"
52 #include "components/arc/common/enterprise_reporting.mojom.h"
51 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 53 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
52 #include "components/policy/proto/device_management_backend.pb.h" 54 #include "components/policy/proto/device_management_backend.pb.h"
53 #include "components/prefs/pref_registry_simple.h" 55 #include "components/prefs/pref_registry_simple.h"
54 #include "components/prefs/pref_service.h" 56 #include "components/prefs/pref_service.h"
55 #include "components/prefs/scoped_user_pref_update.h" 57 #include "components/prefs/scoped_user_pref_update.h"
56 #include "components/user_manager/user.h" 58 #include "components/user_manager/user.h"
57 #include "components/user_manager/user_manager.h" 59 #include "components/user_manager/user_manager.h"
58 #include "components/user_manager/user_type.h" 60 #include "components/user_manager/user_type.h"
59 #include "components/version_info/version_info.h" 61 #include "components/version_info/version_info.h"
60 #include "content/public/browser/browser_thread.h" 62 #include "content/public/browser/browser_thread.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 contents.push_back(info); 211 contents.push_back(info);
210 } else { 212 } else {
211 LOG(WARNING) << "Unable to read CPU temp from " 213 LOG(WARNING) << "Unable to read CPU temp from "
212 << temperature_path.MaybeAsASCII(); 214 << temperature_path.MaybeAsASCII();
213 } 215 }
214 } 216 }
215 } 217 }
216 return contents; 218 return contents;
217 } 219 }
218 220
221 bool ReadAndroidStatus(
222 const policy::DeviceStatusCollector::AndroidStatusReceiver& receiver) {
223 auto* const arc_service = arc::ArcBridgeService::Get();
224 if (arc_service == nullptr)
225 return false;
226 auto* const instance_holder = arc_service->enterprise_reporting();
227 if (instance_holder == nullptr)
228 return false;
229 auto* const instance = instance_holder->GetInstanceForMethod("GetStatus", 1);
230 if (instance == nullptr)
231 return false;
232 instance->GetStatus(receiver);
233 return true;
234 }
235
219 // Returns the DeviceLocalAccount associated with the current kiosk session. 236 // Returns the DeviceLocalAccount associated with the current kiosk session.
220 // Returns null if there is no active kiosk session, or if that kiosk 237 // Returns null if there is no active kiosk session, or if that kiosk
221 // session has been removed from policy since the session started, in which 238 // session has been removed from policy since the session started, in which
222 // case we won't report its status). 239 // case we won't report its status).
223 std::unique_ptr<policy::DeviceLocalAccount> GetCurrentKioskDeviceLocalAccount( 240 std::unique_ptr<policy::DeviceLocalAccount> GetCurrentKioskDeviceLocalAccount(
224 chromeos::CrosSettings* settings) { 241 chromeos::CrosSettings* settings) {
225 if (!user_manager::UserManager::Get()->IsLoggedInAsKioskApp()) 242 if (!user_manager::UserManager::Get()->IsLoggedInAsKioskApp())
226 return std::unique_ptr<policy::DeviceLocalAccount>(); 243 return std::unique_ptr<policy::DeviceLocalAccount>();
227 const user_manager::User* const user = 244 const user_manager::User* const user =
228 user_manager::UserManager::Get()->GetActiveUser(); 245 user_manager::UserManager::Get()->GetActiveUser();
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 348
332 // Queues an async callback to query CPU temperature information. 349 // Queues an async callback to query CPU temperature information.
333 void SampleCPUTempInfo( 350 void SampleCPUTempInfo(
334 const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher) { 351 const policy::DeviceStatusCollector::CPUTempFetcher& cpu_temp_fetcher) {
335 // Call out to the blocking pool to sample CPU temp. 352 // Call out to the blocking pool to sample CPU temp.
336 base::PostTaskAndReplyWithResult( 353 base::PostTaskAndReplyWithResult(
337 content::BrowserThread::GetBlockingPool(), FROM_HERE, cpu_temp_fetcher, 354 content::BrowserThread::GetBlockingPool(), FROM_HERE, cpu_temp_fetcher,
338 base::Bind(&GetStatusState::OnCPUTempInfoReceived, this)); 355 base::Bind(&GetStatusState::OnCPUTempInfoReceived, this));
339 } 356 }
340 357
358 bool FetchAndroidStatus(
359 const policy::DeviceStatusCollector::AndroidStatusFetcher&
360 android_status_fetcher) {
361 return android_status_fetcher.Run(
362 base::Bind(&GetStatusState::OnAndroidInfoReceived, this));
363 }
364
341 private: 365 private:
342 friend class RefCountedThreadSafe<GetStatusState>; 366 friend class RefCountedThreadSafe<GetStatusState>;
343 367
344 // Posts the response on the UI thread. As long as there is an outstanding 368 // Posts the response on the UI thread. As long as there is an outstanding
345 // async query, the query holds a reference to us, so the destructor is 369 // async query, the query holds a reference to us, so the destructor is
346 // not called. 370 // not called.
347 ~GetStatusState() { 371 ~GetStatusState() {
348 task_runner_->PostTask(FROM_HERE, 372 task_runner_->PostTask(FROM_HERE,
349 base::Bind(response_, base::Passed(&device_status_), 373 base::Bind(response_, base::Passed(&device_status_),
350 base::Passed(&session_status_))); 374 base::Passed(&session_status_)));
351 } 375 }
352 376
353 void OnVolumeInfoReceived(const std::vector<em::VolumeInfo>& volume_info) { 377 void OnVolumeInfoReceived(const std::vector<em::VolumeInfo>& volume_info) {
354 device_status_->clear_volume_info(); 378 device_status_->clear_volume_info();
355 for (const em::VolumeInfo& info : volume_info) 379 for (const em::VolumeInfo& info : volume_info)
356 *device_status_->add_volume_info() = info; 380 *device_status_->add_volume_info() = info;
357 } 381 }
358 382
359 void OnCPUTempInfoReceived( 383 void OnCPUTempInfoReceived(
360 const std::vector<em::CPUTempInfo>& cpu_temp_info) { 384 const std::vector<em::CPUTempInfo>& cpu_temp_info) {
361 if (cpu_temp_info.empty()) 385 if (cpu_temp_info.empty())
362 DLOG(WARNING) << "Unable to read CPU temp information."; 386 DLOG(WARNING) << "Unable to read CPU temp information.";
363 387
364 device_status_->clear_cpu_temp_info(); 388 device_status_->clear_cpu_temp_info();
365 for (const em::CPUTempInfo& info : cpu_temp_info) 389 for (const em::CPUTempInfo& info : cpu_temp_info)
366 *device_status_->add_cpu_temp_info() = info; 390 *device_status_->add_cpu_temp_info() = info;
367 } 391 }
368 392
393 void OnAndroidInfoReceived(mojo::String status,
394 mojo::String droid_guard_info) {
395 em::AndroidStatus* android_status =
396 session_status_->mutable_android_status();
397 android_status->set_status_payload(status);
398 android_status->set_droid_guard_info(droid_guard_info);
399 }
400
369 const scoped_refptr<base::SequencedTaskRunner> task_runner_; 401 const scoped_refptr<base::SequencedTaskRunner> task_runner_;
370 policy::DeviceStatusCollector::StatusCallback response_; 402 policy::DeviceStatusCollector::StatusCallback response_;
371 std::unique_ptr<em::DeviceStatusReportRequest> device_status_ = 403 std::unique_ptr<em::DeviceStatusReportRequest> device_status_ =
372 base::MakeUnique<em::DeviceStatusReportRequest>(); 404 base::MakeUnique<em::DeviceStatusReportRequest>();
373 std::unique_ptr<em::SessionStatusReportRequest> session_status_ = 405 std::unique_ptr<em::SessionStatusReportRequest> session_status_ =
374 base::MakeUnique<em::SessionStatusReportRequest>(); 406 base::MakeUnique<em::SessionStatusReportRequest>();
375 }; 407 };
376 408
377 DeviceStatusCollector::DeviceStatusCollector( 409 DeviceStatusCollector::DeviceStatusCollector(
378 PrefService* local_state, 410 PrefService* local_state,
379 chromeos::system::StatisticsProvider* provider, 411 chromeos::system::StatisticsProvider* provider,
380 const VolumeInfoFetcher& volume_info_fetcher, 412 const VolumeInfoFetcher& volume_info_fetcher,
381 const CPUStatisticsFetcher& cpu_statistics_fetcher, 413 const CPUStatisticsFetcher& cpu_statistics_fetcher,
382 const CPUTempFetcher& cpu_temp_fetcher) 414 const CPUTempFetcher& cpu_temp_fetcher,
415 const AndroidStatusFetcher& android_status_fetcher)
383 : max_stored_past_activity_days_(kMaxStoredPastActivityDays), 416 : max_stored_past_activity_days_(kMaxStoredPastActivityDays),
384 max_stored_future_activity_days_(kMaxStoredFutureActivityDays), 417 max_stored_future_activity_days_(kMaxStoredFutureActivityDays),
385 local_state_(local_state), 418 local_state_(local_state),
386 last_idle_check_(Time()), 419 last_idle_check_(Time()),
387 volume_info_fetcher_(volume_info_fetcher), 420 volume_info_fetcher_(volume_info_fetcher),
388 cpu_statistics_fetcher_(cpu_statistics_fetcher), 421 cpu_statistics_fetcher_(cpu_statistics_fetcher),
389 cpu_temp_fetcher_(cpu_temp_fetcher), 422 cpu_temp_fetcher_(cpu_temp_fetcher),
423 android_status_fetcher_(android_status_fetcher),
390 statistics_provider_(provider), 424 statistics_provider_(provider),
391 cros_settings_(chromeos::CrosSettings::Get()), 425 cros_settings_(chromeos::CrosSettings::Get()),
392 task_runner_(nullptr), 426 task_runner_(nullptr),
393 weak_factory_(this) { 427 weak_factory_(this) {
394 // Get the task runner of the current thread, so we can queue status responses 428 // Get the task runner of the current thread, so we can queue status responses
395 // on this thread. 429 // on this thread.
396 CHECK(base::SequencedTaskRunnerHandle::IsSet()); 430 CHECK(base::SequencedTaskRunnerHandle::IsSet());
397 task_runner_ = base::SequencedTaskRunnerHandle::Get(); 431 task_runner_ = base::SequencedTaskRunnerHandle::Get();
398 432
399 if (volume_info_fetcher_.is_null()) 433 if (volume_info_fetcher_.is_null())
400 volume_info_fetcher_ = base::Bind(&GetVolumeInfo); 434 volume_info_fetcher_ = base::Bind(&GetVolumeInfo);
401 435
402 if (cpu_statistics_fetcher_.is_null()) 436 if (cpu_statistics_fetcher_.is_null())
403 cpu_statistics_fetcher_ = base::Bind(&ReadCPUStatistics); 437 cpu_statistics_fetcher_ = base::Bind(&ReadCPUStatistics);
404 438
405 if (cpu_temp_fetcher_.is_null()) 439 if (cpu_temp_fetcher_.is_null())
406 cpu_temp_fetcher_ = base::Bind(&ReadCPUTempInfo); 440 cpu_temp_fetcher_ = base::Bind(&ReadCPUTempInfo);
407 441
442 if (android_status_fetcher_.is_null())
443 android_status_fetcher_ = base::Bind(&ReadAndroidStatus);
444
408 idle_poll_timer_.Start(FROM_HERE, 445 idle_poll_timer_.Start(FROM_HERE,
409 TimeDelta::FromSeconds(kIdlePollIntervalSeconds), 446 TimeDelta::FromSeconds(kIdlePollIntervalSeconds),
410 this, &DeviceStatusCollector::CheckIdleState); 447 this, &DeviceStatusCollector::CheckIdleState);
411 resource_usage_sampling_timer_.Start( 448 resource_usage_sampling_timer_.Start(
412 FROM_HERE, TimeDelta::FromSeconds(kResourceUsageSampleIntervalSeconds), 449 FROM_HERE, TimeDelta::FromSeconds(kResourceUsageSampleIntervalSeconds),
413 this, &DeviceStatusCollector::SampleResourceUsage); 450 this, &DeviceStatusCollector::SampleResourceUsage);
414 451
415 // Watch for changes to the individual policies that control what the status 452 // Watch for changes to the individual policies that control what the status
416 // reports contain. 453 // reports contain.
417 base::Closure callback = 454 base::Closure callback =
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 if (!cros_settings_->GetBoolean( 545 if (!cros_settings_->GetBoolean(
509 chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) { 546 chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) {
510 report_hardware_status_ = true; 547 report_hardware_status_ = true;
511 } 548 }
512 549
513 if (!cros_settings_->GetBoolean( 550 if (!cros_settings_->GetBoolean(
514 chromeos::kReportDeviceSessionStatus, &report_session_status_)) { 551 chromeos::kReportDeviceSessionStatus, &report_session_status_)) {
515 report_session_status_ = true; 552 report_session_status_ = true;
516 } 553 }
517 554
555 // TODO(phweiss): Create policy to control this, and turn it on by default.
556 report_android_status_ = false;
557
518 if (!report_hardware_status_) { 558 if (!report_hardware_status_) {
519 ClearCachedResourceUsage(); 559 ClearCachedResourceUsage();
520 } else if (!already_reporting_hardware_status) { 560 } else if (!already_reporting_hardware_status) {
521 // Turning on hardware status reporting - fetch an initial sample 561 // Turning on hardware status reporting - fetch an initial sample
522 // immediately instead of waiting for the sampling timer to fire. 562 // immediately instead of waiting for the sampling timer to fire.
523 SampleResourceUsage(); 563 SampleResourceUsage();
524 } 564 }
525 565
526 // Os update status and running kiosk app reporting are disabled by default. 566 // Os update status and running kiosk app reporting are disabled by default.
527 if (!cros_settings_->GetBoolean(chromeos::kReportOsUpdateStatus, 567 if (!cros_settings_->GetBoolean(chromeos::kReportOsUpdateStatus,
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 anything_reported |= GetOsUpdateStatus(status); 1113 anything_reported |= GetOsUpdateStatus(status);
1074 1114
1075 if (report_running_kiosk_app_) 1115 if (report_running_kiosk_app_)
1076 anything_reported |= GetRunningKioskApp(status); 1116 anything_reported |= GetRunningKioskApp(status);
1077 1117
1078 // Wipe pointer if we didn't actually add any data. 1118 // Wipe pointer if we didn't actually add any data.
1079 if (!anything_reported) 1119 if (!anything_reported)
1080 state->ResetDeviceStatus(); 1120 state->ResetDeviceStatus();
1081 } 1121 }
1082 1122
1083 void DeviceStatusCollector::GetSessionStatus( 1123 void DeviceStatusCollector::GetSessionStatus(
ljusten (tachyonic) 2016/10/05 18:19:49 While you're at it, the code that calls this metho
phweiss 2016/10/06 08:56:19 Done.
1084 scoped_refptr<GetStatusState> state) { 1124 scoped_refptr<GetStatusState> state) {
1085 em::SessionStatusReportRequest* status = state->session_status(); 1125 em::SessionStatusReportRequest* status = state->session_status();
1086 bool anything_reported = false; 1126 bool anything_reported = false;
1087 1127
1088 if (report_session_status_) 1128 if (report_session_status_)
ljusten (tachyonic) 2016/10/05 18:19:49 We should rename a few things then to prevent conf
phweiss 2016/10/06 08:56:19 Done.
1089 anything_reported |= GetAccountStatus(status); 1129 anything_reported |= GetAccountStatus(status);
1130 if (report_android_status_)
1131 anything_reported |= GetAndroidStatus(status, state);
1090 1132
1091 // Wipe pointer if we didn't actually add any data. 1133 // Wipe pointer if we didn't actually add any data.
1092 if (!anything_reported) 1134 if (!anything_reported)
1093 state->ResetSessionStatus(); 1135 state->ResetSessionStatus();
1094 } 1136 }
1095 1137
1096 bool DeviceStatusCollector::GetAccountStatus( 1138 bool DeviceStatusCollector::GetAccountStatus(
1097 em::SessionStatusReportRequest* status) { 1139 em::SessionStatusReportRequest* status) {
1098 std::unique_ptr<const DeviceLocalAccount> account = 1140 std::unique_ptr<const DeviceLocalAccount> account =
1099 GetAutoLaunchedKioskSessionInfo(); 1141 GetAutoLaunchedKioskSessionInfo();
(...skipping 10 matching lines...) Expand all
1110 if (app_version.empty()) { 1152 if (app_version.empty()) {
1111 DLOG(ERROR) << "Unable to get version for extension: " 1153 DLOG(ERROR) << "Unable to get version for extension: "
1112 << account->kiosk_app_id; 1154 << account->kiosk_app_id;
1113 } else { 1155 } else {
1114 app_status->set_extension_version(app_version); 1156 app_status->set_extension_version(app_version);
1115 } 1157 }
1116 1158
1117 return true; 1159 return true;
1118 } 1160 }
1119 1161
1162 bool DeviceStatusCollector::GetAndroidStatus(
1163 em::SessionStatusReportRequest* status,
1164 scoped_refptr<GetStatusState> state) {
1165 return state->FetchAndroidStatus(android_status_fetcher_);
1166 }
1167
1120 std::string DeviceStatusCollector::GetAppVersion( 1168 std::string DeviceStatusCollector::GetAppVersion(
1121 const std::string& kiosk_app_id) { 1169 const std::string& kiosk_app_id) {
1122 Profile* const profile = 1170 Profile* const profile =
1123 chromeos::ProfileHelper::Get()->GetProfileByUser( 1171 chromeos::ProfileHelper::Get()->GetProfileByUser(
1124 user_manager::UserManager::Get()->GetActiveUser()); 1172 user_manager::UserManager::Get()->GetActiveUser());
1125 const extensions::ExtensionRegistry* const registry = 1173 const extensions::ExtensionRegistry* const registry =
1126 extensions::ExtensionRegistry::Get(profile); 1174 extensions::ExtensionRegistry::Get(profile);
1127 const extensions::Extension* const extension = registry->GetExtensionById( 1175 const extensions::Extension* const extension = registry->GetExtensionById(
1128 kiosk_app_id, extensions::ExtensionRegistry::EVERYTHING); 1176 kiosk_app_id, extensions::ExtensionRegistry::EVERYTHING);
1129 if (!extension) 1177 if (!extension)
1130 return std::string(); 1178 return std::string();
1131 return extension->VersionString(); 1179 return extension->VersionString();
1132 } 1180 }
1133 1181
1134 void DeviceStatusCollector::OnSubmittedSuccessfully() { 1182 void DeviceStatusCollector::OnSubmittedSuccessfully() {
1135 TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_, 1183 TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_,
1136 std::numeric_limits<int64_t>::max()); 1184 std::numeric_limits<int64_t>::max());
1137 } 1185 }
1138 1186
1139 void DeviceStatusCollector::OnOSVersion(const std::string& version) { 1187 void DeviceStatusCollector::OnOSVersion(const std::string& version) {
1140 os_version_ = version; 1188 os_version_ = version;
1141 } 1189 }
1142 1190
1143 void DeviceStatusCollector::OnOSFirmware(const std::string& version) { 1191 void DeviceStatusCollector::OnOSFirmware(const std::string& version) {
1144 firmware_version_ = version; 1192 firmware_version_ = version;
1145 } 1193 }
1146 1194
1147 } // namespace policy 1195 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698