| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/android/new_tab_page_prefs.h" | |
| 6 | |
| 7 #include <jni.h> | |
| 8 | |
| 9 #include "base/android/jni_string.h" | |
| 10 #include "chrome/browser/profiles/profile_android.h" | |
| 11 #include "chrome/common/pref_names.h" | |
| 12 #include "components/pref_registry/pref_registry_syncable.h" | |
| 13 #include "components/prefs/pref_service.h" | |
| 14 #include "components/prefs/scoped_user_pref_update.h" | |
| 15 #include "jni/NewTabPagePrefs_jni.h" | |
| 16 | |
| 17 using base::android::ConvertJavaStringToUTF8; | |
| 18 | |
| 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); | |
| 25 } | |
| 26 | |
| 27 NewTabPagePrefs::NewTabPagePrefs(Profile* profile) | |
| 28 : profile_(profile) { | |
| 29 } | |
| 30 | |
| 31 void NewTabPagePrefs::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | |
| 32 delete this; | |
| 33 } | |
| 34 | |
| 35 NewTabPagePrefs::~NewTabPagePrefs() { | |
| 36 } | |
| 37 | |
| 38 jboolean NewTabPagePrefs::GetCurrentlyOpenTabsCollapsed( | |
| 39 JNIEnv* env, | |
| 40 const JavaParamRef<jobject>& obj) { | |
| 41 PrefService* prefs = profile_->GetPrefs(); | |
| 42 return prefs->GetBoolean(prefs::kNtpCollapsedCurrentlyOpenTabs); | |
| 43 } | |
| 44 | |
| 45 void NewTabPagePrefs::SetCurrentlyOpenTabsCollapsed( | |
| 46 JNIEnv* env, | |
| 47 const JavaParamRef<jobject>& obj, | |
| 48 jboolean is_collapsed) { | |
| 49 PrefService* prefs = profile_->GetPrefs(); | |
| 50 prefs->SetBoolean(prefs::kNtpCollapsedCurrentlyOpenTabs, is_collapsed); | |
| 51 } | |
| 52 | |
| 53 jboolean NewTabPagePrefs::GetSnapshotDocumentCollapsed( | |
| 54 JNIEnv* env, | |
| 55 const JavaParamRef<jobject>& obj) { | |
| 56 return profile_->GetPrefs()->GetBoolean(prefs::kNtpCollapsedSnapshotDocument); | |
| 57 } | |
| 58 | |
| 59 void NewTabPagePrefs::SetSnapshotDocumentCollapsed( | |
| 60 JNIEnv* env, | |
| 61 const JavaParamRef<jobject>& obj, | |
| 62 jboolean is_collapsed) { | |
| 63 PrefService* prefs = profile_->GetPrefs(); | |
| 64 prefs->SetBoolean(prefs::kNtpCollapsedSnapshotDocument, is_collapsed); | |
| 65 } | |
| 66 | |
| 67 jboolean NewTabPagePrefs::GetRecentlyClosedTabsCollapsed( | |
| 68 JNIEnv* env, | |
| 69 const JavaParamRef<jobject>& obj) { | |
| 70 return profile_->GetPrefs()->GetBoolean( | |
| 71 prefs::kNtpCollapsedRecentlyClosedTabs); | |
| 72 } | |
| 73 | |
| 74 void NewTabPagePrefs::SetRecentlyClosedTabsCollapsed( | |
| 75 JNIEnv* env, | |
| 76 const JavaParamRef<jobject>& obj, | |
| 77 jboolean is_collapsed) { | |
| 78 PrefService* prefs = profile_->GetPrefs(); | |
| 79 prefs->SetBoolean(prefs::kNtpCollapsedRecentlyClosedTabs, is_collapsed); | |
| 80 } | |
| 81 | |
| 82 jboolean NewTabPagePrefs::GetSyncPromoCollapsed( | |
| 83 JNIEnv* env, | |
| 84 const JavaParamRef<jobject>& obj) { | |
| 85 return profile_->GetPrefs()->GetBoolean(prefs::kNtpCollapsedSyncPromo); | |
| 86 } | |
| 87 | |
| 88 void NewTabPagePrefs::SetSyncPromoCollapsed(JNIEnv* env, | |
| 89 const JavaParamRef<jobject>& obj, | |
| 90 jboolean is_collapsed) { | |
| 91 PrefService* prefs = profile_->GetPrefs(); | |
| 92 prefs->SetBoolean(prefs::kNtpCollapsedSyncPromo, is_collapsed); | |
| 93 } | |
| 94 | |
| 95 jboolean NewTabPagePrefs::GetForeignSessionCollapsed( | |
| 96 JNIEnv* env, | |
| 97 const JavaParamRef<jobject>& obj, | |
| 98 const JavaParamRef<jstring>& session_tag) { | |
| 99 const base::DictionaryValue* dict = profile_->GetPrefs()->GetDictionary( | |
| 100 prefs::kNtpCollapsedForeignSessions); | |
| 101 return dict && dict->HasKey(ConvertJavaStringToUTF8(env, session_tag)); | |
| 102 } | |
| 103 | |
| 104 void NewTabPagePrefs::SetForeignSessionCollapsed( | |
| 105 JNIEnv* env, | |
| 106 const JavaParamRef<jobject>& obj, | |
| 107 const JavaParamRef<jstring>& session_tag, | |
| 108 jboolean is_collapsed) { | |
| 109 // Store session tags for collapsed sessions in a preference so that the | |
| 110 // collapsed state persists. | |
| 111 PrefService* prefs = profile_->GetPrefs(); | |
| 112 DictionaryPrefUpdate update(prefs, prefs::kNtpCollapsedForeignSessions); | |
| 113 if (is_collapsed) | |
| 114 update.Get()->SetBoolean(ConvertJavaStringToUTF8(env, session_tag), true); | |
| 115 else | |
| 116 update.Get()->Remove(ConvertJavaStringToUTF8(env, session_tag), NULL); | |
| 117 } | |
| 118 | |
| 119 // static | |
| 120 void NewTabPagePrefs::RegisterProfilePrefs( | |
| 121 user_prefs::PrefRegistrySyncable* registry) { | |
| 122 registry->RegisterBooleanPref(prefs::kNtpCollapsedCurrentlyOpenTabs, false); | |
| 123 registry->RegisterBooleanPref(prefs::kNtpCollapsedSnapshotDocument, false); | |
| 124 registry->RegisterBooleanPref(prefs::kNtpCollapsedRecentlyClosedTabs, false); | |
| 125 registry->RegisterBooleanPref(prefs::kNtpCollapsedSyncPromo, false); | |
| 126 registry->RegisterDictionaryPref(prefs::kNtpCollapsedForeignSessions); | |
| 127 } | |
| 128 | |
| 129 // static | |
| 130 bool NewTabPagePrefs::RegisterNewTabPagePrefs(JNIEnv* env) { | |
| 131 return RegisterNativesImpl(env); | |
| 132 } | |
| OLD | NEW |