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

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

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

Powered by Google App Engine
This is Rietveld 408576698