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

Side by Side Diff: chrome/browser/android/recently_closed_tabs_bridge.cc

Issue 2610143002: Add RecentTabsPageTest (Closed)
Patch Set: Undo the prefs changes. Created 3 years, 11 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 unified diff | Download patch
OLDNEW
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/recently_closed_tabs_bridge.h" 5 #include "chrome/browser/android/recently_closed_tabs_bridge.h"
6 6
7 #include "base/android/jni_string.h" 7 #include "base/android/jni_string.h"
8 #include "chrome/browser/android/tab_android.h" 8 #include "chrome/browser/android/tab_android.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/profiles/profile_android.h" 10 #include "chrome/browser/profiles/profile_android.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 auto& tab = static_cast<const sessions::TabRestoreService::Tab&>(*entry); 46 auto& tab = static_cast<const sessions::TabRestoreService::Tab&>(*entry);
47 AddTabToList(env, tab, jtabs_list); 47 AddTabToList(env, tab, jtabs_list);
48 if (++added_count == max_tab_count) 48 if (++added_count == max_tab_count)
49 break; 49 break;
50 } 50 }
51 } 51 }
52 } 52 }
53 53
54 } // namespace 54 } // namespace
55 55
56 RecentlyClosedTabsBridge::RecentlyClosedTabsBridge(Profile* profile) 56 RecentlyClosedTabsBridge::RecentlyClosedTabsBridge(
57 : profile_(profile), 57 const JavaParamRef<jobject>& bridge,
58 tab_restore_service_(NULL) { 58 Profile* profile)
59 } 59 : bridge_(AttachCurrentThread(), bridge),
Bernhard Bauer 2017/01/04 11:54:16 Nit: I think what I would do is create the ScopedJ
Michael van Ouwerkerk 2017/01/05 11:02:14 Done.
60 profile_(profile),
61 tab_restore_service_(NULL) {}
60 62
61 RecentlyClosedTabsBridge::~RecentlyClosedTabsBridge() { 63 RecentlyClosedTabsBridge::~RecentlyClosedTabsBridge() {
62 if (tab_restore_service_) 64 if (tab_restore_service_)
63 tab_restore_service_->RemoveObserver(this); 65 tab_restore_service_->RemoveObserver(this);
64 } 66 }
65 67
66 void RecentlyClosedTabsBridge::Destroy(JNIEnv* env, 68 void RecentlyClosedTabsBridge::Destroy(JNIEnv* env,
67 const JavaParamRef<jobject>& obj) { 69 const JavaParamRef<jobject>& obj) {
68 delete this; 70 delete this;
69 } 71 }
70 72
71 void RecentlyClosedTabsBridge::SetRecentlyClosedCallback(
72 JNIEnv* env,
73 const JavaParamRef<jobject>& obj,
74 const JavaParamRef<jobject>& jcallback) {
75 callback_.Reset(env, jcallback);
76 }
77
78 jboolean RecentlyClosedTabsBridge::GetRecentlyClosedTabs( 73 jboolean RecentlyClosedTabsBridge::GetRecentlyClosedTabs(
79 JNIEnv* env, 74 JNIEnv* env,
80 const JavaParamRef<jobject>& obj, 75 const JavaParamRef<jobject>& obj,
81 const JavaParamRef<jobject>& jtabs_list, 76 const JavaParamRef<jobject>& jtabs_list,
82 jint max_tab_count) { 77 jint max_tab_count) {
83 EnsureTabRestoreService(); 78 EnsureTabRestoreService();
84 if (!tab_restore_service_) 79 if (!tab_restore_service_)
85 return false; 80 return false;
86 81
87 AddTabsToList(env, tab_restore_service_->entries(), jtabs_list, 82 AddTabsToList(env, tab_restore_service_->entries(), jtabs_list,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 void RecentlyClosedTabsBridge::ClearRecentlyClosedTabs( 140 void RecentlyClosedTabsBridge::ClearRecentlyClosedTabs(
146 JNIEnv* env, 141 JNIEnv* env,
147 const JavaParamRef<jobject>& obj) { 142 const JavaParamRef<jobject>& obj) {
148 EnsureTabRestoreService(); 143 EnsureTabRestoreService();
149 if (tab_restore_service_) 144 if (tab_restore_service_)
150 tab_restore_service_->ClearEntries(); 145 tab_restore_service_->ClearEntries();
151 } 146 }
152 147
153 void RecentlyClosedTabsBridge::TabRestoreServiceChanged( 148 void RecentlyClosedTabsBridge::TabRestoreServiceChanged(
154 sessions::TabRestoreService* service) { 149 sessions::TabRestoreService* service) {
155 if (callback_.is_null()) 150 Java_RecentlyClosedBridge_onUpdated(AttachCurrentThread(), bridge_);
156 return;
157 JNIEnv* env = AttachCurrentThread();
158 Java_RecentlyClosedCallback_onUpdated(env, callback_);
159 } 151 }
160 152
161 void RecentlyClosedTabsBridge::TabRestoreServiceDestroyed( 153 void RecentlyClosedTabsBridge::TabRestoreServiceDestroyed(
162 sessions::TabRestoreService* service) { 154 sessions::TabRestoreService* service) {
163 tab_restore_service_ = NULL; 155 tab_restore_service_ = NULL;
164 } 156 }
165 157
166 void RecentlyClosedTabsBridge::EnsureTabRestoreService() { 158 void RecentlyClosedTabsBridge::EnsureTabRestoreService() {
167 if (tab_restore_service_) 159 if (tab_restore_service_)
168 return; 160 return;
169 161
170 tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile_); 162 tab_restore_service_ = TabRestoreServiceFactory::GetForProfile(profile_);
171 163
172 // TabRestoreServiceFactory::GetForProfile() can return NULL (e.g. in 164 // TabRestoreServiceFactory::GetForProfile() can return NULL (e.g. in
173 // incognito mode). 165 // incognito mode).
174 if (tab_restore_service_) { 166 if (tab_restore_service_) {
175 // This does nothing if the tabs have already been loaded or they 167 // This does nothing if the tabs have already been loaded or they
176 // shouldn't be loaded. 168 // shouldn't be loaded.
177 tab_restore_service_->LoadTabsFromLastSession(); 169 tab_restore_service_->LoadTabsFromLastSession();
178 tab_restore_service_->AddObserver(this); 170 tab_restore_service_->AddObserver(this);
179 } 171 }
180 } 172 }
181 173
182 static jlong Init(JNIEnv* env, 174 static jlong Init(JNIEnv* env,
183 const JavaParamRef<jobject>& obj, 175 const JavaParamRef<jobject>& obj,
184 const JavaParamRef<jobject>& jprofile) { 176 const JavaParamRef<jobject>& jprofile) {
185 RecentlyClosedTabsBridge* bridge = new RecentlyClosedTabsBridge( 177 RecentlyClosedTabsBridge* bridge = new RecentlyClosedTabsBridge(
186 ProfileAndroid::FromProfileAndroid(jprofile)); 178 obj, ProfileAndroid::FromProfileAndroid(jprofile));
187 return reinterpret_cast<intptr_t>(bridge); 179 return reinterpret_cast<intptr_t>(bridge);
188 } 180 }
189 181
190 // static 182 // static
191 bool RecentlyClosedTabsBridge::Register(JNIEnv* env) { 183 bool RecentlyClosedTabsBridge::Register(JNIEnv* env) {
192 return RegisterNativesImpl(env); 184 return RegisterNativesImpl(env);
193 } 185 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698