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/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" |
11 #include "chrome/browser/sessions/session_restore.h" | 11 #include "chrome/browser/sessions/session_restore.h" |
12 #include "chrome/browser/sessions/tab_restore_service_factory.h" | 12 #include "chrome/browser/sessions/tab_restore_service_factory.h" |
13 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | 13 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" |
14 #include "components/sessions/core/live_tab.h" | 14 #include "components/sessions/core/live_tab.h" |
15 #include "components/sessions/core/tab_restore_service.h" | 15 #include "components/sessions/core/tab_restore_service.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "jni/RecentlyClosedBridge_jni.h" | 17 #include "jni/RecentlyClosedBridge_jni.h" |
18 | 18 |
19 using base::android::AttachCurrentThread; | 19 using base::android::AttachCurrentThread; |
20 using base::android::ConvertUTF16ToJavaString; | 20 using base::android::ConvertUTF16ToJavaString; |
21 using base::android::ConvertUTF8ToJavaString; | 21 using base::android::ConvertUTF8ToJavaString; |
22 using base::android::ScopedJavaLocalRef; | 22 using base::android::ScopedJavaLocalRef; |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 void AddTabToList(JNIEnv* env, | 26 void AddTabToList(JNIEnv* env, |
27 sessions::TabRestoreService::Entry* entry, | 27 const sessions::TabRestoreService::Tab& tab, |
28 jobject jtabs_list) { | 28 jobject jtabs_list) { |
29 const sessions::TabRestoreService::Tab* tab = | |
30 static_cast<sessions::TabRestoreService::Tab*>(entry); | |
31 const sessions::SerializedNavigationEntry& current_navigation = | 29 const sessions::SerializedNavigationEntry& current_navigation = |
32 tab->navigations.at(tab->current_navigation_index); | 30 tab.navigations.at(tab.current_navigation_index); |
33 Java_RecentlyClosedBridge_pushTab( | 31 Java_RecentlyClosedBridge_pushTab( |
34 env, jtabs_list, entry->id, | 32 env, jtabs_list, tab.id, |
35 ConvertUTF16ToJavaString(env, current_navigation.title()).obj(), | 33 ConvertUTF16ToJavaString(env, current_navigation.title()).obj(), |
36 ConvertUTF8ToJavaString(env, current_navigation.virtual_url().spec()) | 34 ConvertUTF8ToJavaString(env, current_navigation.virtual_url().spec()) |
37 .obj()); | 35 .obj()); |
38 } | 36 } |
39 | 37 |
40 void AddTabsToList(JNIEnv* env, | 38 void AddTabsToList(JNIEnv* env, |
41 const sessions::TabRestoreService::Entries& entries, | 39 const sessions::TabRestoreService::Entries& entries, |
42 jobject jtabs_list, | 40 jobject jtabs_list, |
43 int max_tab_count) { | 41 int max_tab_count) { |
44 int added_count = 0; | 42 int added_count = 0; |
45 for (sessions::TabRestoreService::Entries::const_iterator it = | 43 for (const auto& entry : entries) { |
46 entries.begin(); | |
47 it != entries.end() && added_count < max_tab_count; ++it) { | |
48 sessions::TabRestoreService::Entry* entry = *it; | |
49 DCHECK_EQ(entry->type, sessions::TabRestoreService::TAB); | 44 DCHECK_EQ(entry->type, sessions::TabRestoreService::TAB); |
50 if (entry->type == sessions::TabRestoreService::TAB) { | 45 if (entry->type == sessions::TabRestoreService::TAB) { |
51 AddTabToList(env, entry, jtabs_list); | 46 auto& tab = static_cast<const sessions::TabRestoreService::Tab&>(*entry); |
52 ++added_count; | 47 AddTabToList(env, tab, jtabs_list); |
| 48 if (++added_count == max_tab_count) |
| 49 break; |
53 } | 50 } |
54 } | 51 } |
55 } | 52 } |
56 | 53 |
57 } // namespace | 54 } // namespace |
58 | 55 |
59 RecentlyClosedTabsBridge::RecentlyClosedTabsBridge(Profile* profile) | 56 RecentlyClosedTabsBridge::RecentlyClosedTabsBridge(Profile* profile) |
60 : profile_(profile), | 57 : profile_(profile), |
61 tab_restore_service_(NULL) { | 58 tab_restore_service_(NULL) { |
62 } | 59 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 const JavaParamRef<jobject>& jprofile) { | 184 const JavaParamRef<jobject>& jprofile) { |
188 RecentlyClosedTabsBridge* bridge = new RecentlyClosedTabsBridge( | 185 RecentlyClosedTabsBridge* bridge = new RecentlyClosedTabsBridge( |
189 ProfileAndroid::FromProfileAndroid(jprofile)); | 186 ProfileAndroid::FromProfileAndroid(jprofile)); |
190 return reinterpret_cast<intptr_t>(bridge); | 187 return reinterpret_cast<intptr_t>(bridge); |
191 } | 188 } |
192 | 189 |
193 // static | 190 // static |
194 bool RecentlyClosedTabsBridge::Register(JNIEnv* env) { | 191 bool RecentlyClosedTabsBridge::Register(JNIEnv* env) { |
195 return RegisterNativesImpl(env); | 192 return RegisterNativesImpl(env); |
196 } | 193 } |
OLD | NEW |