| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/ui/toolbar/recent_tabs_sub_menu_model.h" | 5 #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 // Collect tabs from all windows of session, pruning those that are not | 293 // Collect tabs from all windows of session, pruning those that are not |
| 294 // syncable or are NewTabPage, then sort them from most recent to least | 294 // syncable or are NewTabPage, then sort them from most recent to least |
| 295 // recent, independent of which window the tabs were from. | 295 // recent, independent of which window the tabs were from. |
| 296 std::vector<const SessionTab*> tabs_in_session; | 296 std::vector<const SessionTab*> tabs_in_session; |
| 297 for (size_t j = 0; j < windows.size(); ++j) { | 297 for (size_t j = 0; j < windows.size(); ++j) { |
| 298 const SessionWindow* window = windows[j]; | 298 const SessionWindow* window = windows[j]; |
| 299 for (size_t t = 0; t < window->tabs.size(); ++t) { | 299 for (size_t t = 0; t < window->tabs.size(); ++t) { |
| 300 const SessionTab* tab = window->tabs[t]; | 300 const SessionTab* tab = window->tabs[t]; |
| 301 if (tab->navigations.empty()) | 301 if (tab->navigations.empty()) |
| 302 continue; | 302 continue; |
| 303 const TabNavigation& current_navigation = | 303 const sessions::SerializedNavigationEntry& current_navigation = |
| 304 tab->navigations.at(tab->normalized_navigation_index()); | 304 tab->navigations.at(tab->normalized_navigation_index()); |
| 305 if (current_navigation.virtual_url() == | 305 if (current_navigation.virtual_url() == |
| 306 GURL(chrome::kChromeUINewTabURL)) { | 306 GURL(chrome::kChromeUINewTabURL)) { |
| 307 continue; | 307 continue; |
| 308 } | 308 } |
| 309 tabs_in_session.push_back(tab); | 309 tabs_in_session.push_back(tab); |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 if (tabs_in_session.empty()) | 312 if (tabs_in_session.empty()) |
| 313 continue; | 313 continue; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 333 | 333 |
| 334 // We are not supposed to get here unless at least some items were added. | 334 // We are not supposed to get here unless at least some items were added. |
| 335 DCHECK_GT(GetItemCount(), 0); | 335 DCHECK_GT(GetItemCount(), 0); |
| 336 AddSeparator(ui::NORMAL_SEPARATOR); | 336 AddSeparator(ui::NORMAL_SEPARATOR); |
| 337 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_RECENT_TABS_MORE); | 337 AddItemWithStringId(IDC_SHOW_HISTORY, IDS_RECENT_TABS_MORE); |
| 338 } | 338 } |
| 339 | 339 |
| 340 void RecentTabsSubMenuModel::BuildForeignTabItem( | 340 void RecentTabsSubMenuModel::BuildForeignTabItem( |
| 341 const std::string& session_tag, | 341 const std::string& session_tag, |
| 342 const SessionTab& tab) { | 342 const SessionTab& tab) { |
| 343 const TabNavigation& current_navigation = | 343 const sessions::SerializedNavigationEntry& current_navigation = |
| 344 tab.navigations.at(tab.normalized_navigation_index()); | 344 tab.navigations.at(tab.normalized_navigation_index()); |
| 345 NavigationItem item(session_tag, tab.tab_id.id(), | 345 NavigationItem item(session_tag, tab.tab_id.id(), |
| 346 current_navigation.virtual_url()); | 346 current_navigation.virtual_url()); |
| 347 int command_id = ModelIndexToCommandId(model_.size()); | 347 int command_id = ModelIndexToCommandId(model_.size()); |
| 348 // There may be no tab title, in which case, use the url as tab title. | 348 // There may be no tab title, in which case, use the url as tab title. |
| 349 AddItem(command_id, | 349 AddItem(command_id, |
| 350 current_navigation.title().empty() ? | 350 current_navigation.title().empty() ? |
| 351 UTF8ToUTF16(item.url.spec()) : current_navigation.title()); | 351 UTF8ToUTF16(item.url.spec()) : current_navigation.title()); |
| 352 AddTabFavicon(model_.size(), command_id, item.url); | 352 AddTabFavicon(model_.size(), command_id, item.url); |
| 353 model_.push_back(item); | 353 model_.push_back(item); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 RecentTabsSubMenuModel::GetModelAssociator() { | 437 RecentTabsSubMenuModel::GetModelAssociator() { |
| 438 if (!associator_) { | 438 if (!associator_) { |
| 439 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> | 439 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> |
| 440 GetForProfile(browser_->profile()); | 440 GetForProfile(browser_->profile()); |
| 441 // Only return the associator if it exists and it is done syncing sessions. | 441 // Only return the associator if it exists and it is done syncing sessions. |
| 442 if (service && service->ShouldPushChanges()) | 442 if (service && service->ShouldPushChanges()) |
| 443 associator_ = service->GetSessionModelAssociator(); | 443 associator_ = service->GetSessionModelAssociator(); |
| 444 } | 444 } |
| 445 return associator_; | 445 return associator_; |
| 446 } | 446 } |
| OLD | NEW |