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