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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 IDS_RECENTLY_CLOSED); | 433 IDS_RECENTLY_CLOSED); |
434 #if defined(OS_MACOSX) | 434 #if defined(OS_MACOSX) |
435 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 435 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
436 SetIcon(last_local_model_index_, | 436 SetIcon(last_local_model_index_, |
437 rb.GetNativeImageNamed(IDR_RECENTLY_CLOSED_WINDOW)); | 437 rb.GetNativeImageNamed(IDR_RECENTLY_CLOSED_WINDOW)); |
438 #else | 438 #else |
439 SetIcon(last_local_model_index_, CreateFavicon(gfx::VectorIconId::TAB)); | 439 SetIcon(last_local_model_index_, CreateFavicon(gfx::VectorIconId::TAB)); |
440 #endif | 440 #endif |
441 | 441 |
442 int added_count = 0; | 442 int added_count = 0; |
443 sessions::TabRestoreService::Entries entries = service->entries(); | 443 for (const auto& entry : service->entries()) { |
444 for (sessions::TabRestoreService::Entries::const_iterator it = | 444 if (added_count == kMaxLocalEntries) |
445 entries.begin(); | 445 break; |
446 it != entries.end() && added_count < kMaxLocalEntries; ++it) { | 446 switch (entry->type) { |
447 sessions::TabRestoreService::Entry* entry = *it; | 447 case sessions::TabRestoreService::TAB: { |
448 if (entry->type == sessions::TabRestoreService::TAB) { | 448 auto& tab = |
449 sessions::TabRestoreService::Tab* tab = | 449 static_cast<const sessions::TabRestoreService::Tab&>(*entry); |
450 static_cast<sessions::TabRestoreService::Tab*>(entry); | 450 const sessions::SerializedNavigationEntry& current_navigation = |
451 const sessions::SerializedNavigationEntry& current_navigation = | 451 tab.navigations.at(tab.current_navigation_index); |
452 tab->navigations.at(tab->current_navigation_index); | 452 BuildLocalTabItem(entry->id, current_navigation.title(), |
453 BuildLocalTabItem( | 453 current_navigation.virtual_url(), |
454 entry->id, | 454 ++last_local_model_index_); |
455 current_navigation.title(), | 455 break; |
456 current_navigation.virtual_url(), | 456 } |
457 ++last_local_model_index_); | 457 case sessions::TabRestoreService::WINDOW: { |
458 } else { | 458 BuildLocalWindowItem( |
459 DCHECK_EQ(entry->type, sessions::TabRestoreService::WINDOW); | 459 entry->id, |
460 BuildLocalWindowItem( | 460 static_cast<const sessions::TabRestoreService::Window&>(*entry) |
461 entry->id, static_cast<sessions::TabRestoreService::Window*>(entry) | 461 .tabs.size(), |
462 ->tabs.size(), | 462 ++last_local_model_index_); |
463 ++last_local_model_index_); | 463 break; |
| 464 } |
464 } | 465 } |
465 ++added_count; | 466 ++added_count; |
466 } | 467 } |
467 } | 468 } |
468 DCHECK_GE(last_local_model_index_, 0); | 469 DCHECK_GE(last_local_model_index_, 0); |
469 } | 470 } |
470 | 471 |
471 void RecentTabsSubMenuModel::BuildTabsFromOtherDevices() { | 472 void RecentTabsSubMenuModel::BuildTabsFromOtherDevices() { |
472 // All other devices' items (device headers or tabs) use AddItem*() to append | 473 // All other devices' items (device headers or tabs) use AddItem*() to append |
473 // a menu item, because they are always only built once (i.e. invoked from | 474 // a menu item, because they are always only built once (i.e. invoked from |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
724 | 725 |
725 ui::MenuModelDelegate* menu_model_delegate = GetMenuModelDelegate(); | 726 ui::MenuModelDelegate* menu_model_delegate = GetMenuModelDelegate(); |
726 if (menu_model_delegate) | 727 if (menu_model_delegate) |
727 menu_model_delegate->OnMenuStructureChanged(); | 728 menu_model_delegate->OnMenuStructureChanged(); |
728 } | 729 } |
729 | 730 |
730 void RecentTabsSubMenuModel::TabRestoreServiceDestroyed( | 731 void RecentTabsSubMenuModel::TabRestoreServiceDestroyed( |
731 sessions::TabRestoreService* service) { | 732 sessions::TabRestoreService* service) { |
732 TabRestoreServiceChanged(service); | 733 TabRestoreServiceChanged(service); |
733 } | 734 } |
OLD | NEW |