| 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/foreign_session_helper.h" | 5 #include "chrome/browser/android/foreign_session_helper.h" |
| 6 | 6 |
| 7 #include <jni.h> | 7 #include <jni.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 int selected_index = tab.normalized_navigation_index(); | 91 int selected_index = tab.normalized_navigation_index(); |
| 92 DCHECK_GE(selected_index, 0); | 92 DCHECK_GE(selected_index, 0); |
| 93 DCHECK_LT(selected_index, static_cast<int>(tab.navigations.size())); | 93 DCHECK_LT(selected_index, static_cast<int>(tab.navigations.size())); |
| 94 | 94 |
| 95 const sessions::SerializedNavigationEntry& current_navigation = | 95 const sessions::SerializedNavigationEntry& current_navigation = |
| 96 tab.navigations.at(selected_index); | 96 tab.navigations.at(selected_index); |
| 97 | 97 |
| 98 GURL tab_url = current_navigation.virtual_url(); | 98 GURL tab_url = current_navigation.virtual_url(); |
| 99 | 99 |
| 100 Java_ForeignSessionHelper_pushTab( | 100 Java_ForeignSessionHelper_pushTab( |
| 101 env, j_window.obj(), | 101 env, j_window, ConvertUTF8ToJavaString(env, tab_url.spec()), |
| 102 ConvertUTF8ToJavaString(env, tab_url.spec()).obj(), | 102 ConvertUTF16ToJavaString(env, current_navigation.title()), |
| 103 ConvertUTF16ToJavaString(env, current_navigation.title()).obj(), | 103 tab.timestamp.ToJavaTime(), tab.tab_id.id()); |
| 104 tab.timestamp.ToJavaTime(), | |
| 105 tab.tab_id.id()); | |
| 106 } | 104 } |
| 107 | 105 |
| 108 void CopyWindowToJava( | 106 void CopyWindowToJava( |
| 109 JNIEnv* env, | 107 JNIEnv* env, |
| 110 const sessions::SessionWindow& window, | 108 const sessions::SessionWindow& window, |
| 111 ScopedJavaLocalRef<jobject>& j_window) { | 109 ScopedJavaLocalRef<jobject>& j_window) { |
| 112 for (std::vector<sessions::SessionTab*>::const_iterator tab_it = | 110 for (std::vector<sessions::SessionTab*>::const_iterator tab_it = |
| 113 window.tabs.begin(); tab_it != window.tabs.end(); ++tab_it) { | 111 window.tabs.begin(); tab_it != window.tabs.end(); ++tab_it) { |
| 114 const sessions::SessionTab &session_tab = **tab_it; | 112 const sessions::SessionTab &session_tab = **tab_it; |
| 115 | 113 |
| 116 if (ShouldSkipTab(session_tab)) | 114 if (ShouldSkipTab(session_tab)) |
| 117 return; | 115 return; |
| 118 | 116 |
| 119 CopyTabToJava(env, session_tab, j_window); | 117 CopyTabToJava(env, session_tab, j_window); |
| 120 } | 118 } |
| 121 } | 119 } |
| 122 | 120 |
| 123 void CopySessionToJava( | 121 void CopySessionToJava( |
| 124 JNIEnv* env, | 122 JNIEnv* env, |
| 125 const SyncedSession& session, | 123 const SyncedSession& session, |
| 126 ScopedJavaLocalRef<jobject>& j_session) { | 124 ScopedJavaLocalRef<jobject>& j_session) { |
| 127 for (SyncedSession::SyncedWindowMap::const_iterator it = | 125 for (SyncedSession::SyncedWindowMap::const_iterator it = |
| 128 session.windows.begin(); it != session.windows.end(); ++it) { | 126 session.windows.begin(); it != session.windows.end(); ++it) { |
| 129 const sessions::SessionWindow &window = *(it->second); | 127 const sessions::SessionWindow &window = *(it->second); |
| 130 | 128 |
| 131 if (ShouldSkipWindow(window)) | 129 if (ShouldSkipWindow(window)) |
| 132 continue; | 130 continue; |
| 133 | 131 |
| 134 ScopedJavaLocalRef<jobject> last_pushed_window; | 132 ScopedJavaLocalRef<jobject> last_pushed_window; |
| 135 last_pushed_window.Reset( | 133 last_pushed_window.Reset(Java_ForeignSessionHelper_pushWindow( |
| 136 Java_ForeignSessionHelper_pushWindow( | 134 env, j_session, window.timestamp.ToJavaTime(), window.window_id.id())); |
| 137 env, j_session.obj(), | |
| 138 window.timestamp.ToJavaTime(), | |
| 139 window.window_id.id())); | |
| 140 | 135 |
| 141 CopyWindowToJava(env, window, last_pushed_window); | 136 CopyWindowToJava(env, window, last_pushed_window); |
| 142 } | 137 } |
| 143 } | 138 } |
| 144 | 139 |
| 145 } // namespace | 140 } // namespace |
| 146 | 141 |
| 147 static jlong Init(JNIEnv* env, | 142 static jlong Init(JNIEnv* env, |
| 148 const JavaParamRef<jclass>& clazz, | 143 const JavaParamRef<jclass>& clazz, |
| 149 const JavaParamRef<jobject>& profile) { | 144 const JavaParamRef<jobject>& profile) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 const JavaParamRef<jobject>& obj, | 190 const JavaParamRef<jobject>& obj, |
| 196 const JavaParamRef<jobject>& callback) { | 191 const JavaParamRef<jobject>& callback) { |
| 197 callback_.Reset(env, callback); | 192 callback_.Reset(env, callback); |
| 198 } | 193 } |
| 199 | 194 |
| 200 void ForeignSessionHelper::FireForeignSessionCallback() { | 195 void ForeignSessionHelper::FireForeignSessionCallback() { |
| 201 if (callback_.is_null()) | 196 if (callback_.is_null()) |
| 202 return; | 197 return; |
| 203 | 198 |
| 204 JNIEnv* env = AttachCurrentThread(); | 199 JNIEnv* env = AttachCurrentThread(); |
| 205 Java_ForeignSessionCallback_onUpdated(env, callback_.obj()); | 200 Java_ForeignSessionCallback_onUpdated(env, callback_); |
| 206 } | 201 } |
| 207 | 202 |
| 208 void ForeignSessionHelper::OnSyncConfigurationCompleted() { | 203 void ForeignSessionHelper::OnSyncConfigurationCompleted() { |
| 209 FireForeignSessionCallback(); | 204 FireForeignSessionCallback(); |
| 210 } | 205 } |
| 211 | 206 |
| 212 void ForeignSessionHelper::OnForeignSessionUpdated() { | 207 void ForeignSessionHelper::OnForeignSessionUpdated() { |
| 213 FireForeignSessionCallback(); | 208 FireForeignSessionCallback(); |
| 214 } | 209 } |
| 215 | 210 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 241 for (size_t i = 0; i < sessions.size(); ++i) { | 236 for (size_t i = 0; i < sessions.size(); ++i) { |
| 242 const sync_driver::SyncedSession& session = *(sessions[i]); | 237 const sync_driver::SyncedSession& session = *(sessions[i]); |
| 243 if (ShouldSkipSession(session)) | 238 if (ShouldSkipSession(session)) |
| 244 continue; | 239 continue; |
| 245 | 240 |
| 246 const bool is_collapsed = collapsed_sessions->HasKey(session.session_tag); | 241 const bool is_collapsed = collapsed_sessions->HasKey(session.session_tag); |
| 247 | 242 |
| 248 if (is_collapsed) | 243 if (is_collapsed) |
| 249 pref_collapsed_sessions->SetBoolean(session.session_tag, true); | 244 pref_collapsed_sessions->SetBoolean(session.session_tag, true); |
| 250 | 245 |
| 251 last_pushed_session.Reset( | 246 last_pushed_session.Reset(Java_ForeignSessionHelper_pushSession( |
| 252 Java_ForeignSessionHelper_pushSession( | 247 env, result, ConvertUTF8ToJavaString(env, session.session_tag), |
| 253 env, | 248 ConvertUTF8ToJavaString(env, session.session_name), session.device_type, |
| 254 result, | 249 session.modified_time.ToJavaTime())); |
| 255 ConvertUTF8ToJavaString(env, session.session_tag).obj(), | |
| 256 ConvertUTF8ToJavaString(env, session.session_name).obj(), | |
| 257 session.device_type, | |
| 258 session.modified_time.ToJavaTime())); | |
| 259 | 250 |
| 260 const std::string group_name = | 251 const std::string group_name = |
| 261 base::FieldTrialList::FindFullName("TabSyncByRecency"); | 252 base::FieldTrialList::FindFullName("TabSyncByRecency"); |
| 262 if (group_name == "Enabled") { | 253 if (group_name == "Enabled") { |
| 263 // Create a custom window with tabs from all windows included and ordered | 254 // Create a custom window with tabs from all windows included and ordered |
| 264 // by recency (GetForeignSessionTabs will do ordering automatically). | 255 // by recency (GetForeignSessionTabs will do ordering automatically). |
| 265 std::vector<const sessions::SessionTab*> tabs; | 256 std::vector<const sessions::SessionTab*> tabs; |
| 266 open_tabs->GetForeignSessionTabs(session.session_tag, &tabs); | 257 open_tabs->GetForeignSessionTabs(session.session_tag, &tabs); |
| 267 ScopedJavaLocalRef<jobject> last_pushed_window( | 258 ScopedJavaLocalRef<jobject> last_pushed_window( |
| 268 Java_ForeignSessionHelper_pushWindow( | 259 Java_ForeignSessionHelper_pushWindow( |
| 269 env, last_pushed_session.obj(), | 260 env, last_pushed_session, session.modified_time.ToJavaTime(), 0)); |
| 270 session.modified_time.ToJavaTime(), 0)); | |
| 271 for (const sessions::SessionTab* tab : tabs) { | 261 for (const sessions::SessionTab* tab : tabs) { |
| 272 if (ShouldSkipTab(*tab)) | 262 if (ShouldSkipTab(*tab)) |
| 273 continue; | 263 continue; |
| 274 CopyTabToJava(env, *tab, last_pushed_window); | 264 CopyTabToJava(env, *tab, last_pushed_window); |
| 275 } | 265 } |
| 276 } else { | 266 } else { |
| 277 // Push the full session, with tabs ordered by visual position. | 267 // Push the full session, with tabs ordered by visual position. |
| 278 CopySessionToJava(env, session, last_pushed_session); | 268 CopySessionToJava(env, session, last_pushed_session); |
| 279 } | 269 } |
| 280 } | 270 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 const JavaParamRef<jstring>& session_tag) { | 321 const JavaParamRef<jstring>& session_tag) { |
| 332 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); | 322 OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate(profile_); |
| 333 if (open_tabs) | 323 if (open_tabs) |
| 334 open_tabs->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); | 324 open_tabs->DeleteForeignSession(ConvertJavaStringToUTF8(env, session_tag)); |
| 335 } | 325 } |
| 336 | 326 |
| 337 // static | 327 // static |
| 338 bool ForeignSessionHelper::RegisterForeignSessionHelper(JNIEnv* env) { | 328 bool ForeignSessionHelper::RegisterForeignSessionHelper(JNIEnv* env) { |
| 339 return RegisterNativesImpl(env); | 329 return RegisterNativesImpl(env); |
| 340 } | 330 } |
| OLD | NEW |