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/intent_helper/arc_settings_service.h" | 5 #include "chrome/browser/chromeos/arc/intent_helper/arc_settings_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 145 |
| 146 void OnBluetoothAdapterInitialized( | 146 void OnBluetoothAdapterInitialized( |
| 147 scoped_refptr<device::BluetoothAdapter> adapter); | 147 scoped_refptr<device::BluetoothAdapter> adapter); |
| 148 | 148 |
| 149 // Registers to listen to a particular perf. | 149 // Registers to listen to a particular perf. |
| 150 void AddPrefToObserve(const std::string& pref_name); | 150 void AddPrefToObserve(const std::string& pref_name); |
| 151 | 151 |
| 152 // Returns the integer value of the pref. pref_name must exist. | 152 // Returns the integer value of the pref. pref_name must exist. |
| 153 int GetIntegerPref(const std::string& pref_name) const; | 153 int GetIntegerPref(const std::string& pref_name) const; |
| 154 | 154 |
| 155 // Gets whether this is a managed pref. | |
| 156 bool IsPrefManaged(const std::string& pref_name) const; | |
| 157 | |
| 155 // Sends boolean pref broadcast to the delegate. | 158 // Sends boolean pref broadcast to the delegate. |
| 156 void SendBoolPrefSettingsBroadcast(const std::string& pref_name, | 159 void SendBoolPrefSettingsBroadcast(const std::string& pref_name, |
| 157 const std::string& action) const; | 160 const std::string& action) const; |
| 158 | 161 |
| 162 // Same as above, except sends a specific boolean value. | |
| 163 void SendBoolValueSettingsBroadcast(bool value, | |
| 164 bool managed, | |
| 165 const std::string& action) const; | |
| 166 | |
| 159 // Sends a broadcast to the delegate. | 167 // Sends a broadcast to the delegate. |
| 160 void SendSettingsBroadcast(const std::string& action, | 168 void SendSettingsBroadcast(const std::string& action, |
| 161 const base::DictionaryValue& extras) const; | 169 const base::DictionaryValue& extras) const; |
| 162 | 170 |
| 163 // Manages pref observation registration. | 171 // Manages pref observation registration. |
| 164 PrefChangeRegistrar registrar_; | 172 PrefChangeRegistrar registrar_; |
| 165 | 173 |
| 166 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> | 174 std::unique_ptr<chromeos::CrosSettings::ObserverSubscription> |
| 167 reporting_consent_subscription_; | 175 reporting_consent_subscription_; |
| 168 ArcBridgeService* const arc_bridge_service_; | 176 ArcBridgeService* const arc_bridge_service_; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 void ArcSettingsServiceImpl::SyncReportingConsent() const { | 491 void ArcSettingsServiceImpl::SyncReportingConsent() const { |
| 484 bool consent = false; | 492 bool consent = false; |
| 485 CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, &consent); | 493 CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, &consent); |
| 486 base::DictionaryValue extras; | 494 base::DictionaryValue extras; |
| 487 extras.SetBoolean("reportingConsent", consent); | 495 extras.SetBoolean("reportingConsent", consent); |
| 488 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_REPORTING_CONSENT", | 496 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_REPORTING_CONSENT", |
| 489 extras); | 497 extras); |
| 490 } | 498 } |
| 491 | 499 |
| 492 void ArcSettingsServiceImpl::SyncSpokenFeedbackEnabled() const { | 500 void ArcSettingsServiceImpl::SyncSpokenFeedbackEnabled() const { |
| 493 std::string setting = | 501 // Chrome spoken feedback triggers enabling of Android spoken feedback. |
| 502 // There are two types of spoken feedback from Android: | |
| 503 // 1. Talkback (default) | |
| 504 // 2. accessibility helper (experimental, works through ChromeVox). | |
| 505 // These two features are mutually exclusive. | |
| 506 | |
| 507 int enabled = GetIntegerPref(prefs::kAccessibilitySpokenFeedbackEnabled); | |
| 508 bool managed = IsPrefManaged(prefs::kAccessibilitySpokenFeedbackEnabled); | |
| 509 | |
| 510 std::string talkback_setting = | |
| 494 "org.chromium.arc.intent_helper.SET_SPOKEN_FEEDBACK_ENABLED"; | 511 "org.chromium.arc.intent_helper.SET_SPOKEN_FEEDBACK_ENABLED"; |
| 512 std::string accessibility_helper_setting = | |
| 513 "org.chromium.arc.intent_helper.SET_ACCESSIBILITY_HELPER_ENABLED"; | |
| 514 | |
| 495 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 515 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 496 chromeos::switches::kEnableChromeVoxArcSupport)) | 516 chromeos::switches::kEnableChromeVoxArcSupport)) { |
| 497 setting = "org.chromium.arc.intent_helper.SET_ACCESSIBILITY_HELPER_ENABLED"; | 517 SendBoolValueSettingsBroadcast(enabled, managed, |
| 518 accessibility_helper_setting); | |
| 498 | 519 |
| 499 SendBoolPrefSettingsBroadcast(prefs::kAccessibilitySpokenFeedbackEnabled, | 520 // Make sure if ChromeVox is on, TalkBack is off. |
| 500 setting); | 521 if (enabled) { |
| 522 SendBoolValueSettingsBroadcast(false, managed, talkback_setting); | |
| 523 } | |
| 524 return; | |
| 525 } | |
| 526 | |
| 527 SendBoolValueSettingsBroadcast(enabled, managed, talkback_setting); | |
| 528 | |
| 529 // Makes sure if Talkback is on, accessibility helper is off. | |
| 530 if (enabled) { | |
|
yawano
2017/03/10 05:05:47
I think this will disable focus highlight if user
David Tseng
2017/03/10 17:51:38
I'm not sure I follow. Are you saying if someone h
yawano
2017/03/13 02:03:24
Sorry, I missed the point that TalkBack also does
| |
| 531 SendBoolValueSettingsBroadcast(false, managed, | |
| 532 accessibility_helper_setting); | |
| 533 } | |
| 501 } | 534 } |
| 502 | 535 |
| 503 void ArcSettingsServiceImpl::SyncTimeZone() const { | 536 void ArcSettingsServiceImpl::SyncTimeZone() const { |
| 504 TimezoneSettings* timezone_settings = TimezoneSettings::GetInstance(); | 537 TimezoneSettings* timezone_settings = TimezoneSettings::GetInstance(); |
| 505 base::string16 timezoneID = timezone_settings->GetCurrentTimezoneID(); | 538 base::string16 timezoneID = timezone_settings->GetCurrentTimezoneID(); |
| 506 base::DictionaryValue extras; | 539 base::DictionaryValue extras; |
| 507 extras.SetString("olsonTimeZone", timezoneID); | 540 extras.SetString("olsonTimeZone", timezoneID); |
| 508 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_TIME_ZONE", extras); | 541 SendSettingsBroadcast("org.chromium.arc.intent_helper.SET_TIME_ZONE", extras); |
| 509 } | 542 } |
| 510 | 543 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 int ArcSettingsServiceImpl::GetIntegerPref(const std::string& pref_name) const { | 584 int ArcSettingsServiceImpl::GetIntegerPref(const std::string& pref_name) const { |
| 552 const PrefService::Preference* pref = | 585 const PrefService::Preference* pref = |
| 553 registrar_.prefs()->FindPreference(pref_name); | 586 registrar_.prefs()->FindPreference(pref_name); |
| 554 DCHECK(pref); | 587 DCHECK(pref); |
| 555 int val = -1; | 588 int val = -1; |
| 556 bool value_exists = pref->GetValue()->GetAsInteger(&val); | 589 bool value_exists = pref->GetValue()->GetAsInteger(&val); |
| 557 DCHECK(value_exists); | 590 DCHECK(value_exists); |
| 558 return val; | 591 return val; |
| 559 } | 592 } |
| 560 | 593 |
| 594 bool ArcSettingsServiceImpl::IsPrefManaged(const std::string& pref_name) const { | |
| 595 const PrefService::Preference* pref = | |
| 596 registrar_.prefs()->FindPreference(pref_name); | |
| 597 DCHECK(pref); | |
| 598 bool value_exists = pref->GetValue()->is_int(); | |
| 599 DCHECK(value_exists); | |
| 600 return !pref->IsUserModifiable(); | |
| 601 } | |
| 602 | |
| 561 void ArcSettingsServiceImpl::SendBoolPrefSettingsBroadcast( | 603 void ArcSettingsServiceImpl::SendBoolPrefSettingsBroadcast( |
| 562 const std::string& pref_name, | 604 const std::string& pref_name, |
| 563 const std::string& action) const { | 605 const std::string& action) const { |
| 564 const PrefService::Preference* pref = | 606 const PrefService::Preference* pref = |
| 565 registrar_.prefs()->FindPreference(pref_name); | 607 registrar_.prefs()->FindPreference(pref_name); |
| 566 DCHECK(pref); | 608 DCHECK(pref); |
| 567 bool enabled = false; | 609 bool enabled = false; |
| 568 bool value_exists = pref->GetValue()->GetAsBoolean(&enabled); | 610 bool value_exists = pref->GetValue()->GetAsBoolean(&enabled); |
| 569 DCHECK(value_exists); | 611 DCHECK(value_exists); |
| 612 SendBoolValueSettingsBroadcast(enabled, !pref->IsUserModifiable(), action); | |
| 613 } | |
| 614 | |
| 615 void ArcSettingsServiceImpl::SendBoolValueSettingsBroadcast( | |
| 616 bool enabled, | |
| 617 bool managed, | |
| 618 const std::string& action) const { | |
| 570 base::DictionaryValue extras; | 619 base::DictionaryValue extras; |
| 571 extras.SetBoolean("enabled", enabled); | 620 extras.SetBoolean("enabled", enabled); |
| 572 extras.SetBoolean("managed", !pref->IsUserModifiable()); | 621 extras.SetBoolean("managed", managed); |
| 573 SendSettingsBroadcast(action, extras); | 622 SendSettingsBroadcast(action, extras); |
| 574 } | 623 } |
| 575 | 624 |
| 576 void ArcSettingsServiceImpl::SendSettingsBroadcast( | 625 void ArcSettingsServiceImpl::SendSettingsBroadcast( |
| 577 const std::string& action, | 626 const std::string& action, |
| 578 const base::DictionaryValue& extras) const { | 627 const base::DictionaryValue& extras) const { |
| 579 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( | 628 auto* instance = ARC_GET_INSTANCE_FOR_METHOD( |
| 580 arc_bridge_service_->intent_helper(), SendBroadcast); | 629 arc_bridge_service_->intent_helper(), SendBroadcast); |
| 581 if (!instance) | 630 if (!instance) |
| 582 return; | 631 return; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 600 | 649 |
| 601 void ArcSettingsService::OnInstanceReady() { | 650 void ArcSettingsService::OnInstanceReady() { |
| 602 impl_.reset(new ArcSettingsServiceImpl(arc_bridge_service())); | 651 impl_.reset(new ArcSettingsServiceImpl(arc_bridge_service())); |
| 603 } | 652 } |
| 604 | 653 |
| 605 void ArcSettingsService::OnInstanceClosed() { | 654 void ArcSettingsService::OnInstanceClosed() { |
| 606 impl_.reset(); | 655 impl_.reset(); |
| 607 } | 656 } |
| 608 | 657 |
| 609 } // namespace arc | 658 } // namespace arc |
| OLD | NEW |