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_IMPL_H_ | 4 #ifndef CHROME_BROWSER_CHROMEOS_ARC_SETTINGS_BRIDGE_H_ |
5 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_SETTINGS_BRIDGE_IMPL_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/settings/arc_settings_bridge.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 ArcSettingsBridgeImpl | 42 class SettingsBridge : public chromeos::system::TimezoneSettings::Observer { |
44 : public ArcSettingsBridge, | |
45 public ArcBridgeService::Observer, | |
46 public chromeos::system::TimezoneSettings::Observer { | |
47 public: | 43 public: |
48 ArcSettingsBridgeImpl() = default; | 44 class Delegate { |
45 public: | |
46 virtual void OnBroadcastNeeded(const std::string& action, | |
47 const base::DictionaryValue& extras) = 0; | |
48 }; | |
49 | 49 |
50 ~ArcSettingsBridgeImpl() override; | 50 explicit SettingsBridge(Delegate* delegate); |
51 | 51 ~SettingsBridge() override; |
52 // Starts listening to state changes of the ArcBridgeService. | |
53 // This must be called before the bridge service starts bootstrapping. | |
54 void StartObservingBridgeServiceChanges() override; | |
55 | 52 |
56 // 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. |
57 // Obtains the new pref value and sends it to Android. | 54 // Obtains the new pref value and sends it to Android. |
58 void OnPrefChanged(const std::string& pref_name) const; | 55 void OnPrefChanged(const std::string& pref_name) const; |
59 | 56 |
60 // ArcBridgeService::Observer | |
61 void OnStateChanged(ArcBridgeService::State state) override; | |
62 void OnSettingsInstanceReady() override; | |
63 | |
64 // TimezoneSettings::Observer | 57 // TimezoneSettings::Observer |
65 void TimezoneChanged(const icu::TimeZone& timezone) override; | 58 void TimezoneChanged(const icu::TimeZone& timezone) override; |
66 | 59 |
67 private: | 60 private: |
68 // Registers to observe changes for Chrome settings we care about. | 61 // Registers to observe changes for Chrome settings we care about. |
69 void StartObservingSettingsChanges(); | 62 void StartObservingSettingsChanges(); |
70 | 63 |
71 // Stops listening for Chrome settings changes. | 64 // Stops listening for Chrome settings changes. |
72 void StopObservingSettingsChanges(); | 65 void StopObservingSettingsChanges(); |
73 | 66 |
74 // 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. |
75 void SyncAllPrefs() const; | 68 void SyncAllPrefs() const; |
76 void SyncFontSize() const; | 69 void SyncFontSize() const; |
77 void SyncLocale() const; | 70 void SyncLocale() const; |
78 void SyncSpokenFeedbackEnabled() const; | 71 void SyncSpokenFeedbackEnabled() const; |
79 void SyncTimeZone() const; | 72 void SyncTimeZone() const; |
80 | 73 |
81 // Registers to listen to a particular perf. | 74 // Registers to listen to a particular perf. |
82 void AddPrefToObserve(const std::string& pref_name); | 75 void AddPrefToObserve(const std::string& pref_name); |
83 | 76 |
84 // Returns the integer value of the pref. pref_name must exist. | 77 // Returns the integer value of the pref. pref_name must exist. |
85 int GetIntegerPref(const std::string& pref_name) const; | 78 int GetIntegerPref(const std::string& pref_name) const; |
86 | 79 |
87 // Sends a broadcast to the ArcSettings app in Android. | 80 // Sends a broadcast to the delegate. |
88 void SendSettingsBroadcast(const std::string& action, | 81 void SendSettingsBroadcast(const std::string& action, |
89 const base::DictionaryValue& extras) const; | 82 const base::DictionaryValue& extras) const; |
90 | 83 |
91 // Manages pref observation registration. | 84 // Manages pref observation registration. |
92 PrefChangeRegistrar registrar_; | 85 PrefChangeRegistrar registrar_; |
93 | 86 |
94 DISALLOW_COPY_AND_ASSIGN(ArcSettingsBridgeImpl); | 87 Delegate* delegate_; |
Luis Héctor Chávez
2016/01/21 23:32:06
nit: Can you make this Delegate* const delegate_;?
Yusuke Sato
2016/01/22 00:57:57
Done.
| |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(SettingsBridge); | |
95 }; | 90 }; |
96 | 91 |
97 } // namespace arc | 92 } // namespace arc |
98 | 93 |
99 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SETTINGS_BRIDGE_IMPL_H_ | 94 #endif // CHROME_BROWSER_CHROMEOS_ARC_SETTINGS_BRIDGE_H_ |
OLD | NEW |