Add ICU message format support
[chromium-blink-merge.git] / chrome / browser / bitmap_fetcher / bitmap_fetcher.cc
blobf379cff5f4f30ce0d26fbdceff32ca84f496bdb2
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
3 // found in the LICENSE file.
5 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
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"
12 namespace chrome {
14 BitmapFetcher::BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate)
15 : url_(url),
16 delegate_(delegate) {
19 BitmapFetcher::~BitmapFetcher() {
22 void BitmapFetcher::Init(net::URLRequestContextGetter* request_context,
23 const std::string& referrer,
24 net::URLRequest::ReferrerPolicy referrer_policy,
25 int load_flags) {
26 if (url_fetcher_ != NULL)
27 return;
29 url_fetcher_ = net::URLFetcher::Create(url_, net::URLFetcher::GET, this);
30 url_fetcher_->SetRequestContext(request_context);
31 url_fetcher_->SetReferrer(referrer);
32 url_fetcher_->SetReferrerPolicy(referrer_policy);
33 url_fetcher_->SetLoadFlags(load_flags);
36 void BitmapFetcher::Start() {
37 if (url_fetcher_)
38 url_fetcher_->Start();
41 // Methods inherited from URLFetcherDelegate.
43 void BitmapFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
46 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS) {
47 ReportFailure();
48 return;
51 std::string image_data;
52 source->GetResponseAsString(&image_data);
54 // Call start to begin decoding. The ImageDecoder will call OnImageDecoded
55 // with the data when it is done.
56 ImageDecoder::Start(this, image_data);
59 void BitmapFetcher::OnURLFetchDownloadProgress(const net::URLFetcher* source,
60 int64 current,
61 int64 total) {
62 // Do nothing here.
65 // Methods inherited from ImageDecoder::ImageRequest.
67 void BitmapFetcher::OnImageDecoded(const SkBitmap& decoded_image) {
68 // Report success.
69 delegate_->OnFetchComplete(url_, &decoded_image);
72 void BitmapFetcher::OnDecodeImageFailed() {
73 ReportFailure();
76 void BitmapFetcher::ReportFailure() {
77 delegate_->OnFetchComplete(url_, NULL);
80 } // namespace chrome