Commit fc1897fb authored by Victor Hugo Vianna Silva's avatar Victor Hugo Vianna Silva Committed by Commit Bot

Change order of sync/local favicon queries in recent tabs menu

Prefactoring step for making FaviconSource and RecentTabsSubMenuModel
share the same code for favicon retrieval. We request first from local
storage and then from sync in case of failure. We no longer rely on the
fact that the tab is local or not. This order of operations is the one
currently used in FaviconSource.

Bug: 955475
Change-Id: I02ed5615ae462b916a09b3d0dd85dea39d88a680
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1609849
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660077}
parent c9ecec13
...@@ -563,29 +563,9 @@ void RecentTabsSubMenuModel::AddDeviceFavicon( ...@@ -563,29 +563,9 @@ void RecentTabsSubMenuModel::AddDeviceFavicon(
} }
void RecentTabsSubMenuModel::AddTabFavicon(int command_id, const GURL& url) { void RecentTabsSubMenuModel::AddTabFavicon(int command_id, const GURL& url) {
bool is_local_tab = command_id < kFirstOtherDevicesTabCommandId;
int index_in_menu = GetIndexOfCommandId(command_id); int index_in_menu = GetIndexOfCommandId(command_id);
if (!is_local_tab) { // Start to fetch the favicon from local history asynchronously.
// If tab has synced favicon, use it.
// Note that currently, other devices' tabs only have favicons if
// --sync-tab-favicons switch is on; according to zea@, this flag is now
// automatically enabled for iOS and android, and they're looking into
// enabling it for other platforms.
sync_sessions::OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate();
scoped_refptr<base::RefCountedMemory> favicon_png;
if (open_tabs &&
open_tabs->GetSyncedFaviconForPageURL(url.spec(), &favicon_png)) {
favicon::RecordFaviconRequestMetric(
favicon::FaviconRequestOrigin::RECENTLY_CLOSED_TABS,
favicon::FaviconAvailability::kSync);
gfx::Image image = gfx::Image::CreateFrom1xPNGBytes(favicon_png);
SetIcon(index_in_menu, image);
return;
}
}
// Otherwise, start to fetch the favicon from local history asynchronously.
// Set default icon first. // Set default icon first.
SetIcon(index_in_menu, favicon::GetDefaultFavicon()); SetIcon(index_in_menu, favicon::GetDefaultFavicon());
// Start request to fetch actual icon if possible. // Start request to fetch actual icon if possible.
...@@ -595,34 +575,52 @@ void RecentTabsSubMenuModel::AddTabFavicon(int command_id, const GURL& url) { ...@@ -595,34 +575,52 @@ void RecentTabsSubMenuModel::AddTabFavicon(int command_id, const GURL& url) {
if (!favicon_service) if (!favicon_service)
return; return;
bool is_local_tab = command_id < kFirstOtherDevicesTabCommandId;
favicon_service->GetFaviconImageForPageURL( favicon_service->GetFaviconImageForPageURL(
url, url,
base::Bind(&RecentTabsSubMenuModel::OnFaviconDataAvailable, base::Bind(&RecentTabsSubMenuModel::OnFaviconDataAvailable,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(), url, command_id),
command_id),
is_local_tab ? &local_tab_cancelable_task_tracker_ is_local_tab ? &local_tab_cancelable_task_tracker_
: &other_devices_tab_cancelable_task_tracker_); : &other_devices_tab_cancelable_task_tracker_);
} }
void RecentTabsSubMenuModel::OnFaviconDataAvailable( void RecentTabsSubMenuModel::OnFaviconDataAvailable(
const GURL& page_url,
int command_id, int command_id,
const favicon_base::FaviconImageResult& image_result) { const favicon_base::FaviconImageResult& image_result) {
if (image_result.image.IsEmpty()) { int index_in_menu = GetIndexOfCommandId(command_id);
if (!image_result.image.IsEmpty()) {
favicon::RecordFaviconRequestMetric( favicon::RecordFaviconRequestMetric(
favicon::FaviconRequestOrigin::RECENTLY_CLOSED_TABS, favicon::FaviconRequestOrigin::RECENTLY_CLOSED_TABS,
favicon::FaviconAvailability::kNotAvailable); favicon::FaviconAvailability::kLocal);
DCHECK_GT(index_in_menu, -1);
SetIcon(index_in_menu, image_result.image);
ui::MenuModelDelegate* delegate = menu_model_delegate();
if (delegate)
delegate->OnIconChanged(index_in_menu);
return;
}
// If tab has synced favicon, use it.
// Note that currently, other devices' tabs only have favicons if
// --sync-tab-favicons switch is on; according to zea@, this flag is now
// automatically enabled for iOS and android, and they're looking into
// enabling it for other platforms.
sync_sessions::OpenTabsUIDelegate* open_tabs = GetOpenTabsUIDelegate();
scoped_refptr<base::RefCountedMemory> favicon_png;
if (open_tabs &&
open_tabs->GetSyncedFaviconForPageURL(page_url.spec(), &favicon_png)) {
favicon::RecordFaviconRequestMetric(
favicon::FaviconRequestOrigin::RECENTLY_CLOSED_TABS,
favicon::FaviconAvailability::kSync);
gfx::Image image = gfx::Image::CreateFrom1xPNGBytes(favicon_png);
SetIcon(index_in_menu, image);
return; return;
} }
favicon::RecordFaviconRequestMetric( favicon::RecordFaviconRequestMetric(
favicon::FaviconRequestOrigin::RECENTLY_CLOSED_TABS, favicon::FaviconRequestOrigin::RECENTLY_CLOSED_TABS,
favicon::FaviconAvailability::kLocal); favicon::FaviconAvailability::kNotAvailable);
int index_in_menu = GetIndexOfCommandId(command_id);
DCHECK_GT(index_in_menu, -1);
SetIcon(index_in_menu, image_result.image);
ui::MenuModelDelegate* delegate = menu_model_delegate();
if (delegate)
delegate->OnIconChanged(index_in_menu);
} }
int RecentTabsSubMenuModel::CommandIdToTabVectorIndex( int RecentTabsSubMenuModel::CommandIdToTabVectorIndex(
......
...@@ -119,6 +119,7 @@ class RecentTabsSubMenuModel : public ui::SimpleMenuModel, ...@@ -119,6 +119,7 @@ class RecentTabsSubMenuModel : public ui::SimpleMenuModel,
// OnFaviconDataAvailable() will be invoked when the favicon is ready. // OnFaviconDataAvailable() will be invoked when the favicon is ready.
void AddTabFavicon(int command_id, const GURL& url); void AddTabFavicon(int command_id, const GURL& url);
void OnFaviconDataAvailable( void OnFaviconDataAvailable(
const GURL& page_url,
int command_id, int command_id,
const favicon_base::FaviconImageResult& image_result); const favicon_base::FaviconImageResult& image_result);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment