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

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

Issue 18348016: If requested, report network interfaces to management server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test. Created 7 years, 5 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 | Annotate | Revision Log
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/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/browser/chromeos/settings/cros_settings.h" 18 #include "chrome/browser/chromeos/settings/cros_settings.h"
19 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 19 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
20 #include "chrome/browser/chromeos/system/statistics_provider.h" 20 #include "chrome/browser/chromeos/system/statistics_provider.h"
21 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" 21 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
22 #include "chrome/browser/prefs/scoped_user_pref_update.h" 22 #include "chrome/browser/prefs/scoped_user_pref_update.h"
23 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
24 #include "chrome/common/chrome_version_info.h" 24 #include "chrome/common/chrome_version_info.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "chromeos/network/device_state.h"
27 #include "chromeos/network/network_handler.h"
28 #include "chromeos/network/network_state_handler.h"
26 #include "content/public/browser/browser_thread.h" 29 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/notification_details.h" 30 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_source.h" 31 #include "content/public/browser/notification_source.h"
29 32
30 using base::Time; 33 using base::Time;
31 using base::TimeDelta; 34 using base::TimeDelta;
32 using chromeos::VersionLoader; 35 using chromeos::VersionLoader;
33 36
34 namespace em = enterprise_management; 37 namespace em = enterprise_management;
35 38
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 last_idle_check_(Time()), 130 last_idle_check_(Time()),
128 last_reported_day_(0), 131 last_reported_day_(0),
129 duration_for_last_reported_day_(0), 132 duration_for_last_reported_day_(0),
130 geolocation_update_in_progress_(false), 133 geolocation_update_in_progress_(false),
131 statistics_provider_(provider), 134 statistics_provider_(provider),
132 weak_factory_(this), 135 weak_factory_(this),
133 report_version_info_(false), 136 report_version_info_(false),
134 report_activity_times_(false), 137 report_activity_times_(false),
135 report_boot_mode_(false), 138 report_boot_mode_(false),
136 report_location_(false), 139 report_location_(false),
140 report_network_interfaces_(false),
137 context_(new Context()) { 141 context_(new Context()) {
138 if (location_update_requester) { 142 if (location_update_requester) {
139 location_update_requester_ = *location_update_requester; 143 location_update_requester_ = *location_update_requester;
140 } else { 144 } else {
141 location_update_requester_ = 145 location_update_requester_ =
142 base::Bind(&Context::GetLocationUpdate, context_.get()); 146 base::Bind(&Context::GetLocationUpdate, context_.get());
143 } 147 }
144 idle_poll_timer_.Start(FROM_HERE, 148 idle_poll_timer_.Start(FROM_HERE,
145 TimeDelta::FromSeconds(kIdlePollIntervalSeconds), 149 TimeDelta::FromSeconds(kIdlePollIntervalSeconds),
146 this, &DeviceStatusCollector::CheckIdleState); 150 this, &DeviceStatusCollector::CheckIdleState);
147 151
148 cros_settings_ = chromeos::CrosSettings::Get(); 152 cros_settings_ = chromeos::CrosSettings::Get();
149 153
150 // Watch for changes to the individual policies that control what the status 154 // Watch for changes to the individual policies that control what the status
151 // reports contain. 155 // reports contain.
152 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceVersionInfo, this); 156 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceVersionInfo, this);
153 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceActivityTimes, 157 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceActivityTimes,
154 this); 158 this);
155 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceBootMode, this); 159 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceBootMode, this);
156 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceLocation, this); 160 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceLocation, this);
161 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceNetworkInterfaces,
162 this);
157 163
158 // The last known location is persisted in local state. This makes location 164 // The last known location is persisted in local state. This makes location
159 // information available immediately upon startup and avoids the need to 165 // information available immediately upon startup and avoids the need to
160 // reacquire the location on every user session change or browser crash. 166 // reacquire the location on every user session change or browser crash.
161 content::Geoposition position; 167 content::Geoposition position;
162 std::string timestamp_str; 168 std::string timestamp_str;
163 int64 timestamp; 169 int64 timestamp;
164 const base::DictionaryValue* location = 170 const base::DictionaryValue* location =
165 local_state_->GetDictionary(prefs::kDeviceLocation); 171 local_state_->GetDictionary(prefs::kDeviceLocation);
166 if (location->GetDouble(kLatitude, &position.latitude) && 172 if (location->GetDouble(kLatitude, &position.latitude) &&
(...skipping 22 matching lines...) Expand all
189 &tracker_); 195 &tracker_);
190 } 196 }
191 197
192 DeviceStatusCollector::~DeviceStatusCollector() { 198 DeviceStatusCollector::~DeviceStatusCollector() {
193 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceVersionInfo, 199 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceVersionInfo,
194 this); 200 this);
195 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceActivityTimes, 201 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceActivityTimes,
196 this); 202 this);
197 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceBootMode, this); 203 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceBootMode, this);
198 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceLocation, this); 204 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceLocation, this);
205 cros_settings_->RemoveSettingsObserver(
206 chromeos::kReportDeviceNetworkInterfaces, this);
199 } 207 }
200 208
201 // static 209 // static
202 void DeviceStatusCollector::RegisterPrefs(PrefRegistrySimple* registry) { 210 void DeviceStatusCollector::RegisterPrefs(PrefRegistrySimple* registry) {
203 registry->RegisterDictionaryPref(prefs::kDeviceActivityTimes, 211 registry->RegisterDictionaryPref(prefs::kDeviceActivityTimes,
204 new base::DictionaryValue); 212 new base::DictionaryValue);
205 registry->RegisterDictionaryPref(prefs::kDeviceLocation, 213 registry->RegisterDictionaryPref(prefs::kDeviceLocation,
206 new base::DictionaryValue); 214 new base::DictionaryValue);
207 } 215 }
208 216
(...skipping 14 matching lines...) Expand all
223 return; 231 return;
224 } 232 }
225 cros_settings_->GetBoolean( 233 cros_settings_->GetBoolean(
226 chromeos::kReportDeviceVersionInfo, &report_version_info_); 234 chromeos::kReportDeviceVersionInfo, &report_version_info_);
227 cros_settings_->GetBoolean( 235 cros_settings_->GetBoolean(
228 chromeos::kReportDeviceActivityTimes, &report_activity_times_); 236 chromeos::kReportDeviceActivityTimes, &report_activity_times_);
229 cros_settings_->GetBoolean( 237 cros_settings_->GetBoolean(
230 chromeos::kReportDeviceBootMode, &report_boot_mode_); 238 chromeos::kReportDeviceBootMode, &report_boot_mode_);
231 cros_settings_->GetBoolean( 239 cros_settings_->GetBoolean(
232 chromeos::kReportDeviceLocation, &report_location_); 240 chromeos::kReportDeviceLocation, &report_location_);
241 cros_settings_->GetBoolean(
242 chromeos::kReportDeviceNetworkInterfaces, &report_network_interfaces_);
233 243
234 if (report_location_) { 244 if (report_location_) {
235 ScheduleGeolocationUpdateRequest(); 245 ScheduleGeolocationUpdateRequest();
236 } else { 246 } else {
237 geolocation_update_timer_.Stop(); 247 geolocation_update_timer_.Stop();
238 position_ = content::Geoposition(); 248 position_ = content::Geoposition();
239 local_state_->ClearPref(prefs::kDeviceLocation); 249 local_state_->ClearPref(prefs::kDeviceLocation);
240 } 250 }
241 } 251 }
242 252
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 if (position_.altitude_accuracy >= 0.) 408 if (position_.altitude_accuracy >= 0.)
399 location->set_altitude_accuracy(position_.altitude_accuracy); 409 location->set_altitude_accuracy(position_.altitude_accuracy);
400 if (position_.heading >= 0. && position_.heading <= 360) 410 if (position_.heading >= 0. && position_.heading <= 360)
401 location->set_heading(position_.heading); 411 location->set_heading(position_.heading);
402 if (position_.speed >= 0.) 412 if (position_.speed >= 0.)
403 location->set_speed(position_.speed); 413 location->set_speed(position_.speed);
404 location->set_error_code(em::DeviceLocation::ERROR_CODE_NONE); 414 location->set_error_code(em::DeviceLocation::ERROR_CODE_NONE);
405 } 415 }
406 } 416 }
407 417
418 void DeviceStatusCollector::GetNetworkInterfaces(
419 em::DeviceStatusReportRequest* request) {
420 chromeos::NetworkStateHandler::DeviceStateList device_list;
421 chromeos::NetworkHandler::Get()->network_state_handler()->GetDeviceList(
422 &device_list);
423
424 chromeos::NetworkStateHandler::DeviceStateList::const_iterator device;
pneubeck (no reviews) 2013/07/04 15:51:48 nit: alternatively, typedef chromeos::NetworkState
Mattias Nissler (ping if slow) 2013/07/11 17:41:46 I only need the type once, and I'd have to break t
pneubeck (no reviews) 2013/07/11 18:49:31 FWIW, chromeos::NetworkStateHandler::DeviceStateLi
Mattias Nissler (ping if slow) 2013/07/12 08:11:55 Oh right, I misread your comment to typedef the it
425 for (device = device_list.begin(); device != device_list.end(); ++device) {
426 em::NetworkInterface* interface = request->add_network_interface();
427 if ((*device)->type().empty())
428 continue;
pneubeck (no reviews) 2013/07/04 15:51:48 in this case, an empty NetworkInterface would have
Mattias Nissler (ping if slow) 2013/07/11 17:41:46 I don't think so, hence I skip this case. The upda
429
430 interface->set_type((*device)->type());
431 if (!(*device)->mac_address().empty())
432 interface->set_mac_address((*device)->mac_address());
433 if (!(*device)->meid().empty())
434 interface->set_meid((*device)->meid());
435 }
436 }
437
408 void DeviceStatusCollector::GetStatus(em::DeviceStatusReportRequest* request) { 438 void DeviceStatusCollector::GetStatus(em::DeviceStatusReportRequest* request) {
409 // TODO(mnissler): Remove once the old cloud policy stack is retired. The old 439 // TODO(mnissler): Remove once the old cloud policy stack is retired. The old
410 // stack doesn't support reporting successful submissions back to here, so 440 // stack doesn't support reporting successful submissions back to here, so
411 // just assume whatever ends up in |request| gets submitted successfully. 441 // just assume whatever ends up in |request| gets submitted successfully.
412 GetDeviceStatus(request); 442 GetDeviceStatus(request);
413 OnSubmittedSuccessfully(); 443 OnSubmittedSuccessfully();
414 } 444 }
415 445
416 bool DeviceStatusCollector::GetDeviceStatus( 446 bool DeviceStatusCollector::GetDeviceStatus(
417 em::DeviceStatusReportRequest* status) { 447 em::DeviceStatusReportRequest* status) {
418 if (report_activity_times_) 448 if (report_activity_times_)
419 GetActivityTimes(status); 449 GetActivityTimes(status);
420 450
421 if (report_version_info_) 451 if (report_version_info_)
422 GetVersionInfo(status); 452 GetVersionInfo(status);
423 453
424 if (report_boot_mode_) 454 if (report_boot_mode_)
425 GetBootMode(status); 455 GetBootMode(status);
426 456
427 if (report_location_) 457 if (report_location_)
428 GetLocation(status); 458 GetLocation(status);
429 459
460 if (report_network_interfaces_)
461 GetNetworkInterfaces(status);
462
430 return true; 463 return true;
431 } 464 }
432 465
433 bool DeviceStatusCollector::GetSessionStatus( 466 bool DeviceStatusCollector::GetSessionStatus(
434 em::SessionStatusReportRequest* status) { 467 em::SessionStatusReportRequest* status) {
435 return false; 468 return false;
436 } 469 }
437 470
438 void DeviceStatusCollector::OnSubmittedSuccessfully() { 471 void DeviceStatusCollector::OnSubmittedSuccessfully() {
439 TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_, 472 TrimStoredActivityPeriods(last_reported_day_, duration_for_last_reported_day_,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 location.SetDouble(kSpeed, position.speed); 539 location.SetDouble(kSpeed, position.speed);
507 location.SetString(kTimestamp, 540 location.SetString(kTimestamp,
508 base::Int64ToString(position.timestamp.ToInternalValue())); 541 base::Int64ToString(position.timestamp.ToInternalValue()));
509 local_state_->Set(prefs::kDeviceLocation, location); 542 local_state_->Set(prefs::kDeviceLocation, location);
510 } 543 }
511 544
512 ScheduleGeolocationUpdateRequest(); 545 ScheduleGeolocationUpdateRequest();
513 } 546 }
514 547
515 } // namespace policy 548 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698