Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Unified Diff: chrome/browser/android/new_tab_page_prefs.cc

Issue 33863002: Added pref for snapshot document collapsed state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/new_tab_page_prefs.cc
diff --git a/chrome/browser/android/new_tab_page_prefs.cc b/chrome/browser/android/new_tab_page_prefs.cc
new file mode 100644
index 0000000000000000000000000000000000000000..169de3199c01a3a02878d37042de54140b509d25
--- /dev/null
+++ b/chrome/browser/android/new_tab_page_prefs.cc
@@ -0,0 +1,115 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/new_tab_page_prefs.h"
+
+#include <jni.h>
+
+#include "base/android/jni_string.h"
+#include "base/prefs/pref_service.h"
+#include "base/prefs/scoped_user_pref_update.h"
+#include "chrome/browser/profiles/profile_android.h"
+#include "chrome/common/pref_names.h"
+#include "components/user_prefs/pref_registry_syncable.h"
+#include "jni/NewTabPagePrefs_jni.h"
+
+using base::android::ConvertJavaStringToUTF8;
+
+static jint Init(JNIEnv* env, jclass clazz, jobject profile) {
+ NewTabPagePrefs * new_tab_page_prefs =
newt (away) 2013/10/30 23:47:51 no space before *
apiccion 2013/11/01 23:30:32 Done.
+ new NewTabPagePrefs(ProfileAndroid::FromProfileAndroid(profile));
newt (away) 2013/10/30 23:47:51 indent by 4 on wrapped lines
apiccion 2013/11/01 23:30:32 Done.
+ return reinterpret_cast<jint>(new_tab_page_prefs);
+}
+
+NewTabPagePrefs::NewTabPagePrefs(Profile* profile)
+ : profile_(profile){
newt (away) 2013/10/30 23:47:51 space before {
apiccion 2013/11/01 23:30:32 Done.
+}
+
+void NewTabPagePrefs::Destroy(JNIEnv* env, jobject obj) {
+ delete this;
+}
+
+NewTabPagePrefs::~NewTabPagePrefs() {
+}
+
+jboolean NewTabPagePrefs::GetSnapshotDocumentCollapsed(JNIEnv* env,
+ jobject obj) {
+ return profile_->GetPrefs()->GetBoolean(prefs::kNtpCollapsedSnapshotDocument);
+}
+
+void NewTabPagePrefs::SetSnapshotDocumentCollapsed(JNIEnv* env,
+ jobject obj,
+ jboolean is_collapsed) {
+ PrefService* prefs = profile_->GetPrefs();
+ prefs->SetBoolean(prefs::kNtpCollapsedSnapshotDocument, is_collapsed);
+}
+
+jboolean NewTabPagePrefs::GetRecentlyClosedTabsCollapsed(JNIEnv* env,
+ jobject obj) {
+ return profile_->GetPrefs()->GetBoolean(
+ prefs::kNtpCollapsedRecentlyClosedTabs);
+}
+
+void NewTabPagePrefs::SetRecentlyClosedTabsCollapsed(JNIEnv* env,
+ jobject obj,
+ jboolean is_collapsed) {
+ PrefService* prefs = profile_->GetPrefs();
+ prefs->SetBoolean(prefs::kNtpCollapsedRecentlyClosedTabs, is_collapsed);
+}
+
+jboolean NewTabPagePrefs::GetSyncPromoCollapsed(JNIEnv* env,
+ jobject obj) {
+ return profile_->GetPrefs()->GetBoolean(prefs::kNtpCollapsedSyncPromo);
+}
+
+void NewTabPagePrefs::SetSyncPromoCollapsed(JNIEnv* env,
+ jobject obj,
+ jboolean is_collapsed) {
+ PrefService* prefs = profile_->GetPrefs();
+ prefs->SetBoolean(prefs::kNtpCollapsedSyncPromo, is_collapsed);
+}
+
+jboolean NewTabPagePrefs::GetForeignSessionCollapsed(JNIEnv* env,
+ jobject obj,
+ jstring session_tag) {
+ const DictionaryValue* dict = profile_->GetPrefs()->GetDictionary(
+ prefs::kNtpCollapsedForeignSessions);
+ return dict && dict->HasKey(ConvertJavaStringToUTF8(env, session_tag));
+}
+
+void NewTabPagePrefs::SetForeignSessionCollapsed(JNIEnv* env,
+ jobject obj,
+ jstring session_tag,
+ jboolean is_collapsed) {
+ // Store session tags for collapsed sessions in a preference so that the
+ // collapsed state persists.
+ PrefService* prefs = profile_->GetPrefs();
+ DictionaryPrefUpdate update(prefs, prefs::kNtpCollapsedForeignSessions);
+ if (is_collapsed)
+ update.Get()->SetBoolean(ConvertJavaStringToUTF8(env, session_tag), true);
+ else
+ update.Get()->Remove(ConvertJavaStringToUTF8(env, session_tag), NULL);
+}
+
+// static
+void NewTabPagePrefs::RegisterProfilePrefs(
+ user_prefs::PrefRegistrySyncable* registry) {
+ registry->RegisterBooleanPref(
newt (away) 2013/10/30 23:47:51 unindent
apiccion 2013/11/01 23:30:32 Done.
+ prefs::kNtpCollapsedSnapshotDocument,
+ false,
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
Yaron 2013/10/31 20:57:34 Thinking out loud:I wonder whether we'll want thes
apiccion 2013/11/01 23:30:32 These particular preferences are device specific (
+ registry->RegisterBooleanPref(
+ prefs::kNtpCollapsedRecentlyClosedTabs,
+ false,
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+ registry->RegisterBooleanPref(
+ prefs::kNtpCollapsedSyncPromo,
+ false,
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+}
+
+// static
+bool NewTabPagePrefs::RegisterNewTabPagePrefs(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}

Powered by Google App Engine
This is Rietveld 408576698