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

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: Rename instance_ to image_decoder_instance_ for mac linker 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"
(...skipping 27 matching lines...) Expand all
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,
53 image_data,
54 ImageDecoder::DEFAULT_CODEC,
54 content::BrowserThread::GetMessageLoopProxyForThread( 55 content::BrowserThread::GetMessageLoopProxyForThread(
55 content::BrowserThread::UI); 56 content::BrowserThread::UI));
56 image_decoder_->Start(task_runner);
57 } 57 }
58 58
59 void BitmapFetcher::OnURLFetchDownloadProgress(const net::URLFetcher* source, 59 void BitmapFetcher::OnURLFetchDownloadProgress(const net::URLFetcher* source,
60 int64 current, 60 int64 current,
61 int64 total) { 61 int64 total) {
62 // Do nothing here. 62 // Do nothing here.
63 } 63 }
64 64
65 // Methods inherited from ImageDecoder::Delegate. 65 // Methods inherited from ImageDecoder::Delegate.
66 66
67 void BitmapFetcher::OnImageDecoded(const ImageDecoder* decoder, 67 void BitmapFetcher::OnImageDecoded(const SkBitmap& decoded_image) {
68 const SkBitmap& decoded_image) {
69 // Report success. 68 // Report success.
70 delegate_->OnFetchComplete(url_, &decoded_image); 69 delegate_->OnFetchComplete(url_, &decoded_image);
71 } 70 }
72 71
73 void BitmapFetcher::OnDecodeImageFailed(const ImageDecoder* decoder) { 72 void BitmapFetcher::OnDecodeImageFailed() {
74 ReportFailure(); 73 ReportFailure();
75 } 74 }
76 75
77 void BitmapFetcher::ReportFailure() { 76 void BitmapFetcher::ReportFailure() {
78 delegate_->OnFetchComplete(url_, NULL); 77 delegate_->OnFetchComplete(url_, NULL);
79 } 78 }
80 79
81 } // namespace chrome 80 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698