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

Side by Side Diff: chrome/browser/bitmap_fetcher/bitmap_batch_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 couple more build issues Created 5 years, 10 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/bitmap_fetcher/bitmap_batch_fetcher.h"
6
7 #include "content/public/browser/browser_thread.h"
8 #include "net/url_request/url_fetcher.h"
9 #include "net/url_request/url_request_context_getter.h"
10 #include "net/url_request/url_request_status.h"
11
12 namespace chrome {
13
14 BitmapBatchFetcher::BitmapBatchFetcher() {
15 image_batch_decoder_ =
16 new ImageBatchDecoder(
17 content::BrowserThread::GetMessageLoopProxyForThread(
18 content::BrowserThread::UI));
19 }
20
21 BitmapBatchFetcher::~BitmapBatchFetcher() {
22 }
23
24 void BitmapBatchFetcher::Start(net::URLRequestContextGetter* request_context,
25 const std::string& referrer,
26 net::URLRequest::ReferrerPolicy referrer_policy,
27 int load_flags,
28 const GURL& url,
29 BitmapFetcherDelegate* delegate) {
30 net::URLFetcher* url_fetcher =
31 net::URLFetcher::Create(url, net::URLFetcher::GET, this);
32 url_fetcher_map_[url_fetcher] =
33 std::pair<GURL, BitmapFetcherDelegate*>(url, delegate);
34
35 url_fetcher->SetRequestContext(request_context);
36 url_fetcher->SetReferrer(referrer);
37 url_fetcher->SetReferrerPolicy(referrer_policy);
38 url_fetcher->SetLoadFlags(load_flags);
39 url_fetcher->Start();
40 }
41
42 // Methods inherited from URLFetcherDelegate.
43
44 void BitmapBatchFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
45 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
46
47 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS) {
48 url_fetcher_map_[source].second->OnFetchComplete(
49 url_fetcher_map_[source].first, NULL);
50 return;
51 }
52
53 std::string image_data;
54 source->GetResponseAsString(&image_data);
55 // Call start to begin decoding. The ImageBatchDecoder will call
56 // OnImageDecoded with the data when it is done.
57 scoped_refptr<base::MessageLoopProxy> task_runner =
58 content::BrowserThread::GetMessageLoopProxyForThread(
59 content::BrowserThread::UI);
60 image_batch_decoder_->Start(
61 new BitmapBatchFetcher::Delegate(url_fetcher_map_[source].first,
62 url_fetcher_map_[source].second),
63 image_data,
64 ImageBatchDecoder::DEFAULT_CODEC);
65 }
66
67 void BitmapBatchFetcher::OnURLFetchDownloadProgress(
68 const net::URLFetcher* source,
69 int64 current,
70 int64 total) {
71 // Do nothing here.
72 }
73
74 // Methods inherited from ImageBatchDecoder::Delegate.
75
76 void BitmapBatchFetcher::Delegate::OnImageDecoded(
77 const ImageBatchDecoder* decoder,
78 const SkBitmap& decoded_image) {
79 // Report success.
80 delegate_->OnFetchComplete(url_, &decoded_image);
81 }
82
83 void BitmapBatchFetcher::Delegate::OnDecodeImageFailed(
84 const ImageBatchDecoder* decoder) {
85 delegate_->OnFetchComplete(url_, NULL);
86 }
87
88 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698