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/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 break; | 571 break; |
572 | 572 |
573 case browser_sync::SyncedSession::TYPE_CHROMEOS: | 573 case browser_sync::SyncedSession::TYPE_CHROMEOS: |
574 case browser_sync::SyncedSession::TYPE_WIN: | 574 case browser_sync::SyncedSession::TYPE_WIN: |
575 case browser_sync::SyncedSession::TYPE_MACOSX: | 575 case browser_sync::SyncedSession::TYPE_MACOSX: |
576 case browser_sync::SyncedSession::TYPE_LINUX: | 576 case browser_sync::SyncedSession::TYPE_LINUX: |
577 case browser_sync::SyncedSession::TYPE_OTHER: | 577 case browser_sync::SyncedSession::TYPE_OTHER: |
578 case browser_sync::SyncedSession::TYPE_UNSET: | 578 case browser_sync::SyncedSession::TYPE_UNSET: |
579 favicon_id = IDR_LAPTOP_FAVICON; | 579 favicon_id = IDR_LAPTOP_FAVICON; |
580 break; | 580 break; |
581 }; | 581 } |
582 | 582 |
583 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 583 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
584 SetIcon(index_in_menu, rb.GetNativeImageNamed(favicon_id)); | 584 SetIcon(index_in_menu, rb.GetNativeImageNamed(favicon_id)); |
585 } | 585 } |
586 | 586 |
587 void RecentTabsSubMenuModel::AddTabFavicon(int command_id, const GURL& url) { | 587 void RecentTabsSubMenuModel::AddTabFavicon(int command_id, const GURL& url) { |
588 bool is_local_tab = command_id < kFirstOtherDevicesTabCommandId; | 588 bool is_local_tab = command_id < kFirstOtherDevicesTabCommandId; |
589 int index_in_menu = GetIndexOfCommandId(command_id); | 589 int index_in_menu = GetIndexOfCommandId(command_id); |
590 | 590 |
591 if (!is_local_tab) { | 591 if (!is_local_tab) { |
(...skipping 14 matching lines...) Expand all Loading... |
606 | 606 |
607 // Otherwise, start to fetch the favicon from local history asynchronously. | 607 // Otherwise, start to fetch the favicon from local history asynchronously. |
608 // Set default icon first. | 608 // Set default icon first. |
609 SetIcon(index_in_menu, default_favicon_); | 609 SetIcon(index_in_menu, default_favicon_); |
610 // Start request to fetch actual icon if possible. | 610 // Start request to fetch actual icon if possible. |
611 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | 611 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( |
612 browser_->profile(), Profile::EXPLICIT_ACCESS); | 612 browser_->profile(), Profile::EXPLICIT_ACCESS); |
613 if (!favicon_service) | 613 if (!favicon_service) |
614 return; | 614 return; |
615 | 615 |
616 favicon_service->GetFaviconImageForURL( | 616 favicon_service->GetFaviconImageForPageURL( |
617 FaviconService::FaviconForURLParams( | 617 FaviconService::FaviconForPageURLParams( |
618 url, favicon_base::FAVICON, gfx::kFaviconSize), | 618 url, favicon_base::FAVICON, gfx::kFaviconSize), |
619 base::Bind(&RecentTabsSubMenuModel::OnFaviconDataAvailable, | 619 base::Bind(&RecentTabsSubMenuModel::OnFaviconDataAvailable, |
620 weak_ptr_factory_.GetWeakPtr(), | 620 weak_ptr_factory_.GetWeakPtr(), |
621 command_id), | 621 command_id), |
622 is_local_tab ? &local_tab_cancelable_task_tracker_ | 622 is_local_tab ? &local_tab_cancelable_task_tracker_ |
623 : &other_devices_tab_cancelable_task_tracker_); | 623 : &other_devices_tab_cancelable_task_tracker_); |
624 } | 624 } |
625 | 625 |
626 void RecentTabsSubMenuModel::OnFaviconDataAvailable( | 626 void RecentTabsSubMenuModel::OnFaviconDataAvailable( |
627 int command_id, | 627 int command_id, |
(...skipping 18 matching lines...) Expand all Loading... |
646 } | 646 } |
647 *tab_items = &local_tab_navigation_items_; | 647 *tab_items = &local_tab_navigation_items_; |
648 return command_id - kFirstLocalTabCommandId; | 648 return command_id - kFirstLocalTabCommandId; |
649 } | 649 } |
650 | 650 |
651 void RecentTabsSubMenuModel::ClearLocalEntries() { | 651 void RecentTabsSubMenuModel::ClearLocalEntries() { |
652 // Remove local items (recently closed tabs and windows) from menumodel. | 652 // Remove local items (recently closed tabs and windows) from menumodel. |
653 while (last_local_model_index_ >= 0) | 653 while (last_local_model_index_ >= 0) |
654 RemoveItemAt(last_local_model_index_--); | 654 RemoveItemAt(last_local_model_index_--); |
655 | 655 |
656 // Cancel asynchronous FaviconService::GetFaviconImageForURL() tasks of all | 656 // Cancel asynchronous FaviconService::GetFaviconImageForPageURL() tasks of |
| 657 // all |
657 // local tabs. | 658 // local tabs. |
658 local_tab_cancelable_task_tracker_.TryCancelAll(); | 659 local_tab_cancelable_task_tracker_.TryCancelAll(); |
659 | 660 |
660 // Remove all local tab navigation items. | 661 // Remove all local tab navigation items. |
661 local_tab_navigation_items_.clear(); | 662 local_tab_navigation_items_.clear(); |
662 | 663 |
663 // Remove all local window items. | 664 // Remove all local window items. |
664 local_window_items_.clear(); | 665 local_window_items_.clear(); |
665 } | 666 } |
666 | 667 |
(...skipping 17 matching lines...) Expand all Loading... |
684 | 685 |
685 ui::MenuModelDelegate* menu_model_delegate = GetMenuModelDelegate(); | 686 ui::MenuModelDelegate* menu_model_delegate = GetMenuModelDelegate(); |
686 if (menu_model_delegate) | 687 if (menu_model_delegate) |
687 menu_model_delegate->OnMenuStructureChanged(); | 688 menu_model_delegate->OnMenuStructureChanged(); |
688 } | 689 } |
689 | 690 |
690 void RecentTabsSubMenuModel::TabRestoreServiceDestroyed( | 691 void RecentTabsSubMenuModel::TabRestoreServiceDestroyed( |
691 TabRestoreService* service) { | 692 TabRestoreService* service) { |
692 TabRestoreServiceChanged(service); | 693 TabRestoreServiceChanged(service); |
693 } | 694 } |
OLD | NEW |