Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / android / accessibility / font_size_prefs_android.cc
blob56e94edf8b7be16dd18a4726b0d1f5c84b0f107b
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/android/accessibility/font_size_prefs_android.h"
7 #include "base/observer_list.h"
8 #include "base/prefs/pref_change_registrar.h"
9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/profiles/profile_android.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "chrome/common/pref_names.h"
13 #include "jni/FontSizePrefs_jni.h"
15 FontSizePrefsAndroid::FontSizePrefsAndroid(JNIEnv* env, jobject obj)
16 : pref_service_(ProfileManager::GetActiveUserProfile()->GetPrefs()) {
17 java_ref_.Reset(env, obj);
18 pref_change_registrar_.reset(new PrefChangeRegistrar);
19 pref_change_registrar_->Init(pref_service_);
20 pref_change_registrar_->Add(
21 prefs::kWebKitFontScaleFactor,
22 base::Bind(&FontSizePrefsAndroid::OnFontScaleFactorPrefsChanged,
23 base::Unretained(this)));
24 pref_change_registrar_->Add(
25 prefs::kWebKitForceEnableZoom,
26 base::Bind(&FontSizePrefsAndroid::OnForceEnableZoomPrefsChanged,
27 base::Unretained(this)));
30 FontSizePrefsAndroid::~FontSizePrefsAndroid() {
33 void FontSizePrefsAndroid::SetFontScaleFactor(JNIEnv* env,
34 jobject obj,
35 jfloat font_size) {
36 pref_service_->SetDouble(prefs::kWebKitFontScaleFactor,
37 static_cast<double>(font_size));
40 float FontSizePrefsAndroid::GetFontScaleFactor(JNIEnv* env, jobject obj) {
41 return pref_service_->GetDouble(prefs::kWebKitFontScaleFactor);
44 void FontSizePrefsAndroid::SetForceEnableZoom(JNIEnv* env,
45 jobject obj,
46 jboolean enabled) {
47 pref_service_->SetBoolean(prefs::kWebKitForceEnableZoom, enabled);
50 bool FontSizePrefsAndroid::GetForceEnableZoom(JNIEnv* env, jobject obj) {
51 return pref_service_->GetBoolean(prefs::kWebKitForceEnableZoom);
54 void FontSizePrefsAndroid::AddObserver(JNIEnv* env,
55 jobject obj,
56 jlong observer_ptr) {
57 FontSizePrefsObserverAndroid* font_size_prefs_observer_android =
58 reinterpret_cast<FontSizePrefsObserverAndroid*>(observer_ptr);
59 observers_.AddObserver(font_size_prefs_observer_android);
62 void FontSizePrefsAndroid::RemoveObserver(JNIEnv* env,
63 jobject obj,
64 jlong observer_ptr) {
65 FontSizePrefsObserverAndroid* font_size_prefs_observer_android =
66 reinterpret_cast<FontSizePrefsObserverAndroid*>(observer_ptr);
67 observers_.RemoveObserver(font_size_prefs_observer_android);
70 bool FontSizePrefsAndroid::Register(JNIEnv* env) {
71 return RegisterNativesImpl(env);
74 jlong Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
75 FontSizePrefsAndroid* font_size_prefs_android =
76 new FontSizePrefsAndroid(env, obj);
77 return reinterpret_cast<intptr_t>(font_size_prefs_android);
80 void FontSizePrefsAndroid::OnFontScaleFactorPrefsChanged() {
81 JNIEnv* env = base::android::AttachCurrentThread();
82 FOR_EACH_OBSERVER(Observer,
83 observers_,
84 OnChangeFontSize(GetFontScaleFactor(env, java_ref_.obj())));
87 void FontSizePrefsAndroid::OnForceEnableZoomPrefsChanged() {
88 JNIEnv* env = base::android::AttachCurrentThread();
89 FOR_EACH_OBSERVER(
90 Observer,
91 observers_,
92 OnChangeForceEnableZoom(GetForceEnableZoom(env, java_ref_.obj())));
95 FontSizePrefsObserverAndroid::FontSizePrefsObserverAndroid(JNIEnv* env,
96 jobject obj) {
97 java_ref_.Reset(env, obj);
100 FontSizePrefsObserverAndroid::~FontSizePrefsObserverAndroid() {
103 bool FontSizePrefsObserverAndroid::Register(JNIEnv* env) {
104 return RegisterNativesImpl(env);
107 void FontSizePrefsObserverAndroid::DestroyObserverAndroid(JNIEnv* env,
108 jobject obj) {
109 delete this;
112 jlong InitObserverAndroid(JNIEnv* env, const JavaParamRef<jobject>& obj) {
113 FontSizePrefsObserverAndroid* observer_wrapper =
114 new FontSizePrefsObserverAndroid(env, obj);
115 return reinterpret_cast<intptr_t>(observer_wrapper);
118 void FontSizePrefsObserverAndroid::OnChangeFontSize(float font_size) {
119 JNIEnv* env = base::android::AttachCurrentThread();
120 Java_FontSizePrefsObserverWrapper_onChangeFontSize(
121 env, java_ref_.obj(), font_size);
124 void FontSizePrefsObserverAndroid::OnChangeForceEnableZoom(bool enabled) {
125 JNIEnv* env = base::android::AttachCurrentThread();
126 Java_FontSizePrefsObserverWrapper_onChangeForceEnableZoom(
127 env, java_ref_.obj(), enabled);