Index: chrome/browser/android/foreign_session_helper.cc |
diff --git a/chrome/browser/android/foreign_session_helper.cc b/chrome/browser/android/foreign_session_helper.cc |
index 0c8f0d9483bea7f5ebb0d7883c6d2540de1cc761..99b97a4de301505b0b0801ca0cb5de42dde747e1 100644 |
--- a/chrome/browser/android/foreign_session_helper.cc |
+++ b/chrome/browser/android/foreign_session_helper.cc |
@@ -43,6 +43,51 @@ SessionModelAssociator* GetSessionModelAssociator(Profile* profile) { |
return service->GetSessionModelAssociator(); |
} |
+bool shouldSkipUrl(const GURL& url) { |
Yaron
2013/09/20 22:18:08
All of these should start with Caps.
apiccion
2013/09/20 23:02:57
Done.
|
+ return (url.SchemeIs(chrome::kChromeNativeScheme) || |
+ (url.SchemeIs(chrome::kChromeUIScheme) && |
+ url.host() == chrome::kChromeUINewTabHost)); |
+} |
+ |
+bool shouldSkipTab(const SessionTab& tab) { |
+ if (tab.navigations.empty()) |
+ return true; |
+ |
+ int selected_index = tab.current_navigation_index; |
+ if (selected_index < 0 || |
+ selected_index >= static_cast<int>(tab.navigations.size())) { |
+ return true; |
+ } |
+ |
+ const ::sessions::SerializedNavigationEntry& current_navigation = |
+ tab.navigations.at(selected_index); |
+ |
+ GURL tab_url = current_navigation.virtual_url(); |
+ if (shouldSkipUrl(tab_url)) |
+ return true; |
+ return false; |
+} |
+ |
+bool shouldSkipWindow(const SessionWindow* window) { |
Yaron
2013/09/20 22:18:08
use a const&
apiccion
2013/09/20 23:02:57
Done.
|
+ for (std::vector<SessionTab*>::const_iterator tab_it = window->tabs.begin(); |
+ tab_it != window->tabs.end(); ++tab_it) { |
+ const SessionTab &tab = **tab_it; |
+ if (!shouldSkipTab(tab)) |
+ return false; |
+ } |
+ return true; |
+} |
+ |
+bool shouldSkipSession(const browser_sync::SyncedSession* session) { |
Yaron
2013/09/20 22:18:08
use a const&
apiccion
2013/09/20 23:02:57
Done.
|
+ for (SyncedSession::SyncedWindowMap::const_iterator it = |
+ session->windows.begin(); it != session->windows.end(); ++it) { |
+ const SessionWindow* window = it->second; |
+ if (!shouldSkipWindow(window)) |
+ return false; |
+ } |
+ return true; |
+} |
+ |
void CopyTabsToJava( |
JNIEnv* env, |
const SessionWindow* window, |
@@ -51,23 +96,24 @@ void CopyTabsToJava( |
tab_it != window->tabs.end(); ++tab_it) { |
const SessionTab &tab = **tab_it; |
- if (tab.navigations.empty()) |
+ if (shouldSkipTab(tab)) |
continue; |
+ int selected_index = tab.current_navigation_index; |
+ DCHECK(selected_index >= 0 |
Yaron
2013/09/20 22:18:08
Split to 2 DCHECKs (otherwise you can't tell which
apiccion
2013/09/20 23:02:57
Done.
|
+ && selected_index < static_cast<int>(tab.navigation.size())); |
+ |
const ::sessions::SerializedNavigationEntry& current_navigation = |
- tab.navigations.at(tab.current_navigation_index); |
+ tab.navigations.at(selected_index); |
GURL tab_url = current_navigation.virtual_url(); |
- if (tab_url.SchemeIs(chrome::kChromeNativeScheme) || |
- (tab_url.SchemeIs(chrome::kChromeUIScheme) && |
- tab_url.host() == chrome::kChromeUINewTabHost)) |
- continue; |
Java_ForeignSessionHelper_pushTab( |
env, j_window.obj(), |
ConvertUTF8ToJavaString(env, tab_url.spec()).Release(), |
ConvertUTF16ToJavaString(env, current_navigation.title()).Release(), |
- tab.timestamp.ToInternalValue(), tab.tab_id.id()); |
+ tab.timestamp.ToJavaTime(), |
+ tab.tab_id.id()); |
} |
} |
@@ -79,10 +125,14 @@ void CopyWindowsToJava( |
session->windows.begin(); it != session->windows.end(); ++it) { |
const SessionWindow* window = it->second; |
+ if (shouldSkipWindow(window)) |
+ continue; |
+ |
ScopedJavaLocalRef<jobject> last_pushed_window; |
last_pushed_window.Reset( |
Java_ForeignSessionHelper_pushWindow( |
- env, j_session.obj(), window->timestamp.ToInternalValue(), |
+ env, j_session.obj(), |
+ window->timestamp.ToJavaTime(), |
window->window_id.id())); |
CopyTabsToJava(env, window, last_pushed_window); |
@@ -101,7 +151,6 @@ ForeignSessionHelper::ForeignSessionHelper(Profile* profile) |
: profile_(profile) { |
ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> |
GetForProfile(profile); |
- |
registrar_.Add(this, chrome::NOTIFICATION_SYNC_CONFIGURE_DONE, |
content::Source<ProfileSyncService>(service)); |
registrar_.Add(this, chrome::NOTIFICATION_FOREIGN_SESSION_UPDATED, |
@@ -179,6 +228,8 @@ jboolean ForeignSessionHelper::GetForeignSessions(JNIEnv* env, |
// Note: we don't own the SyncedSessions themselves. |
for (size_t i = 0; i < sessions.size(); ++i) { |
const browser_sync::SyncedSession* session = sessions[i]; |
+ if (shouldSkipSession(session)) |
+ continue; |
const bool is_collapsed = collapsed_sessions->HasKey(session->session_tag); |
@@ -191,9 +242,8 @@ jboolean ForeignSessionHelper::GetForeignSessions(JNIEnv* env, |
result, |
ConvertUTF8ToJavaString(env, session->session_tag).Release(), |
ConvertUTF8ToJavaString(env, session->session_name).Release(), |
- ConvertUTF8ToJavaString(env, |
- session->DeviceTypeAsString()).Release(), |
- session->modified_time.ToInternalValue())); |
+ session->device_type, |
+ session->modified_time.ToJavaTime())); |
CopyWindowsToJava(env, session, last_pushed_session); |
} |
@@ -257,6 +307,14 @@ void ForeignSessionHelper::SetForeignSessionCollapsed(JNIEnv* env, jobject obj, |
update.Get()->Remove(ConvertJavaStringToUTF8(env, session_tag), NULL); |
} |
+jboolean ForeignSessionHelper::GetForeignSessionCollapsed(JNIEnv* env, |
+ jobject obj, |
+ jstring session_tag) { |
+ const DictionaryValue* dict = profile_->GetPrefs()->GetDictionary( |
+ prefs::kNtpCollapsedForeignSessions); |
+ return dict && dict->HasKey(ConvertJavaStringToUTF8(env, session_tag)); |
+} |
+ |
void ForeignSessionHelper::DeleteForeignSession(JNIEnv* env, jobject obj, |
jstring session_tag) { |
SessionModelAssociator* associator = GetSessionModelAssociator(profile_); |