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

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

Issue 23494053: Remove NOTIFICATION_SYSTEM_SETTING_CHANGED, switch CrosSettings to base::CallbackRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: trailing space Created 7 years, 3 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/chrome_notification_types.h"
19 #include "chrome/browser/chromeos/settings/cros_settings.h" 18 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #include "chrome/browser/chromeos/settings/cros_settings_names.h" 19 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
21 #include "chrome/browser/chromeos/system/statistics_provider.h" 20 #include "chrome/browser/chromeos/system/statistics_provider.h"
22 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" 21 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h"
23 #include "chrome/browser/prefs/scoped_user_pref_update.h" 22 #include "chrome/browser/prefs/scoped_user_pref_update.h"
24 #include "chrome/common/chrome_version_info.h" 23 #include "chrome/common/chrome_version_info.h"
25 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
26 #include "chromeos/network/device_state.h" 25 #include "chromeos/network/device_state.h"
27 #include "chromeos/network/network_handler.h" 26 #include "chromeos/network/network_handler.h"
28 #include "chromeos/network/network_state_handler.h" 27 #include "chromeos/network/network_state_handler.h"
29 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
30 #include "content/public/browser/notification_details.h"
31 #include "content/public/browser/notification_source.h"
32 #include "third_party/cros_system_api/dbus/service_constants.h" 29 #include "third_party/cros_system_api/dbus/service_constants.h"
33 30
34 using base::Time; 31 using base::Time;
35 using base::TimeDelta; 32 using base::TimeDelta;
36 using chromeos::VersionLoader; 33 using chromeos::VersionLoader;
37 34
38 namespace em = enterprise_management; 35 namespace em = enterprise_management;
39 36
40 namespace { 37 namespace {
41 // How many seconds of inactivity triggers the idle state. 38 // How many seconds of inactivity triggers the idle state.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 base::Bind(&Context::GetLocationUpdate, context_.get()); 138 base::Bind(&Context::GetLocationUpdate, context_.get());
142 } 139 }
143 idle_poll_timer_.Start(FROM_HERE, 140 idle_poll_timer_.Start(FROM_HERE,
144 TimeDelta::FromSeconds(kIdlePollIntervalSeconds), 141 TimeDelta::FromSeconds(kIdlePollIntervalSeconds),
145 this, &DeviceStatusCollector::CheckIdleState); 142 this, &DeviceStatusCollector::CheckIdleState);
146 143
147 cros_settings_ = chromeos::CrosSettings::Get(); 144 cros_settings_ = chromeos::CrosSettings::Get();
148 145
149 // Watch for changes to the individual policies that control what the status 146 // Watch for changes to the individual policies that control what the status
150 // reports contain. 147 // reports contain.
151 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceVersionInfo, this); 148 base::Closure callback =
152 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceActivityTimes, 149 base::Bind(&DeviceStatusCollector::UpdateReportingSettings,
153 this); 150 base::Unretained(this));
154 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceBootMode, this); 151 version_info_subscription_ = cros_settings_->AddSettingsObserver(
155 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceLocation, this); 152 chromeos::kReportDeviceVersionInfo, callback);
156 cros_settings_->AddSettingsObserver(chromeos::kReportDeviceNetworkInterfaces, 153 activity_times_subscription_ = cros_settings_->AddSettingsObserver(
157 this); 154 chromeos::kReportDeviceActivityTimes, callback);
155 boot_mode_subscription_ = cros_settings_->AddSettingsObserver(
156 chromeos::kReportDeviceBootMode, callback);
157 location_subscription_ = cros_settings_->AddSettingsObserver(
158 chromeos::kReportDeviceLocation, callback);
159 network_interfaces_subscription_ = cros_settings_->AddSettingsObserver(
160 chromeos::kReportDeviceNetworkInterfaces, callback);
158 161
159 // The last known location is persisted in local state. This makes location 162 // The last known location is persisted in local state. This makes location
160 // information available immediately upon startup and avoids the need to 163 // information available immediately upon startup and avoids the need to
161 // reacquire the location on every user session change or browser crash. 164 // reacquire the location on every user session change or browser crash.
162 content::Geoposition position; 165 content::Geoposition position;
163 std::string timestamp_str; 166 std::string timestamp_str;
164 int64 timestamp; 167 int64 timestamp;
165 const base::DictionaryValue* location = 168 const base::DictionaryValue* location =
166 local_state_->GetDictionary(prefs::kDeviceLocation); 169 local_state_->GetDictionary(prefs::kDeviceLocation);
167 if (location->GetDouble(kLatitude, &position.latitude) && 170 if (location->GetDouble(kLatitude, &position.latitude) &&
(...skipping 16 matching lines...) Expand all
184 version_loader_.GetVersion( 187 version_loader_.GetVersion(
185 VersionLoader::VERSION_FULL, 188 VersionLoader::VERSION_FULL,
186 base::Bind(&DeviceStatusCollector::OnOSVersion, base::Unretained(this)), 189 base::Bind(&DeviceStatusCollector::OnOSVersion, base::Unretained(this)),
187 &tracker_); 190 &tracker_);
188 version_loader_.GetFirmware( 191 version_loader_.GetFirmware(
189 base::Bind(&DeviceStatusCollector::OnOSFirmware, base::Unretained(this)), 192 base::Bind(&DeviceStatusCollector::OnOSFirmware, base::Unretained(this)),
190 &tracker_); 193 &tracker_);
191 } 194 }
192 195
193 DeviceStatusCollector::~DeviceStatusCollector() { 196 DeviceStatusCollector::~DeviceStatusCollector() {
194 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceVersionInfo,
195 this);
196 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceActivityTimes,
197 this);
198 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceBootMode, this);
199 cros_settings_->RemoveSettingsObserver(chromeos::kReportDeviceLocation, this);
200 cros_settings_->RemoveSettingsObserver(
201 chromeos::kReportDeviceNetworkInterfaces, this);
202 } 197 }
203 198
204 // static 199 // static
205 void DeviceStatusCollector::RegisterPrefs(PrefRegistrySimple* registry) { 200 void DeviceStatusCollector::RegisterPrefs(PrefRegistrySimple* registry) {
206 registry->RegisterDictionaryPref(prefs::kDeviceActivityTimes, 201 registry->RegisterDictionaryPref(prefs::kDeviceActivityTimes,
207 new base::DictionaryValue); 202 new base::DictionaryValue);
208 registry->RegisterDictionaryPref(prefs::kDeviceLocation, 203 registry->RegisterDictionaryPref(prefs::kDeviceLocation,
209 new base::DictionaryValue); 204 new base::DictionaryValue);
210 } 205 }
211 206
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 } 487 }
493 488
494 void DeviceStatusCollector::OnOSVersion(const std::string& version) { 489 void DeviceStatusCollector::OnOSVersion(const std::string& version) {
495 os_version_ = version; 490 os_version_ = version;
496 } 491 }
497 492
498 void DeviceStatusCollector::OnOSFirmware(const std::string& version) { 493 void DeviceStatusCollector::OnOSFirmware(const std::string& version) {
499 firmware_version_ = version; 494 firmware_version_ = version;
500 } 495 }
501 496
502 void DeviceStatusCollector::Observe(
503 int type,
504 const content::NotificationSource& source,
505 const content::NotificationDetails& details) {
506 if (type == chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED)
507 UpdateReportingSettings();
508 else
509 NOTREACHED();
510 }
511
512 void DeviceStatusCollector::ScheduleGeolocationUpdateRequest() { 497 void DeviceStatusCollector::ScheduleGeolocationUpdateRequest() {
513 if (geolocation_update_timer_.IsRunning() || geolocation_update_in_progress_) 498 if (geolocation_update_timer_.IsRunning() || geolocation_update_in_progress_)
514 return; 499 return;
515 500
516 if (position_.Validate()) { 501 if (position_.Validate()) {
517 TimeDelta elapsed = GetCurrentTime() - position_.timestamp; 502 TimeDelta elapsed = GetCurrentTime() - position_.timestamp;
518 TimeDelta interval = 503 TimeDelta interval =
519 TimeDelta::FromSeconds(kGeolocationPollIntervalSeconds); 504 TimeDelta::FromSeconds(kGeolocationPollIntervalSeconds);
520 if (elapsed > interval) { 505 if (elapsed > interval) {
521 geolocation_update_in_progress_ = true; 506 geolocation_update_in_progress_ = true;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 location.SetDouble(kSpeed, position.speed); 542 location.SetDouble(kSpeed, position.speed);
558 location.SetString(kTimestamp, 543 location.SetString(kTimestamp,
559 base::Int64ToString(position.timestamp.ToInternalValue())); 544 base::Int64ToString(position.timestamp.ToInternalValue()));
560 local_state_->Set(prefs::kDeviceLocation, location); 545 local_state_->Set(prefs::kDeviceLocation, location);
561 } 546 }
562 547
563 ScheduleGeolocationUpdateRequest(); 548 ScheduleGeolocationUpdateRequest();
564 } 549 }
565 550
566 } // namespace policy 551 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/device_status_collector.h ('k') | chrome/browser/chromeos/settings/cros_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698