OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_SETTINGS_BRIDGE_H_ | 4 #ifndef CHROME_BROWSER_CHROMEOS_ARC_SETTINGS_BRIDGE_H_ |
5 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_SETTINGS_BRIDGE_H_ | 5 #define CHROME_BROWSER_CHROMEOS_ARC_SETTINGS_BRIDGE_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/macros.h" | 10 #include "base/macros.h" |
11 #include "base/prefs/pref_change_registrar.h" | 11 #include "base/prefs/pref_change_registrar.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chromeos/settings/timezone_settings.h" | 13 #include "chromeos/settings/timezone_settings.h" |
14 #include "components/arc/arc_bridge_service.h" | 14 #include "components/arc/arc_bridge_service.h" |
15 #include "components/arc/arc_service.h" | |
16 | 15 |
17 namespace arc { | 16 namespace arc { |
18 | 17 |
19 namespace fontsizes { | 18 namespace fontsizes { |
20 | 19 |
21 // The following values were obtained from chrome://settings and Android's | 20 // The following values were obtained from chrome://settings and Android's |
22 // Display settings on Nov 2015. They are expected to remain stable. | 21 // Display settings on Nov 2015. They are expected to remain stable. |
23 const float kAndroidFontScaleSmall = 0.85; | 22 const float kAndroidFontScaleSmall = 0.85; |
24 const float kAndroidFontScaleNormal = 1; | 23 const float kAndroidFontScaleNormal = 1; |
25 const float kAndroidFontScaleLarge = 1.15; | 24 const float kAndroidFontScaleLarge = 1.15; |
26 const float kAndroidFontScaleHuge = 1.3; | 25 const float kAndroidFontScaleHuge = 1.3; |
27 const int kChromeFontSizeNormal = 16; | 26 const int kChromeFontSizeNormal = 16; |
28 const int kChromeFontSizeLarge = 20; | 27 const int kChromeFontSizeLarge = 20; |
29 const int kChromeFontSizeVeryLarge = 24; | 28 const int kChromeFontSizeVeryLarge = 24; |
30 | 29 |
31 // Android has only a single float value for system-wide font size | 30 // Android has only a single float value for system-wide font size |
32 // (font_scale). Chrome has three main int pixel values that affect | 31 // (font_scale). Chrome has three main int pixel values that affect |
33 // system-wide font size. We will take the largest font value of the three | 32 // system-wide font size. We will take the largest font value of the three |
34 // main font values on Chrome and convert to an Android size. | 33 // main font values on Chrome and convert to an Android size. |
35 double ConvertFontSizeChromeToAndroid(int default_size, | 34 double ConvertFontSizeChromeToAndroid(int default_size, |
36 int default_fixed_size, | 35 int default_fixed_size, |
37 int minimum_size); | 36 int minimum_size); |
38 | 37 |
39 } // namespace fontsizes | 38 } // namespace fontsizes |
40 | 39 |
41 // Listens to changes for select Chrome settings (prefs) that Android cares | 40 // Listens to changes for select Chrome settings (prefs) that Android cares |
42 // about and sends the new values to Android to keep the state in sync. | 41 // about and sends the new values to Android to keep the state in sync. |
43 class ArcSettingsBridge : public ArcService, | 42 class SettingsBridge : public chromeos::system::TimezoneSettings::Observer { |
44 public ArcBridgeService::Observer, | |
45 public chromeos::system::TimezoneSettings::Observer { | |
46 public: | 43 public: |
47 explicit ArcSettingsBridge(ArcBridgeService* bridge_service); | 44 class Delegate { |
48 ~ArcSettingsBridge() override; | 45 public: |
| 46 virtual void OnBroadcastNeeded(const std::string& action, |
| 47 const base::DictionaryValue& extras) = 0; |
| 48 }; |
| 49 |
| 50 explicit SettingsBridge(Delegate* delegate); |
| 51 ~SettingsBridge() override; |
49 | 52 |
50 // Called when a Chrome pref we have registered an observer for has changed. | 53 // Called when a Chrome pref we have registered an observer for has changed. |
51 // Obtains the new pref value and sends it to Android. | 54 // Obtains the new pref value and sends it to Android. |
52 void OnPrefChanged(const std::string& pref_name) const; | 55 void OnPrefChanged(const std::string& pref_name) const; |
53 | 56 |
54 // ArcBridgeService::Observer | |
55 void OnStateChanged(ArcBridgeService::State state) override; | |
56 void OnSettingsInstanceReady() override; | |
57 | |
58 // TimezoneSettings::Observer | 57 // TimezoneSettings::Observer |
59 void TimezoneChanged(const icu::TimeZone& timezone) override; | 58 void TimezoneChanged(const icu::TimeZone& timezone) override; |
60 | 59 |
61 private: | 60 private: |
62 // Registers to observe changes for Chrome settings we care about. | 61 // Registers to observe changes for Chrome settings we care about. |
63 void StartObservingSettingsChanges(); | 62 void StartObservingSettingsChanges(); |
64 | 63 |
65 // Stops listening for Chrome settings changes. | 64 // Stops listening for Chrome settings changes. |
66 void StopObservingSettingsChanges(); | 65 void StopObservingSettingsChanges(); |
67 | 66 |
68 // Retrives Chrome's state for the settings and send it to Android. | 67 // Retrives Chrome's state for the settings and send it to Android. |
69 void SyncAllPrefs() const; | 68 void SyncAllPrefs() const; |
70 void SyncFontSize() const; | 69 void SyncFontSize() const; |
71 void SyncLocale() const; | 70 void SyncLocale() const; |
72 void SyncSpokenFeedbackEnabled() const; | 71 void SyncSpokenFeedbackEnabled() const; |
73 void SyncTimeZone() const; | 72 void SyncTimeZone() const; |
74 | 73 |
75 // Registers to listen to a particular perf. | 74 // Registers to listen to a particular perf. |
76 void AddPrefToObserve(const std::string& pref_name); | 75 void AddPrefToObserve(const std::string& pref_name); |
77 | 76 |
78 // Returns the integer value of the pref. pref_name must exist. | 77 // Returns the integer value of the pref. pref_name must exist. |
79 int GetIntegerPref(const std::string& pref_name) const; | 78 int GetIntegerPref(const std::string& pref_name) const; |
80 | 79 |
81 // Sends a broadcast to the ArcSettings app in Android. | 80 // Sends a broadcast to the delegate. |
82 void SendSettingsBroadcast(const std::string& action, | 81 void SendSettingsBroadcast(const std::string& action, |
83 const base::DictionaryValue& extras) const; | 82 const base::DictionaryValue& extras) const; |
84 | 83 |
85 // Manages pref observation registration. | 84 // Manages pref observation registration. |
86 PrefChangeRegistrar registrar_; | 85 PrefChangeRegistrar registrar_; |
87 | 86 |
88 DISALLOW_COPY_AND_ASSIGN(ArcSettingsBridge); | 87 Delegate* const delegate_; |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(SettingsBridge); |
89 }; | 90 }; |
90 | 91 |
91 } // namespace arc | 92 } // namespace arc |
92 | 93 |
93 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SETTINGS_BRIDGE_H_ | 94 #endif // CHROME_BROWSER_CHROMEOS_ARC_SETTINGS_BRIDGE_H_ |
OLD | NEW |