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

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

Issue 776803003: Updated DeviceStatusReportRequest to contain new monitoring data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed error in proto def for volume_info Created 6 years 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 <limits> 7 #include <limits>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/prefs/pref_registry_simple.h" 14 #include "base/prefs/pref_registry_simple.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/prefs/scoped_user_pref_update.h" 16 #include "base/prefs/scoped_user_pref_update.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
21 #include "chrome/browser/chromeos/settings/cros_settings.h" 21 #include "chrome/browser/chromeos/settings/cros_settings.h"
22 #include "chrome/common/chrome_version_info.h" 22 #include "chrome/common/chrome_version_info.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chromeos/network/device_state.h" 24 #include "chromeos/network/device_state.h"
25 #include "chromeos/network/network_handler.h" 25 #include "chromeos/network/network_handler.h"
26 #include "chromeos/network/network_state.h"
26 #include "chromeos/network/network_state_handler.h" 27 #include "chromeos/network/network_state_handler.h"
27 #include "chromeos/settings/cros_settings_names.h" 28 #include "chromeos/settings/cros_settings_names.h"
28 #include "chromeos/system/statistics_provider.h" 29 #include "chromeos/system/statistics_provider.h"
29 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 30 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
30 #include "components/user_manager/user_manager.h" 31 #include "components/user_manager/user_manager.h"
31 #include "components/user_manager/user_type.h" 32 #include "components/user_manager/user_type.h"
32 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
33 #include "policy/proto/device_management_backend.pb.h" 34 #include "policy/proto/device_management_backend.pb.h"
34 #include "third_party/cros_system_api/dbus/service_constants.h" 35 #include "third_party/cros_system_api/dbus/service_constants.h"
35 36
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 last_reported_day_(0), 88 last_reported_day_(0),
88 duration_for_last_reported_day_(0), 89 duration_for_last_reported_day_(0),
89 geolocation_update_in_progress_(false), 90 geolocation_update_in_progress_(false),
90 statistics_provider_(provider), 91 statistics_provider_(provider),
91 report_version_info_(false), 92 report_version_info_(false),
92 report_activity_times_(false), 93 report_activity_times_(false),
93 report_boot_mode_(false), 94 report_boot_mode_(false),
94 report_location_(false), 95 report_location_(false),
95 report_network_interfaces_(false), 96 report_network_interfaces_(false),
96 report_users_(false), 97 report_users_(false),
98 report_hardware_status_(false),
97 weak_factory_(this) { 99 weak_factory_(this) {
98 if (location_update_requester) 100 if (location_update_requester)
99 location_update_requester_ = *location_update_requester; 101 location_update_requester_ = *location_update_requester;
100 idle_poll_timer_.Start(FROM_HERE, 102 idle_poll_timer_.Start(FROM_HERE,
101 TimeDelta::FromSeconds(kIdlePollIntervalSeconds), 103 TimeDelta::FromSeconds(kIdlePollIntervalSeconds),
102 this, &DeviceStatusCollector::CheckIdleState); 104 this, &DeviceStatusCollector::CheckIdleState);
103 105
104 cros_settings_ = chromeos::CrosSettings::Get(); 106 cros_settings_ = chromeos::CrosSettings::Get();
105 107
106 // Watch for changes to the individual policies that control what the status 108 // Watch for changes to the individual policies that control what the status
107 // reports contain. 109 // reports contain.
108 base::Closure callback = 110 base::Closure callback =
109 base::Bind(&DeviceStatusCollector::UpdateReportingSettings, 111 base::Bind(&DeviceStatusCollector::UpdateReportingSettings,
110 base::Unretained(this)); 112 base::Unretained(this));
111 version_info_subscription_ = cros_settings_->AddSettingsObserver( 113 version_info_subscription_ = cros_settings_->AddSettingsObserver(
112 chromeos::kReportDeviceVersionInfo, callback); 114 chromeos::kReportDeviceVersionInfo, callback);
113 activity_times_subscription_ = cros_settings_->AddSettingsObserver( 115 activity_times_subscription_ = cros_settings_->AddSettingsObserver(
114 chromeos::kReportDeviceActivityTimes, callback); 116 chromeos::kReportDeviceActivityTimes, callback);
115 boot_mode_subscription_ = cros_settings_->AddSettingsObserver( 117 boot_mode_subscription_ = cros_settings_->AddSettingsObserver(
116 chromeos::kReportDeviceBootMode, callback); 118 chromeos::kReportDeviceBootMode, callback);
117 location_subscription_ = cros_settings_->AddSettingsObserver( 119 location_subscription_ = cros_settings_->AddSettingsObserver(
118 chromeos::kReportDeviceLocation, callback); 120 chromeos::kReportDeviceLocation, callback);
119 network_interfaces_subscription_ = cros_settings_->AddSettingsObserver( 121 network_interfaces_subscription_ = cros_settings_->AddSettingsObserver(
120 chromeos::kReportDeviceNetworkInterfaces, callback); 122 chromeos::kReportDeviceNetworkInterfaces, callback);
121 users_subscription_ = cros_settings_->AddSettingsObserver( 123 users_subscription_ = cros_settings_->AddSettingsObserver(
122 chromeos::kReportDeviceUsers, callback); 124 chromeos::kReportDeviceUsers, callback);
125 hardware_status_subscription_ = cros_settings_->AddSettingsObserver(
126 chromeos::kReportDeviceHardwareStatus, callback);
123 127
124 // The last known location is persisted in local state. This makes location 128 // The last known location is persisted in local state. This makes location
125 // information available immediately upon startup and avoids the need to 129 // information available immediately upon startup and avoids the need to
126 // reacquire the location on every user session change or browser crash. 130 // reacquire the location on every user session change or browser crash.
127 content::Geoposition position; 131 content::Geoposition position;
128 std::string timestamp_str; 132 std::string timestamp_str;
129 int64 timestamp; 133 int64 timestamp;
130 const base::DictionaryValue* location = 134 const base::DictionaryValue* location =
131 local_state_->GetDictionary(prefs::kDeviceLocation); 135 local_state_->GetDictionary(prefs::kDeviceLocation);
132 if (location->GetDouble(kLatitude, &position.latitude) && 136 if (location->GetDouble(kLatitude, &position.latitude) &&
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 report_location_ = false; 203 report_location_ = false;
200 } 204 }
201 if (!cros_settings_->GetBoolean( 205 if (!cros_settings_->GetBoolean(
202 chromeos::kReportDeviceNetworkInterfaces, &report_network_interfaces_)) { 206 chromeos::kReportDeviceNetworkInterfaces, &report_network_interfaces_)) {
203 report_network_interfaces_ = true; 207 report_network_interfaces_ = true;
204 } 208 }
205 if (!cros_settings_->GetBoolean( 209 if (!cros_settings_->GetBoolean(
206 chromeos::kReportDeviceUsers, &report_users_)) { 210 chromeos::kReportDeviceUsers, &report_users_)) {
207 report_users_ = true; 211 report_users_ = true;
208 } 212 }
213 if (!cros_settings_->GetBoolean(
pneubeck (no reviews) 2014/12/09 03:00:09 IMO it would help a bit to drop a comment in front
Andrew T Wilson (Slow) 2014/12/11 00:09:54 Done.
214 chromeos::kReportDeviceHardwareStatus, &report_hardware_status_)) {
215 report_hardware_status_ = true;
216 }
209 217
210 if (report_location_) { 218 if (report_location_) {
211 ScheduleGeolocationUpdateRequest(); 219 ScheduleGeolocationUpdateRequest();
212 } else { 220 } else {
213 geolocation_update_timer_.Stop(); 221 geolocation_update_timer_.Stop();
214 position_ = content::Geoposition(); 222 position_ = content::Geoposition();
215 local_state_->ClearPref(prefs::kDeviceLocation); 223 local_state_->ClearPref(prefs::kDeviceLocation);
216 } 224 }
217 } 225 }
218 226
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 const char* type_string; 396 const char* type_string;
389 em::NetworkInterface::NetworkDeviceType type_constant; 397 em::NetworkInterface::NetworkDeviceType type_constant;
390 } kDeviceTypeMap[] = { 398 } kDeviceTypeMap[] = {
391 { shill::kTypeEthernet, em::NetworkInterface::TYPE_ETHERNET, }, 399 { shill::kTypeEthernet, em::NetworkInterface::TYPE_ETHERNET, },
392 { shill::kTypeWifi, em::NetworkInterface::TYPE_WIFI, }, 400 { shill::kTypeWifi, em::NetworkInterface::TYPE_WIFI, },
393 { shill::kTypeWimax, em::NetworkInterface::TYPE_WIMAX, }, 401 { shill::kTypeWimax, em::NetworkInterface::TYPE_WIMAX, },
394 { shill::kTypeBluetooth, em::NetworkInterface::TYPE_BLUETOOTH, }, 402 { shill::kTypeBluetooth, em::NetworkInterface::TYPE_BLUETOOTH, },
395 { shill::kTypeCellular, em::NetworkInterface::TYPE_CELLULAR, }, 403 { shill::kTypeCellular, em::NetworkInterface::TYPE_CELLULAR, },
396 }; 404 };
397 405
406 // Maps flimflam device connection status to proto enum constants.
pneubeck (no reviews) 2014/12/09 03:00:10 we shouldn't use the name flimflam of the previous
Andrew T Wilson (Slow) 2014/12/11 00:09:54 Done.
407 static const struct {
408 const char* type_string;
pneubeck (no reviews) 2014/12/09 03:00:09 type_string -> state_string
Andrew T Wilson (Slow) 2014/12/11 00:09:54 Done.
409 em::NetworkState::ConnectionState state_constant;
410 } kConnectionStateMap[] = {
411 { shill::kStateIdle, em::NetworkState::IDLE },
412 { shill::kStateCarrier, em::NetworkState::CARRIER },
413 { shill::kStateAssociation, em::NetworkState::ASSOCIATION },
414 { shill::kStateConfiguration, em::NetworkState::CONFIGURATION },
415 { shill::kStateReady, em::NetworkState::READY },
416 { shill::kStatePortal, em::NetworkState::PORTAL },
417 { shill::kStateOffline, em::NetworkState::OFFLINE },
418 { shill::kStateOnline, em::NetworkState::ONLINE },
419 { shill::kStateDisconnect, em::NetworkState::DISCONNECT },
420 { shill::kStateFailure, em::NetworkState::FAILURE },
421 { shill::kStateActivationFailure,
422 em::NetworkState::ACTIVATION_FAILURE },
423 };
424
398 chromeos::NetworkStateHandler::DeviceStateList device_list; 425 chromeos::NetworkStateHandler::DeviceStateList device_list;
399 chromeos::NetworkHandler::Get()->network_state_handler()->GetDeviceList( 426 chromeos::NetworkStateHandler* network_state_handler =
400 &device_list); 427 chromeos::NetworkHandler::Get()->network_state_handler();
428 network_state_handler->GetDeviceList(&device_list);
401 429
402 chromeos::NetworkStateHandler::DeviceStateList::const_iterator device; 430 chromeos::NetworkStateHandler::DeviceStateList::const_iterator device;
403 for (device = device_list.begin(); device != device_list.end(); ++device) { 431 for (device = device_list.begin(); device != device_list.end(); ++device) {
404 // Determine the type enum constant for |device|. 432 // Determine the type enum constant for |device|.
405 size_t type_idx = 0; 433 size_t type_idx = 0;
406 for (; type_idx < arraysize(kDeviceTypeMap); ++type_idx) { 434 for (; type_idx < arraysize(kDeviceTypeMap); ++type_idx) {
407 if ((*device)->type() == kDeviceTypeMap[type_idx].type_string) 435 if ((*device)->type() == kDeviceTypeMap[type_idx].type_string)
408 break; 436 break;
409 } 437 }
410 438
411 // If the type isn't in |kDeviceTypeMap|, the interface is not relevant for 439 // If the type isn't in |kDeviceTypeMap|, the interface is not relevant for
412 // reporting. This filters out VPN devices. 440 // reporting. This filters out VPN devices.
413 if (type_idx >= arraysize(kDeviceTypeMap)) 441 if (type_idx >= arraysize(kDeviceTypeMap))
414 continue; 442 continue;
415 443
416 em::NetworkInterface* interface = request->add_network_interface(); 444 em::NetworkInterface* interface = request->add_network_interface();
417 interface->set_type(kDeviceTypeMap[type_idx].type_constant); 445 interface->set_type(kDeviceTypeMap[type_idx].type_constant);
418 if (!(*device)->mac_address().empty()) 446 if (!(*device)->mac_address().empty())
419 interface->set_mac_address((*device)->mac_address()); 447 interface->set_mac_address((*device)->mac_address());
420 if (!(*device)->meid().empty()) 448 if (!(*device)->meid().empty())
421 interface->set_meid((*device)->meid()); 449 interface->set_meid((*device)->meid());
422 if (!(*device)->imei().empty()) 450 if (!(*device)->imei().empty())
423 interface->set_imei((*device)->imei()); 451 interface->set_imei((*device)->imei());
452 if (!(*device)->path().empty())
453 interface->set_device_path((*device)->path());
454 }
455
456 // Walk the various networks and store their state in the status report.
457 chromeos::NetworkStateHandler::NetworkStateList state_list;
458 network_state_handler->GetNetworkListByType(
459 chromeos::NetworkTypePattern::Default(),
460 false, // configured_only
pneubeck (no reviews) 2014/12/09 03:00:09 just verify with your intent here: this will list
Andrew T Wilson (Slow) 2014/12/11 00:09:54 Hmmm. It's probably better to be a little tighter
461 false, // visible_only,
462 0, // no limit to number of results
463 &state_list);
464
465 chromeos::NetworkStateHandler::NetworkStateList::const_iterator state;
466 for (state = state_list.begin(); state != state_list.end(); ++state) {
ygorshenin1 2014/12/05 15:55:41 nit: you can just write: for (const auto& state :
Andrew T Wilson (Slow) 2014/12/11 00:09:54 Done.
467 // Determine the connection state and signal strength for |state|.
468 em::NetworkState::ConnectionState connection_state_enum =
469 em::NetworkState::UNKNOWN;
470 std::string connection_state_string = (*state)->connection_state();
pneubeck (no reviews) 2014/12/09 03:00:09 nit: const, use constructor instead of assignment
Andrew T Wilson (Slow) 2014/12/11 00:09:54 Done.
471 for (size_t i = 0; i < arraysize(kConnectionStateMap); ++i) {
472 if (connection_state_string == kConnectionStateMap[i].type_string) {
473 connection_state_enum = kConnectionStateMap[i].state_constant;
474 break;
475 }
476 }
477
478 // Copy fields from NetworkState into the status report.
479 em::NetworkState* proto_state = request->add_network_state();
480 proto_state->set_connection_state(connection_state_enum);
481 proto_state->set_signal_strength((*state)->signal_strength());
482 if (!(*state)->device_path().empty())
483 proto_state->set_device_path((*state)->device_path());
424 } 484 }
425 } 485 }
426 486
427 void DeviceStatusCollector::GetUsers(em::DeviceStatusReportRequest* request) { 487 void DeviceStatusCollector::GetUsers(em::DeviceStatusReportRequest* request) {
428 policy::BrowserPolicyConnectorChromeOS* connector = 488 policy::BrowserPolicyConnectorChromeOS* connector =
429 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 489 g_browser_process->platform_part()->browser_policy_connector_chromeos();
430 const user_manager::UserList& users = 490 const user_manager::UserList& users =
431 user_manager::UserManager::Get()->GetUsers(); 491 user_manager::UserManager::Get()->GetUsers();
432 user_manager::UserList::const_iterator user; 492 user_manager::UserList::const_iterator user;
433 for (user = users.begin(); user != users.end(); ++user) { 493 for (user = users.begin(); user != users.end(); ++user) {
434 // Only users with gaia accounts (regular) are reported. 494 // Only users with gaia accounts (regular) are reported.
435 if (!(*user)->HasGaiaAccount()) 495 if (!(*user)->HasGaiaAccount())
436 continue; 496 continue;
437 497
438 em::DeviceUser* device_user = request->add_user(); 498 em::DeviceUser* device_user = request->add_user();
439 const std::string& email = (*user)->email(); 499 const std::string& email = (*user)->email();
440 if (connector->GetUserAffiliation(email) == USER_AFFILIATION_MANAGED) { 500 if (connector->GetUserAffiliation(email) == USER_AFFILIATION_MANAGED) {
441 device_user->set_type(em::DeviceUser::USER_TYPE_MANAGED); 501 device_user->set_type(em::DeviceUser::USER_TYPE_MANAGED);
442 device_user->set_email(email); 502 device_user->set_email(email);
443 } else { 503 } else {
444 device_user->set_type(em::DeviceUser::USER_TYPE_UNMANAGED); 504 device_user->set_type(em::DeviceUser::USER_TYPE_UNMANAGED);
445 // Do not report the email address of unmanaged users. 505 // Do not report the email address of unmanaged users.
446 } 506 }
447 } 507 }
448 } 508 }
449 509
450 void DeviceStatusCollector::GetStatus(em::DeviceStatusReportRequest* request) { 510 void DeviceStatusCollector::GetHardwareStatus(
451 // TODO(mnissler): Remove once the old cloud policy stack is retired. The old 511 em::DeviceStatusReportRequest* status) {
pneubeck (no reviews) 2014/12/09 03:00:10 why is this empty function necessary? if it will b
Andrew T Wilson (Slow) 2014/12/11 00:09:54 I'd like to keep this in place because I'd like to
452 // stack doesn't support reporting successful submissions back to here, so 512
453 // just assume whatever ends up in |request| gets submitted successfully.
454 GetDeviceStatus(request);
455 OnSubmittedSuccessfully();
456 } 513 }
457 514
458 bool DeviceStatusCollector::GetDeviceStatus( 515 bool DeviceStatusCollector::GetDeviceStatus(
459 em::DeviceStatusReportRequest* status) { 516 em::DeviceStatusReportRequest* status) {
460 if (report_activity_times_) 517 if (report_activity_times_)
461 GetActivityTimes(status); 518 GetActivityTimes(status);
462 519
463 if (report_version_info_) 520 if (report_version_info_)
464 GetVersionInfo(status); 521 GetVersionInfo(status);
465 522
466 if (report_boot_mode_) 523 if (report_boot_mode_)
467 GetBootMode(status); 524 GetBootMode(status);
468 525
469 if (report_location_) 526 if (report_location_)
470 GetLocation(status); 527 GetLocation(status);
471 528
472 if (report_network_interfaces_) 529 if (report_network_interfaces_)
473 GetNetworkInterfaces(status); 530 GetNetworkInterfaces(status);
474 531
475 if (report_users_) { 532 if (report_users_) {
476 GetUsers(status); 533 GetUsers(status);
477 } 534 }
478 535
536 if (report_hardware_status_)
537 GetHardwareStatus(status);
538
479 return true; 539 return true;
480 } 540 }
481 541
482 bool DeviceStatusCollector::GetSessionStatus( 542 bool DeviceStatusCollector::GetSessionStatus(
483 em::SessionStatusReportRequest* status) { 543 em::SessionStatusReportRequest* status) {
484 return false; 544 return false;
485 } 545 }
486 546
487 void DeviceStatusCollector::OnSubmittedSuccessfully() { 547 void DeviceStatusCollector::OnSubmittedSuccessfully() {
488 TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_, 548 TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 location.SetDouble(kSpeed, position.speed); 609 location.SetDouble(kSpeed, position.speed);
550 location.SetString(kTimestamp, 610 location.SetString(kTimestamp,
551 base::Int64ToString(position.timestamp.ToInternalValue())); 611 base::Int64ToString(position.timestamp.ToInternalValue()));
552 local_state_->Set(prefs::kDeviceLocation, location); 612 local_state_->Set(prefs::kDeviceLocation, location);
553 } 613 }
554 614
555 ScheduleGeolocationUpdateRequest(); 615 ScheduleGeolocationUpdateRequest();
556 } 616 }
557 617
558 } // namespace policy 618 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698