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

Side by Side Diff: chrome/browser/bitmap_fetcher/bitmap_fetcher.cc

Issue 931993002: Make image_decoder a Leaky LazyInstance (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a few comments Created 5 years, 9 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 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"
11 11
12 namespace chrome { 12 namespace chrome {
13 13
14 BitmapFetcher::BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate) 14 BitmapFetcher::BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate)
15 : url_(url), delegate_(delegate) { 15 : ImageRequest(content::BrowserThread::GetMessageLoopProxyForThread(
16 content::BrowserThread::UI)),
17 url_(url),
18 delegate_(delegate) {
16 } 19 }
17 20
18 BitmapFetcher::~BitmapFetcher() { 21 BitmapFetcher::~BitmapFetcher() {
19 } 22 }
20 23
21 void BitmapFetcher::Start(net::URLRequestContextGetter* request_context, 24 void BitmapFetcher::Start(net::URLRequestContextGetter* request_context,
22 const std::string& referrer, 25 const std::string& referrer,
23 net::URLRequest::ReferrerPolicy referrer_policy, 26 net::URLRequest::ReferrerPolicy referrer_policy,
24 int load_flags) { 27 int load_flags) {
25 if (url_fetcher_ != NULL) 28 if (url_fetcher_ != NULL)
(...skipping 12 matching lines...) Expand all
38 void BitmapFetcher::OnURLFetchComplete(const net::URLFetcher* source) { 41 void BitmapFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
39 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 42 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
40 43
41 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS) { 44 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS) {
42 ReportFailure(); 45 ReportFailure();
43 return; 46 return;
44 } 47 }
45 48
46 std::string image_data; 49 std::string image_data;
47 source->GetResponseAsString(&image_data); 50 source->GetResponseAsString(&image_data);
48 image_decoder_ =
49 new ImageDecoder(this, image_data, ImageDecoder::DEFAULT_CODEC);
50 51
51 // Call start to begin decoding. The ImageDecoder will call OnImageDecoded 52 // Call start to begin decoding. The ImageDecoder will call OnImageDecoded
52 // with the data when it is done. 53 // with the data when it is done.
53 scoped_refptr<base::MessageLoopProxy> task_runner = 54 ImageDecoder::Start(this, image_data);
54 content::BrowserThread::GetMessageLoopProxyForThread(
55 content::BrowserThread::UI);
56 image_decoder_->Start(task_runner);
57 } 55 }
58 56
59 void BitmapFetcher::OnURLFetchDownloadProgress(const net::URLFetcher* source, 57 void BitmapFetcher::OnURLFetchDownloadProgress(const net::URLFetcher* source,
60 int64 current, 58 int64 current,
61 int64 total) { 59 int64 total) {
62 // Do nothing here. 60 // Do nothing here.
63 } 61 }
64 62
65 // Methods inherited from ImageDecoder::Delegate. 63 // Methods inherited from ImageDecoder::ImageRequest.
66 64
67 void BitmapFetcher::OnImageDecoded(const ImageDecoder* decoder, 65 void BitmapFetcher::OnImageDecoded(const SkBitmap& decoded_image) {
68 const SkBitmap& decoded_image) {
69 // Report success. 66 // Report success.
70 delegate_->OnFetchComplete(url_, &decoded_image); 67 delegate_->OnFetchComplete(url_, &decoded_image);
71 } 68 }
72 69
73 void BitmapFetcher::OnDecodeImageFailed(const ImageDecoder* decoder) { 70 void BitmapFetcher::OnDecodeImageFailed() {
74 ReportFailure(); 71 ReportFailure();
75 } 72 }
76 73
77 void BitmapFetcher::ReportFailure() { 74 void BitmapFetcher::ReportFailure() {
78 delegate_->OnFetchComplete(url_, NULL); 75 delegate_->OnFetchComplete(url_, NULL);
79 } 76 }
80 77
81 } // namespace chrome 78 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/bitmap_fetcher/bitmap_fetcher.h ('k') | chrome/browser/bitmap_fetcher/bitmap_fetcher_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698