Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/arc/arc_settings_service.h" | 5 #include "chrome/browser/chromeos/arc/arc_settings_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | |
| 13 #include "chrome/browser/chromeos/settings/cros_settings.h" | 14 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 16 #include "chromeos/settings/cros_settings_names.h" | 17 #include "chromeos/settings/cros_settings_names.h" |
| 17 #include "chromeos/settings/timezone_settings.h" | 18 #include "chromeos/settings/timezone_settings.h" |
| 18 #include "components/arc/intent_helper/font_size_util.h" | 19 #include "components/arc/intent_helper/font_size_util.h" |
| 19 #include "components/prefs/pref_change_registrar.h" | 20 #include "components/prefs/pref_change_registrar.h" |
| 20 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
| 21 #include "components/proxy_config/proxy_config_dictionary.h" | 22 #include "components/proxy_config/proxy_config_dictionary.h" |
| 22 #include "components/proxy_config/proxy_config_pref_names.h" | 23 #include "components/proxy_config/proxy_config_pref_names.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 57 } |
| 57 | 58 |
| 58 } // namespace | 59 } // namespace |
| 59 | 60 |
| 60 namespace arc { | 61 namespace arc { |
| 61 | 62 |
| 62 // Listens to changes for select Chrome settings (prefs) that Android cares | 63 // Listens to changes for select Chrome settings (prefs) that Android cares |
| 63 // about and sends the new values to Android to keep the state in sync. | 64 // about and sends the new values to Android to keep the state in sync. |
| 64 class ArcSettingsServiceImpl | 65 class ArcSettingsServiceImpl |
| 65 : public chromeos::system::TimezoneSettings::Observer, | 66 : public chromeos::system::TimezoneSettings::Observer, |
| 66 public device::BluetoothAdapter::Observer { | 67 public device::BluetoothAdapter::Observer, |
| 68 public ArcAuthService::Observer { | |
| 67 public: | 69 public: |
| 68 explicit ArcSettingsServiceImpl(ArcBridgeService* arc_bridge_service); | 70 explicit ArcSettingsServiceImpl(ArcBridgeService* arc_bridge_service); |
| 69 ~ArcSettingsServiceImpl() override; | 71 ~ArcSettingsServiceImpl() override; |
| 70 | 72 |
| 71 // Called when a Chrome pref we have registered an observer for has changed. | 73 // Called when a Chrome pref we have registered an observer for has changed. |
| 72 // Obtains the new pref value and sends it to Android. | 74 // Obtains the new pref value and sends it to Android. |
| 73 void OnPrefChanged(const std::string& pref_name) const; | 75 void OnPrefChanged(const std::string& pref_name) const; |
| 74 | 76 |
| 75 // TimezoneSettings::Observer | 77 // TimezoneSettings::Observer: |
| 76 void TimezoneChanged(const icu::TimeZone& timezone) override; | 78 void TimezoneChanged(const icu::TimeZone& timezone) override; |
| 77 | 79 |
| 78 // BluetoothAdapter::Observer | 80 // BluetoothAdapter::Observer: |
| 79 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, | 81 void AdapterPoweredChanged(device::BluetoothAdapter* adapter, |
| 80 bool powered) override; | 82 bool powered) override; |
| 81 | 83 |
| 84 // ArcAuthService::Observer: | |
| 85 void OnInitialStart() override; | |
| 86 | |
| 82 private: | 87 private: |
| 83 // Registers to observe changes for Chrome settings we care about. | 88 // Registers to observe changes for Chrome settings we care about. |
| 84 void StartObservingSettingsChanges(); | 89 void StartObservingSettingsChanges(); |
| 85 | 90 |
| 86 // Stops listening for Chrome settings changes. | 91 // Stops listening for Chrome settings changes. |
| 87 void StopObservingSettingsChanges(); | 92 void StopObservingSettingsChanges(); |
| 88 | 93 |
| 89 // Retrives Chrome's state for the settings and send it to Android. | 94 // Retrieves Chrome's state for the settings that need to be synced on each |
| 90 void SyncAllPrefs() const; | 95 // Android boot and send it to Android. |
| 96 void SyncRuntimeSettings() const; | |
| 97 // Send settings that need to be synced only on Android first start to | |
| 98 // Android. | |
| 99 void SyncInitialSettings() const; | |
| 91 void SyncFontSize() const; | 100 void SyncFontSize() const; |
| 92 void SyncLocale() const; | 101 void SyncLocale() const; |
| 93 void SyncProxySettings() const; | 102 void SyncProxySettings() const; |
| 94 void SyncReportingConsent() const; | 103 void SyncReportingConsent() const; |
| 95 void SyncSpokenFeedbackEnabled() const; | 104 void SyncSpokenFeedbackEnabled() const; |
| 96 void SyncTimeZone() const; | 105 void SyncTimeZone() const; |
| 97 void SyncUse24HourClock() const; | 106 void SyncUse24HourClock() const; |
| 98 void SyncBackupEnabled() const; | 107 void SyncBackupEnabled() const; |
| 108 void SyncLocationServiceEnabled() const; | |
| 99 | 109 |
| 100 void OnBluetoothAdapterInitialized( | 110 void OnBluetoothAdapterInitialized( |
| 101 scoped_refptr<device::BluetoothAdapter> adapter); | 111 scoped_refptr<device::BluetoothAdapter> adapter); |
| 102 | 112 |
| 103 // Registers to listen to a particular perf. | 113 // Registers to listen to a particular perf. |
| 104 void AddPrefToObserve(const std::string& pref_name); | 114 void AddPrefToObserve(const std::string& pref_name); |
| 105 | 115 |
| 106 // Returns the integer value of the pref. pref_name must exist. | 116 // Returns the integer value of the pref. pref_name must exist. |
| 107 int GetIntegerPref(const std::string& pref_name) const; | 117 int GetIntegerPref(const std::string& pref_name) const; |
| 108 | 118 |
| 119 // Sends boolean pref broadcast to the delegate. | |
| 120 void SendBoolPrefSettingsBroadcast(const std::string& pref_name, | |
| 121 const std::string& action) const; | |
| 122 | |
| 109 // Sends a broadcast to the delegate. | 123 // Sends a broadcast to the delegate. |
| 110 void SendSettingsBroadcast(const std::string& action, | 124 void SendSettingsBroadcast(const std::string& action, |
| 111 const base::DictionaryValue& extras) const; | 125 const base::DictionaryValue& extras) const; |
| 112 | 126 |
| 113 // Manages pref observation registration. | 127 // Manages pref observation registration. |
| 114 PrefChangeRegistrar registrar_; | 128 PrefChangeRegistrar registrar_; |
| 115 | 129 |
| 116 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> | 130 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> |
| 117 reporting_consent_subscription_; | 131 reporting_consent_subscription_; |
| 118 ArcBridgeService* const arc_bridge_service_; | 132 ArcBridgeService* const arc_bridge_service_; |
| 119 | 133 |
| 120 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; | 134 scoped_refptr<device::BluetoothAdapter> bluetooth_adapter_; |
| 121 | 135 |
| 122 // WeakPtrFactory to use for callback for getting the bluetooth adapter. | 136 // WeakPtrFactory to use for callback for getting the bluetooth adapter. |
| 123 base::WeakPtrFactory<ArcSettingsServiceImpl> weak_factory_; | 137 base::WeakPtrFactory<ArcSettingsServiceImpl> weak_factory_; |
| 124 | 138 |
| 125 DISALLOW_COPY_AND_ASSIGN(ArcSettingsServiceImpl); | 139 DISALLOW_COPY_AND_ASSIGN(ArcSettingsServiceImpl); |
| 126 }; | 140 }; |
| 127 | 141 |
| 128 ArcSettingsServiceImpl::ArcSettingsServiceImpl( | 142 ArcSettingsServiceImpl::ArcSettingsServiceImpl( |
| 129 ArcBridgeService* arc_bridge_service) | 143 ArcBridgeService* arc_bridge_service) |
| 130 : arc_bridge_service_(arc_bridge_service), weak_factory_(this) { | 144 : arc_bridge_service_(arc_bridge_service), weak_factory_(this) { |
| 131 StartObservingSettingsChanges(); | 145 StartObservingSettingsChanges(); |
| 132 SyncAllPrefs(); | 146 SyncRuntimeSettings(); |
| 147 DCHECK(ArcAuthService::Get()); | |
| 148 ArcAuthService::Get()->AddObserver(this); | |
| 133 } | 149 } |
| 134 | 150 |
| 135 ArcSettingsServiceImpl::~ArcSettingsServiceImpl() { | 151 ArcSettingsServiceImpl::~ArcSettingsServiceImpl() { |
| 136 StopObservingSettingsChanges(); | 152 StopObservingSettingsChanges(); |
| 137 | 153 |
| 138 if (bluetooth_adapter_) { | 154 ArcAuthService* arc_auth_service = ArcAuthService::Get(); |
| 155 if (arc_auth_service) | |
| 156 arc_auth_service->RemoveObserver(this); | |
| 157 | |
| 158 if (bluetooth_adapter_) | |
| 139 bluetooth_adapter_->RemoveObserver(this); | 159 bluetooth_adapter_->RemoveObserver(this); |
| 140 } | |
| 141 } | 160 } |
| 142 | 161 |
| 143 void ArcSettingsServiceImpl::StartObservingSettingsChanges() { | 162 void ArcSettingsServiceImpl::StartObservingSettingsChanges() { |
| 144 Profile* profile = ProfileManager::GetActiveUserProfile(); | 163 Profile* profile = ProfileManager::GetActiveUserProfile(); |
| 145 registrar_.Init(profile->GetPrefs()); | 164 registrar_.Init(profile->GetPrefs()); |
| 146 | 165 |
| 147 AddPrefToObserve(prefs::kWebKitDefaultFixedFontSize); | 166 AddPrefToObserve(prefs::kWebKitDefaultFixedFontSize); |
| 148 AddPrefToObserve(prefs::kWebKitDefaultFontSize); | 167 AddPrefToObserve(prefs::kWebKitDefaultFontSize); |
| 149 AddPrefToObserve(prefs::kWebKitMinimumFontSize); | 168 AddPrefToObserve(prefs::kWebKitMinimumFontSize); |
| 150 AddPrefToObserve(prefs::kAccessibilitySpokenFeedbackEnabled); | 169 AddPrefToObserve(prefs::kAccessibilitySpokenFeedbackEnabled); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 168 | 187 |
| 169 void ArcSettingsServiceImpl::OnBluetoothAdapterInitialized( | 188 void ArcSettingsServiceImpl::OnBluetoothAdapterInitialized( |
| 170 scoped_refptr<device::BluetoothAdapter> adapter) { | 189 scoped_refptr<device::BluetoothAdapter> adapter) { |
| 171 DCHECK(adapter); | 190 DCHECK(adapter); |
| 172 bluetooth_adapter_ = adapter; | 191 bluetooth_adapter_ = adapter; |
| 173 bluetooth_adapter_->AddObserver(this); | 192 bluetooth_adapter_->AddObserver(this); |
| 174 | 193 |
| 175 AdapterPoweredChanged(adapter.get(), adapter->IsPowered()); | 194 AdapterPoweredChanged(adapter.get(), adapter->IsPowered()); |
| 176 } | 195 } |
| 177 | 196 |
| 178 void ArcSettingsServiceImpl::SyncAllPrefs() const { | 197 void ArcSettingsServiceImpl::OnInitialStart() { |
| 198 SyncInitialSettings(); | |
| 199 } | |
| 200 | |
| 201 void ArcSettingsServiceImpl::SyncRuntimeSettings() const { | |
| 179 SyncFontSize(); | 202 SyncFontSize(); |
| 180 SyncLocale(); | 203 SyncLocale(); |
| 181 SyncProxySettings(); | 204 SyncProxySettings(); |
| 182 SyncReportingConsent(); | 205 SyncReportingConsent(); |
| 183 SyncSpokenFeedbackEnabled(); | 206 SyncSpokenFeedbackEnabled(); |
| 184 SyncTimeZone(); | 207 SyncTimeZone(); |
| 185 SyncUse24HourClock(); | 208 SyncUse24HourClock(); |
| 186 } | 209 } |
| 187 | 210 |
| 211 void ArcSettingsServiceImpl::SyncInitialSettings() const { | |
| 212 SyncBackupEnabled(); | |
| 213 SyncLocationServiceEnabled(); | |
| 214 } | |
| 215 | |
| 188 void ArcSettingsServiceImpl::StopObservingSettingsChanges() { | 216 void ArcSettingsServiceImpl::StopObservingSettingsChanges() { |
| 189 registrar_.RemoveAll(); | 217 registrar_.RemoveAll(); |
| 190 reporting_consent_subscription_.reset(); | 218 reporting_consent_subscription_.reset(); |
| 191 | 219 |
| 192 TimezoneSettings::GetInstance()->RemoveObserver(this); | 220 TimezoneSettings::GetInstance()->RemoveObserver(this); |
| 193 } | 221 } |
| 194 | 222 |
| 195 void ArcSettingsServiceImpl::AddPrefToObserve(const std::string& pref_name) { | 223 void ArcSettingsServiceImpl::AddPrefToObserve(const std::string& pref_name) { |
| 196 registrar_.Add(pref_name, base::Bind(&ArcSettingsServiceImpl::OnPrefChanged, | 224 registrar_.Add(pref_name, base::Bind(&ArcSettingsServiceImpl::OnPrefChanged, |
| 197 base::Unretained(this))); | 225 base::Unretained(this))); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 210 if (pref_name == prefs::kAccessibilitySpokenFeedbackEnabled) { | 238 if (pref_name == prefs::kAccessibilitySpokenFeedbackEnabled) { |
| 211 SyncSpokenFeedbackEnabled(); | 239 SyncSpokenFeedbackEnabled(); |
| 212 } else if (pref_name == prefs::kWebKitDefaultFixedFontSize || | 240 } else if (pref_name == prefs::kWebKitDefaultFixedFontSize || |
| 213 pref_name == prefs::kWebKitDefaultFontSize || | 241 pref_name == prefs::kWebKitDefaultFontSize || |
| 214 pref_name == prefs::kWebKitMinimumFontSize) { | 242 pref_name == prefs::kWebKitMinimumFontSize) { |
| 215 SyncFontSize(); | 243 SyncFontSize(); |
| 216 } else if (pref_name == prefs::kUse24HourClock) { | 244 } else if (pref_name == prefs::kUse24HourClock) { |
| 217 SyncUse24HourClock(); | 245 SyncUse24HourClock(); |
| 218 } else if (pref_name == proxy_config::prefs::kProxy) { | 246 } else if (pref_name == proxy_config::prefs::kProxy) { |
| 219 SyncProxySettings(); | 247 SyncProxySettings(); |
| 220 } else if (pref_name == prefs::kArcBackupRestoreEnabled) { | |
| 221 SyncBackupEnabled(); | |
|
Sergey Poromov
2016/08/02 15:20:41
Looks like because of removing these lines, backup
khmel
2016/08/02 16:22:44
This code does not make sense. kArcBackupRestoreEn
Sergey Poromov
2016/08/02 17:43:49
What if the pref changes after OptIn, because of p
| |
| 222 } else { | 248 } else { |
| 223 LOG(ERROR) << "Unknown pref changed."; | 249 LOG(ERROR) << "Unknown pref changed."; |
| 224 } | 250 } |
| 225 } | 251 } |
| 226 | 252 |
| 227 void ArcSettingsServiceImpl::TimezoneChanged(const icu::TimeZone& timezone) { | 253 void ArcSettingsServiceImpl::TimezoneChanged(const icu::TimeZone& timezone) { |
| 228 SyncTimeZone(); | 254 SyncTimeZone(); |
| 229 } | 255 } |
| 230 | 256 |
| 231 int ArcSettingsServiceImpl::GetIntegerPref(const std::string& pref_name) const { | 257 int ArcSettingsServiceImpl::GetIntegerPref(const std::string& pref_name) const { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 245 | 271 |
| 246 double android_scale = ConvertFontSizeChromeToAndroid( | 272 double android_scale = ConvertFontSizeChromeToAndroid( |
| 247 default_size, default_fixed_size, minimum_size); | 273 default_size, default_fixed_size, minimum_size); |
| 248 | 274 |
| 249 base::DictionaryValue extras; | 275 base::DictionaryValue extras; |
| 250 extras.SetDouble("scale", android_scale); | 276 extras.SetDouble("scale", android_scale); |
| 251 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_FONT_SCALE", | 277 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_FONT_SCALE", |
| 252 extras); | 278 extras); |
| 253 } | 279 } |
| 254 | 280 |
| 255 void ArcSettingsServiceImpl::SyncSpokenFeedbackEnabled() const { | 281 void ArcSettingsServiceImpl::SendBoolPrefSettingsBroadcast( |
| 256 const PrefService::Preference* pref = registrar_.prefs()->FindPreference( | 282 const std::string& pref_name, |
| 257 prefs::kAccessibilitySpokenFeedbackEnabled); | 283 const std::string& action) const { |
| 284 const PrefService::Preference* pref = | |
| 285 registrar_.prefs()->FindPreference(pref_name); | |
| 258 DCHECK(pref); | 286 DCHECK(pref); |
| 259 bool enabled = false; | 287 bool enabled = false; |
| 260 bool value_exists = pref->GetValue()->GetAsBoolean(&enabled); | 288 bool value_exists = pref->GetValue()->GetAsBoolean(&enabled); |
| 261 DCHECK(value_exists); | 289 DCHECK(value_exists); |
| 262 base::DictionaryValue extras; | 290 base::DictionaryValue extras; |
| 263 extras.SetBoolean("enabled", enabled); | 291 extras.SetBoolean("enabled", enabled); |
| 264 SendSettingsBroadcast( | 292 extras.SetBoolean("managed", !pref->IsUserModifiable()); |
| 265 "org.chromium.arc.intent_helper.SET_SPOKEN_FEEDBACK_ENABLED", extras); | 293 SendSettingsBroadcast(action, extras); |
| 294 } | |
| 295 | |
| 296 void ArcSettingsServiceImpl::SyncSpokenFeedbackEnabled() const { | |
| 297 SendBoolPrefSettingsBroadcast( | |
| 298 prefs::kAccessibilitySpokenFeedbackEnabled, | |
| 299 "org.chromium.arc.intent_helper.SET_SPOKEN_FEEDBACK_ENABLED"); | |
| 266 } | 300 } |
| 267 | 301 |
| 268 void ArcSettingsServiceImpl::SyncLocale() const { | 302 void ArcSettingsServiceImpl::SyncLocale() const { |
| 269 const PrefService::Preference* pref = | 303 const PrefService::Preference* pref = |
| 270 registrar_.prefs()->FindPreference(prefs::kApplicationLocale); | 304 registrar_.prefs()->FindPreference(prefs::kApplicationLocale); |
| 271 DCHECK(pref); | 305 DCHECK(pref); |
| 272 std::string locale; | 306 std::string locale; |
| 273 bool value_exists = pref->GetValue()->GetAsString(&locale); | 307 bool value_exists = pref->GetValue()->GetAsString(&locale); |
| 274 DCHECK(value_exists); | 308 DCHECK(value_exists); |
| 275 base::DictionaryValue extras; | 309 base::DictionaryValue extras; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 360 } | 394 } |
| 361 default: | 395 default: |
| 362 LOG(ERROR) << "Incorrect proxy mode."; | 396 LOG(ERROR) << "Incorrect proxy mode."; |
| 363 return; | 397 return; |
| 364 } | 398 } |
| 365 | 399 |
| 366 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_PROXY", extras); | 400 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_PROXY", extras); |
| 367 } | 401 } |
| 368 | 402 |
| 369 void ArcSettingsServiceImpl::SyncBackupEnabled() const { | 403 void ArcSettingsServiceImpl::SyncBackupEnabled() const { |
| 370 const PrefService::Preference* const pref = | 404 SendBoolPrefSettingsBroadcast( |
| 371 registrar_.prefs()->FindPreference(prefs::kArcBackupRestoreEnabled); | 405 prefs::kArcBackupRestoreEnabled, |
| 372 DCHECK(pref); | 406 "org.chromium.arc.intent_helper.SET_BACKUP_ENABLED"); |
| 373 bool enabled = false; | 407 } |
| 374 bool value_exists = pref->GetValue()->GetAsBoolean(&enabled); | 408 |
| 375 DCHECK(value_exists); | 409 void ArcSettingsServiceImpl::SyncLocationServiceEnabled() const { |
| 376 base::DictionaryValue extras; | 410 SendBoolPrefSettingsBroadcast( |
| 377 extras.SetBoolean("enabled", enabled); | 411 prefs::kArcLocationServiceEnabled, |
| 378 extras.SetBoolean("managed", !pref->IsUserModifiable()); | 412 "org.chromium.arc.intent_helper.SET_LOCATION_SERVICE_ENABLED"); |
| 379 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_BACKUP_ENABLED", | |
| 380 extras); | |
| 381 } | 413 } |
| 382 | 414 |
| 383 void ArcSettingsServiceImpl::SendSettingsBroadcast( | 415 void ArcSettingsServiceImpl::SendSettingsBroadcast( |
| 384 const std::string& action, | 416 const std::string& action, |
| 385 const base::DictionaryValue& extras) const { | 417 const base::DictionaryValue& extras) const { |
| 386 if (!arc_bridge_service_->intent_helper()->instance()) { | 418 if (!arc_bridge_service_->intent_helper()->instance()) { |
| 387 LOG(ERROR) << "IntentHelper instance is not ready."; | 419 LOG(ERROR) << "IntentHelper instance is not ready."; |
| 388 return; | 420 return; |
| 389 } | 421 } |
| 390 | 422 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 410 | 442 |
| 411 void ArcSettingsService::OnInstanceReady() { | 443 void ArcSettingsService::OnInstanceReady() { |
| 412 impl_.reset(new ArcSettingsServiceImpl(arc_bridge_service())); | 444 impl_.reset(new ArcSettingsServiceImpl(arc_bridge_service())); |
| 413 } | 445 } |
| 414 | 446 |
| 415 void ArcSettingsService::OnInstanceClosed() { | 447 void ArcSettingsService::OnInstanceClosed() { |
| 416 impl_.reset(); | 448 impl_.reset(); |
| 417 } | 449 } |
| 418 | 450 |
| 419 } // namespace arc | 451 } // namespace arc |
| OLD | NEW |