OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bitmap_fetcher/bitmap_fetcher.h" | 5 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h" |
6 | 6 |
7 #include "content/public/browser/browser_thread.h" | 7 #include "content/public/browser/browser_thread.h" |
8 #include "net/url_request/url_fetcher.h" | 8 #include "net/url_request/url_fetcher.h" |
9 #include "net/url_request/url_request_context_getter.h" | 9 #include "net/url_request/url_request_context_getter.h" |
10 #include "net/url_request/url_request_status.h" | 10 #include "net/url_request/url_request_status.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 void BitmapFetcher::OnURLFetchComplete(const net::URLFetcher* source) { | 38 void BitmapFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
40 | 40 |
41 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS) { | 41 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS) { |
42 ReportFailure(); | 42 ReportFailure(); |
43 return; | 43 return; |
44 } | 44 } |
45 | 45 |
46 std::string image_data; | 46 std::string image_data; |
47 source->GetResponseAsString(&image_data); | 47 source->GetResponseAsString(&image_data); |
48 image_decoder_ = | |
49 new ImageDecoder(this, image_data, ImageDecoder::DEFAULT_CODEC); | |
50 | 48 |
51 // Call start to begin decoding. The ImageDecoder will call OnImageDecoded | 49 // Call start to begin decoding. The ImageDecoder will call OnImageDecoded |
52 // with the data when it is done. | 50 // with the data when it is done. |
53 scoped_refptr<base::MessageLoopProxy> task_runner = | 51 ImageDecoder::GetInstance()->Start( |
| 52 this, image_data, ImageDecoder::DEFAULT_CODEC, |
54 content::BrowserThread::GetMessageLoopProxyForThread( | 53 content::BrowserThread::GetMessageLoopProxyForThread( |
55 content::BrowserThread::UI); | 54 content::BrowserThread::UI), |
56 image_decoder_->Start(task_runner); | 55 false); |
57 } | 56 } |
58 | 57 |
59 void BitmapFetcher::OnURLFetchDownloadProgress(const net::URLFetcher* source, | 58 void BitmapFetcher::OnURLFetchDownloadProgress(const net::URLFetcher* source, |
60 int64 current, | 59 int64 current, |
61 int64 total) { | 60 int64 total) { |
62 // Do nothing here. | 61 // Do nothing here. |
63 } | 62 } |
64 | 63 |
65 // Methods inherited from ImageDecoder::Delegate. | 64 // Methods inherited from ImageDecoder::Delegate. |
66 | 65 |
67 void BitmapFetcher::OnImageDecoded(const ImageDecoder* decoder, | 66 void BitmapFetcher::OnImageDecoded(const SkBitmap& decoded_image) { |
68 const SkBitmap& decoded_image) { | |
69 // Report success. | 67 // Report success. |
70 delegate_->OnFetchComplete(url_, &decoded_image); | 68 delegate_->OnFetchComplete(url_, &decoded_image); |
71 } | 69 } |
72 | 70 |
73 void BitmapFetcher::OnDecodeImageFailed(const ImageDecoder* decoder) { | 71 void BitmapFetcher::OnDecodeImageFailed() { |
74 ReportFailure(); | 72 ReportFailure(); |
75 } | 73 } |
76 | 74 |
77 void BitmapFetcher::ReportFailure() { | 75 void BitmapFetcher::ReportFailure() { |
78 delegate_->OnFetchComplete(url_, NULL); | 76 delegate_->OnFetchComplete(url_, NULL); |
79 } | 77 } |
80 | 78 |
81 } // namespace chrome | 79 } // namespace chrome |
OLD | NEW |