Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / android / new_tab_page_prefs.cc
blobd22d6fb46f294b4564ba9d9e9c16da0ebc5c30ad
1 // Copyright 2013 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/new_tab_page_prefs.h"
7 #include <jni.h>
9 #include "base/android/jni_string.h"
10 #include "base/prefs/pref_service.h"
11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "chrome/browser/profiles/profile_android.h"
13 #include "chrome/common/pref_names.h"
14 #include "components/pref_registry/pref_registry_syncable.h"
15 #include "jni/NewTabPagePrefs_jni.h"
17 using base::android::ConvertJavaStringToUTF8;
19 static jlong Init(JNIEnv* env,
20 const JavaParamRef<jclass>& clazz,
21 const JavaParamRef<jobject>& profile) {
22 NewTabPagePrefs* new_tab_page_prefs =
23 new NewTabPagePrefs(ProfileAndroid::FromProfileAndroid(profile));
24 return reinterpret_cast<intptr_t>(new_tab_page_prefs);
27 NewTabPagePrefs::NewTabPagePrefs(Profile* profile)
28 : profile_(profile) {
31 void NewTabPagePrefs::Destroy(JNIEnv* env, jobject obj) {
32 delete this;
35 NewTabPagePrefs::~NewTabPagePrefs() {
38 jboolean NewTabPagePrefs::GetCurrentlyOpenTabsCollapsed(JNIEnv* env,
39 jobject obj) {
40 PrefService* prefs = profile_->GetPrefs();
41 return prefs->GetBoolean(prefs::kNtpCollapsedCurrentlyOpenTabs);
44 void NewTabPagePrefs::SetCurrentlyOpenTabsCollapsed(JNIEnv* env,
45 jobject obj,
46 jboolean is_collapsed) {
47 PrefService* prefs = profile_->GetPrefs();
48 prefs->SetBoolean(prefs::kNtpCollapsedCurrentlyOpenTabs, is_collapsed);
51 jboolean NewTabPagePrefs::GetSnapshotDocumentCollapsed(JNIEnv* env,
52 jobject obj) {
53 return profile_->GetPrefs()->GetBoolean(prefs::kNtpCollapsedSnapshotDocument);
56 void NewTabPagePrefs::SetSnapshotDocumentCollapsed(JNIEnv* env,
57 jobject obj,
58 jboolean is_collapsed) {
59 PrefService* prefs = profile_->GetPrefs();
60 prefs->SetBoolean(prefs::kNtpCollapsedSnapshotDocument, is_collapsed);
63 jboolean NewTabPagePrefs::GetRecentlyClosedTabsCollapsed(JNIEnv* env,
64 jobject obj) {
65 return profile_->GetPrefs()->GetBoolean(
66 prefs::kNtpCollapsedRecentlyClosedTabs);
69 void NewTabPagePrefs::SetRecentlyClosedTabsCollapsed(JNIEnv* env,
70 jobject obj,
71 jboolean is_collapsed) {
72 PrefService* prefs = profile_->GetPrefs();
73 prefs->SetBoolean(prefs::kNtpCollapsedRecentlyClosedTabs, is_collapsed);
76 jboolean NewTabPagePrefs::GetSyncPromoCollapsed(JNIEnv* env,
77 jobject obj) {
78 return profile_->GetPrefs()->GetBoolean(prefs::kNtpCollapsedSyncPromo);
81 void NewTabPagePrefs::SetSyncPromoCollapsed(JNIEnv* env,
82 jobject obj,
83 jboolean is_collapsed) {
84 PrefService* prefs = profile_->GetPrefs();
85 prefs->SetBoolean(prefs::kNtpCollapsedSyncPromo, is_collapsed);
88 jboolean NewTabPagePrefs::GetForeignSessionCollapsed(JNIEnv* env,
89 jobject obj,
90 jstring session_tag) {
91 const base::DictionaryValue* dict = profile_->GetPrefs()->GetDictionary(
92 prefs::kNtpCollapsedForeignSessions);
93 return dict && dict->HasKey(ConvertJavaStringToUTF8(env, session_tag));
96 void NewTabPagePrefs::SetForeignSessionCollapsed(JNIEnv* env,
97 jobject obj,
98 jstring session_tag,
99 jboolean is_collapsed) {
100 // Store session tags for collapsed sessions in a preference so that the
101 // collapsed state persists.
102 PrefService* prefs = profile_->GetPrefs();
103 DictionaryPrefUpdate update(prefs, prefs::kNtpCollapsedForeignSessions);
104 if (is_collapsed)
105 update.Get()->SetBoolean(ConvertJavaStringToUTF8(env, session_tag), true);
106 else
107 update.Get()->Remove(ConvertJavaStringToUTF8(env, session_tag), NULL);
110 // static
111 void NewTabPagePrefs::RegisterProfilePrefs(
112 user_prefs::PrefRegistrySyncable* registry) {
113 registry->RegisterBooleanPref(prefs::kNtpCollapsedCurrentlyOpenTabs, false);
114 registry->RegisterBooleanPref(prefs::kNtpCollapsedSnapshotDocument, false);
115 registry->RegisterBooleanPref(prefs::kNtpCollapsedRecentlyClosedTabs, false);
116 registry->RegisterBooleanPref(prefs::kNtpCollapsedSyncPromo, false);
117 registry->RegisterDictionaryPref(prefs::kNtpCollapsedForeignSessions);
120 // static
121 bool NewTabPagePrefs::RegisterNewTabPagePrefs(JNIEnv* env) {
122 return RegisterNativesImpl(env);