Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: components/favicon/ios/web_favicon_driver.mm

Issue 2677993002: Use IOSImageDataFetcherWrapper for favicon (Closed)
Patch Set: Add header Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/favicon/ios/web_favicon_driver.h" 5 #include "components/favicon/ios/web_favicon_driver.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h"
sdefresne 2017/02/07 10:18:30 I think this is unused.
gambard 2017/02/08 14:48:12 Done.
8 #include "components/favicon/core/favicon_url.h" 9 #include "components/favicon/core/favicon_url.h"
9 #include "components/favicon/ios/favicon_url_util.h" 10 #include "components/favicon/ios/favicon_url_util.h"
10 #include "ios/web/public/browser_state.h" 11 #include "ios/web/public/browser_state.h"
11 #include "ios/web/public/favicon_status.h" 12 #include "ios/web/public/favicon_status.h"
12 #include "ios/web/public/navigation_item.h" 13 #include "ios/web/public/navigation_item.h"
13 #include "ios/web/public/navigation_manager.h" 14 #include "ios/web/public/navigation_manager.h"
14 #include "ios/web/public/web_state/web_state.h" 15 #include "ios/web/public/web_state/web_state.h"
16 #include "ios/web/public/web_thread.h"
17 #include "skia/ext/skia_utils_ios.h"
18 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "ui/gfx/image/image.h" 19 #include "ui/gfx/image/image.h"
16 20
17 DEFINE_WEB_STATE_USER_DATA_KEY(favicon::WebFaviconDriver); 21 DEFINE_WEB_STATE_USER_DATA_KEY(favicon::WebFaviconDriver);
18 22
23 // Callback for the download of favicon.
24 using ImageDownloadCallback =
25 base::Callback<void(int image_id,
26 int http_status_code,
27 const GURL& image_url,
28 const std::vector<SkBitmap>& bitmaps,
29 const std::vector<gfx::Size>& sizes)>;
30
19 namespace favicon { 31 namespace favicon {
20 32
21 // static 33 // static
22 void WebFaviconDriver::CreateForWebState( 34 void WebFaviconDriver::CreateForWebState(
23 web::WebState* web_state, 35 web::WebState* web_state,
24 FaviconService* favicon_service, 36 FaviconService* favicon_service,
25 history::HistoryService* history_service, 37 history::HistoryService* history_service,
26 bookmarks::BookmarkModel* bookmark_model) { 38 bookmarks::BookmarkModel* bookmark_model) {
27 if (FromWebState(web_state)) 39 if (FromWebState(web_state))
28 return; 40 return;
(...skipping 19 matching lines...) Expand all
48 web_state()->GetNavigationManager()->GetLastCommittedItem(); 60 web_state()->GetNavigationManager()->GetLastCommittedItem();
49 return item ? item->GetFavicon().valid : false; 61 return item ? item->GetFavicon().valid : false;
50 } 62 }
51 63
52 int WebFaviconDriver::StartDownload(const GURL& url, int max_image_size) { 64 int WebFaviconDriver::StartDownload(const GURL& url, int max_image_size) {
53 if (WasUnableToDownloadFavicon(url)) { 65 if (WasUnableToDownloadFavicon(url)) {
54 DVLOG(1) << "Skip Failed FavIcon: " << url; 66 DVLOG(1) << "Skip Failed FavIcon: " << url;
55 return 0; 67 return 0;
56 } 68 }
57 69
58 return web_state()->DownloadImage( 70 static int downloaded_image_count = 0;
59 url, true, max_image_size, false, 71 int local_download_id = ++downloaded_image_count;
60 base::Bind(&FaviconDriverImpl::DidDownloadFavicon, 72
61 base::Unretained(this))); 73 ImageDownloadCallback local_image_callback = base::Bind(
74 &FaviconDriverImpl::DidDownloadFavicon, base::Unretained(this));
75 GURL local_url(url);
76
77 image_fetcher::IOSImageDataFetcherCallback local_callback = ^(
78 NSData* data, const int response_code) {
79 if (response_code == image_fetcher::ImageDataFetcher::RESPONSE_CODE_INVALID)
80 return;
81
82 std::vector<SkBitmap> frames;
83 std::vector<gfx::Size> sizes;
84 if (data) {
85 frames = skia::ImageDataToSkBitmaps(data);
86 for (const auto& frame : frames) {
87 sizes.push_back(gfx::Size(frame.width(), frame.height()));
88 }
89 }
90 local_image_callback.Run(local_download_id, response_code, local_url,
91 frames, sizes);
92 };
93 image_fetcher_.FetchImageDataWebpDecoded(url, local_callback);
94
95 return downloaded_image_count;
62 } 96 }
63 97
64 bool WebFaviconDriver::IsOffTheRecord() { 98 bool WebFaviconDriver::IsOffTheRecord() {
65 DCHECK(web_state()); 99 DCHECK(web_state());
66 return web_state()->GetBrowserState()->IsOffTheRecord(); 100 return web_state()->GetBrowserState()->IsOffTheRecord();
67 } 101 }
68 102
69 GURL WebFaviconDriver::GetActiveURL() { 103 GURL WebFaviconDriver::GetActiveURL() {
70 web::NavigationItem* item = 104 web::NavigationItem* item =
71 web_state()->GetNavigationManager()->GetVisibleItem(); 105 web_state()->GetNavigationManager()->GetVisibleItem();
(...skipping 17 matching lines...) Expand all
89 123
90 NotifyFaviconUpdatedObservers(notification_icon_type, icon_url, 124 NotifyFaviconUpdatedObservers(notification_icon_type, icon_url,
91 icon_url_changed, image); 125 icon_url_changed, image);
92 } 126 }
93 127
94 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state, 128 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state,
95 FaviconService* favicon_service, 129 FaviconService* favicon_service,
96 history::HistoryService* history_service, 130 history::HistoryService* history_service,
97 bookmarks::BookmarkModel* bookmark_model) 131 bookmarks::BookmarkModel* bookmark_model)
98 : web::WebStateObserver(web_state), 132 : web::WebStateObserver(web_state),
99 FaviconDriverImpl(favicon_service, history_service, bookmark_model) { 133 FaviconDriverImpl(favicon_service, history_service, bookmark_model),
100 } 134 image_fetcher_(web_state->GetBrowserState()->GetRequestContext(),
135 web::WebThread::GetBlockingPool()) {}
101 136
102 WebFaviconDriver::~WebFaviconDriver() { 137 WebFaviconDriver::~WebFaviconDriver() {
103 } 138 }
104 139
105 void WebFaviconDriver::FaviconUrlUpdated( 140 void WebFaviconDriver::FaviconUrlUpdated(
106 const std::vector<web::FaviconURL>& candidates) { 141 const std::vector<web::FaviconURL>& candidates) {
107 DCHECK(!candidates.empty()); 142 DCHECK(!candidates.empty());
108 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates)); 143 OnUpdateFaviconURL(GetActiveURL(), FaviconURLsFromWebFaviconURLs(candidates));
109 } 144 }
110 145
111 } // namespace favicon 146 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698