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