| 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_bridge_impl.h" | 5 #include "chrome/browser/chromeos/arc/arc_settings_bridge_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/json/json_writer.h" |
| 9 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "components/arc/common/settings.mojom.h" |
| 13 | 15 |
| 14 namespace arc { | 16 namespace arc { |
| 15 | 17 |
| 16 namespace fontsizes { | 18 namespace fontsizes { |
| 17 | 19 |
| 18 double ConvertFontSizeChromeToAndroid(int default_size, | 20 double ConvertFontSizeChromeToAndroid(int default_size, |
| 19 int default_fixed_size, | 21 int default_fixed_size, |
| 20 int minimum_size) { | 22 int minimum_size) { |
| 21 // kWebKitDefaultFixedFontSize is automatically set to be 3 pixels smaller | 23 // kWebKitDefaultFixedFontSize is automatically set to be 3 pixels smaller |
| 22 // than kWebKitDefaultFontSize when Chrome's settings page's main font | 24 // than kWebKitDefaultFontSize when Chrome's settings page's main font |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 pref_name == prefs::kWebKitDefaultFontSize || | 85 pref_name == prefs::kWebKitDefaultFontSize || |
| 84 pref_name == prefs::kWebKitMinimumFontSize) { | 86 pref_name == prefs::kWebKitMinimumFontSize) { |
| 85 SyncFontSize(); | 87 SyncFontSize(); |
| 86 } else { | 88 } else { |
| 87 LOG(ERROR) << "Unknown pref changed."; | 89 LOG(ERROR) << "Unknown pref changed."; |
| 88 } | 90 } |
| 89 } | 91 } |
| 90 | 92 |
| 91 void ArcSettingsBridgeImpl::OnStateChanged(ArcBridgeService::State state) { | 93 void ArcSettingsBridgeImpl::OnStateChanged(ArcBridgeService::State state) { |
| 92 // ArcBridgeService::State::READY is emitted before ArcSettings app is ready | 94 // ArcBridgeService::State::READY is emitted before ArcSettings app is ready |
| 93 // to send broadcasts. Instead we wait for a later boot phase in | 95 // to send broadcasts. Instead we wait for the SettingsInstance to be ready. |
| 94 // OnInstanceBootPhase. | |
| 95 if (state == ArcBridgeService::State::STOPPING) { | 96 if (state == ArcBridgeService::State::STOPPING) { |
| 96 StopObservingPrefChanges(); | 97 StopObservingPrefChanges(); |
| 97 } | 98 } |
| 98 } | 99 } |
| 99 | 100 |
| 100 void ArcSettingsBridgeImpl::OnInstanceBootPhase(InstanceBootPhase phase) { | 101 void ArcSettingsBridgeImpl::OnSettingsInstanceReady() { |
| 101 if (phase == INSTANCE_BOOT_PHASE_ACTIVITY_MANAGER_READY) { | 102 StartObservingPrefChanges(); |
| 102 StartObservingPrefChanges(); | 103 SyncAllPrefs(); |
| 103 SyncAllPrefs(); | |
| 104 } | |
| 105 } | 104 } |
| 106 | 105 |
| 107 void ArcSettingsBridgeImpl::SyncSpokenFeedbackEnabled() const { | 106 void ArcSettingsBridgeImpl::SyncSpokenFeedbackEnabled() const { |
| 108 const PrefService::Preference* pref = registrar_.prefs()->FindPreference( | 107 const PrefService::Preference* pref = registrar_.prefs()->FindPreference( |
| 109 prefs::kAccessibilitySpokenFeedbackEnabled); | 108 prefs::kAccessibilitySpokenFeedbackEnabled); |
| 110 DCHECK(pref); | 109 DCHECK(pref); |
| 111 bool enabled = false; | 110 bool enabled = false; |
| 112 bool value_exists = pref->GetValue()->GetAsBoolean(&enabled); | 111 bool value_exists = pref->GetValue()->GetAsBoolean(&enabled); |
| 113 DCHECK(value_exists); | 112 DCHECK(value_exists); |
| 114 base::DictionaryValue extras; | 113 base::DictionaryValue extras; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 143 void ArcSettingsBridgeImpl::SendSettingsBroadcast( | 142 void ArcSettingsBridgeImpl::SendSettingsBroadcast( |
| 144 const std::string& action, | 143 const std::string& action, |
| 145 const base::DictionaryValue& extras) const { | 144 const base::DictionaryValue& extras) const { |
| 146 ArcBridgeService* bridge_service = ArcBridgeService::Get(); | 145 ArcBridgeService* bridge_service = ArcBridgeService::Get(); |
| 147 if (!bridge_service || | 146 if (!bridge_service || |
| 148 bridge_service->state() != ArcBridgeService::State::READY) { | 147 bridge_service->state() != ArcBridgeService::State::READY) { |
| 149 LOG(ERROR) << "Bridge service is not ready."; | 148 LOG(ERROR) << "Bridge service is not ready."; |
| 150 return; | 149 return; |
| 151 } | 150 } |
| 152 | 151 |
| 153 bridge_service->SendBroadcast(action, "org.chromium.arc.settings", | 152 std::string extras_json; |
| 154 "org.chromium.arc.settings.SettingsReceiver", | 153 bool write_success = base::JSONWriter::Write(extras, &extras_json); |
| 155 extras); | 154 DCHECK(write_success); |
| 155 bridge_service->settings_instance()->SendBroadcast( |
| 156 action, "org.chromium.arc.settings", |
| 157 "org.chromium.arc.settings.SettingsReceiver", extras_json); |
| 156 } | 158 } |
| 157 | 159 |
| 158 } // namespace arc | 160 } // namespace arc |
| OLD | NEW |