OLD | NEW |
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 "content/child/image_decoder.h" | 9 #include "content/child/image_decoder.h" |
10 #include "content/public/renderer/resource_fetcher.h" | 10 #include "content/public/renderer/resource_fetcher.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 MultiResolutionImageResourceFetcher::MultiResolutionImageResourceFetcher( | 22 MultiResolutionImageResourceFetcher::MultiResolutionImageResourceFetcher( |
23 const GURL& image_url, | 23 const GURL& image_url, |
24 WebFrame* frame, | 24 WebFrame* frame, |
25 int id, | 25 int id, |
26 WebURLRequest::TargetType target_type, | 26 WebURLRequest::TargetType target_type, |
27 const Callback& callback) | 27 const Callback& callback) |
28 : callback_(callback), | 28 : callback_(callback), |
29 id_(id), | 29 id_(id), |
30 http_status_code_(0), | 30 http_status_code_(0), |
31 image_url_(image_url) { | 31 image_url_(image_url) { |
32 fetcher_.reset(ResourceFetcher::Create( | 32 fetcher_.reset(ResourceFetcher::Create(image_url)); |
33 image_url, frame, target_type, | 33 fetcher_->Start( |
| 34 frame, target_type, |
34 base::Bind(&MultiResolutionImageResourceFetcher::OnURLFetchComplete, | 35 base::Bind(&MultiResolutionImageResourceFetcher::OnURLFetchComplete, |
35 base::Unretained(this)))); | 36 base::Unretained(this))); |
36 } | 37 } |
37 | 38 |
38 MultiResolutionImageResourceFetcher::~MultiResolutionImageResourceFetcher() { | 39 MultiResolutionImageResourceFetcher::~MultiResolutionImageResourceFetcher() { |
39 } | 40 } |
40 | 41 |
41 void MultiResolutionImageResourceFetcher::OnURLFetchComplete( | 42 void MultiResolutionImageResourceFetcher::OnURLFetchComplete( |
42 const WebURLResponse& response, | 43 const WebURLResponse& response, |
43 const std::string& data) { | 44 const std::string& data) { |
44 std::vector<SkBitmap> bitmaps; | 45 std::vector<SkBitmap> bitmaps; |
45 if (!response.isNull()) { | 46 if (!response.isNull()) { |
46 http_status_code_ = response.httpStatusCode(); | 47 http_status_code_ = response.httpStatusCode(); |
47 GURL url(response.url()); | 48 GURL url(response.url()); |
48 if (http_status_code_ == 200 || url.SchemeIsFile()) { | 49 if (http_status_code_ == 200 || url.SchemeIsFile()) { |
49 // Request succeeded, try to convert it to an image. | 50 // Request succeeded, try to convert it to an image. |
50 bitmaps = ImageDecoder::DecodeAll( | 51 bitmaps = ImageDecoder::DecodeAll( |
51 reinterpret_cast<const unsigned char*>(data.data()), data.size()); | 52 reinterpret_cast<const unsigned char*>(data.data()), data.size()); |
52 } | 53 } |
53 } // else case: | 54 } // else case: |
54 // If we get here, it means no image from server or couldn't decode the | 55 // If we get here, it means no image from server or couldn't decode the |
55 // response as an image. The delegate will see an empty vector. | 56 // response as an image. The delegate will see an empty vector. |
56 | 57 |
57 // Take a reference to the callback as running the callback may lead to our | 58 // Take a reference to the callback as running the callback may lead to our |
58 // destruction. | 59 // destruction. |
59 Callback callback = callback_; | 60 Callback callback = callback_; |
60 callback.Run(this, bitmaps); | 61 callback.Run(this, bitmaps); |
61 } | 62 } |
62 | 63 |
63 } // namespace content | 64 } // namespace content |
OLD | NEW |