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