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

Side by Side Diff: content/renderer/fetchers/multi_resolution_image_resource_fetcher.cc

Issue 14322023: Don't request missing favicon on every page request. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync up to r199996 Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "content/renderer/fetchers/multi_resolution_image_resource_fetcher.h" 5 #include "content/renderer/fetchers/multi_resolution_image_resource_fetcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
10 #include "third_party/skia/include/core/SkBitmap.h" 10 #include "third_party/skia/include/core/SkBitmap.h"
11 #include "ui/gfx/size.h" 11 #include "ui/gfx/size.h"
12 #include "webkit/glue/image_decoder.h" 12 #include "webkit/glue/image_decoder.h"
13 13
14 using WebKit::WebFrame; 14 using WebKit::WebFrame;
15 using WebKit::WebURLRequest; 15 using WebKit::WebURLRequest;
16 using WebKit::WebURLResponse; 16 using WebKit::WebURLResponse;
17 17
18 namespace content { 18 namespace content {
19 19
20 MultiResolutionImageResourceFetcher::MultiResolutionImageResourceFetcher( 20 MultiResolutionImageResourceFetcher::MultiResolutionImageResourceFetcher(
21 const GURL& image_url, 21 const GURL& image_url,
22 WebFrame* frame, 22 WebFrame* frame,
23 int id, 23 int id,
24 WebURLRequest::TargetType target_type, 24 WebURLRequest::TargetType target_type,
25 const Callback& callback) 25 const Callback& callback)
26 : callback_(callback), 26 : callback_(callback),
27 id_(id), 27 id_(id),
28 http_status_code_(0),
28 image_url_(image_url) { 29 image_url_(image_url) {
29 fetcher_.reset(new ResourceFetcher( 30 fetcher_.reset(new ResourceFetcher(
30 image_url, frame, target_type, 31 image_url, frame, target_type,
31 base::Bind(&MultiResolutionImageResourceFetcher::OnURLFetchComplete, 32 base::Bind(&MultiResolutionImageResourceFetcher::OnURLFetchComplete,
32 base::Unretained(this)))); 33 base::Unretained(this))));
33 } 34 }
34 35
35 MultiResolutionImageResourceFetcher::~MultiResolutionImageResourceFetcher() { 36 MultiResolutionImageResourceFetcher::~MultiResolutionImageResourceFetcher() {
36 if (!fetcher_->completed()) 37 if (!fetcher_->completed())
37 fetcher_->Cancel(); 38 fetcher_->Cancel();
38 } 39 }
39 40
40 void MultiResolutionImageResourceFetcher::OnURLFetchComplete( 41 void MultiResolutionImageResourceFetcher::OnURLFetchComplete(
41 const WebURLResponse& response, 42 const WebURLResponse& response,
42 const std::string& data) { 43 const std::string& data) {
43 std::vector<SkBitmap> bitmaps; 44 std::vector<SkBitmap> bitmaps;
44 if (!response.isNull() && response.httpStatusCode() == 200) { 45 if (!response.isNull()) {
45 // Request succeeded, try to convert it to an image. 46 http_status_code_ = response.httpStatusCode();
46 bitmaps = webkit_glue::ImageDecoder::DecodeAll( 47 if (http_status_code_ == 200) {
47 reinterpret_cast<const unsigned char*>(data.data()), data.size()); 48 // Request succeeded, try to convert it to an image.
49 bitmaps = webkit_glue::ImageDecoder::DecodeAll(
50 reinterpret_cast<const unsigned char*>(data.data()), data.size());
51 }
48 } // else case: 52 } // else case:
49 // If we get here, it means no image from server or couldn't decode the 53 // If we get here, it means no image from server or couldn't decode the
50 // response as an image. The delegate will see an empty vector. 54 // response as an image. The delegate will see an empty vector.
51 55
52 // Take a reference to the callback as running the callback may lead to our 56 // Take a reference to the callback as running the callback may lead to our
53 // destruction. 57 // destruction.
54 Callback callback = callback_; 58 Callback callback = callback_;
55 callback.Run(this, bitmaps); 59 callback.Run(this, bitmaps);
56 } 60 }
57 61
58 } // namespace content 62 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/fetchers/multi_resolution_image_resource_fetcher.h ('k') | content/renderer/image_loading_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698