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

Side by Side Diff: chrome/browser/android/banners/app_banner_icon_fetcher.cc

Issue 155273002: Repurpose NotificationBitmapFetcher to BitmapFetcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: indentation Created 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/android/banners/app_banner_icon_fetcher.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/android/banners/app_banner_icon_fetcher.h"
6
7 #include "chrome/browser/profiles/profile.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/web_contents.h"
10 #include "net/url_request/url_fetcher.h"
11 #include "net/url_request/url_request_status.h"
12 #include "third_party/skia/include/core/SkBitmap.h"
13
14 AppBannerIconFetcher::AppBannerIconFetcher(Delegate* delegate,
15 content::WebContents* web_contents,
16 const GURL& image_url)
17 : delegate_(delegate),
18 image_url_(image_url) {
19 DCHECK(delegate_);
20 Profile* profile =
21 Profile::FromBrowserContext(web_contents->GetBrowserContext());
22 fetcher_.reset(net::URLFetcher::Create(image_url,
23 net::URLFetcher::GET,
24 this));
25 fetcher_.get()->SetRequestContext(profile->GetRequestContext());
26 fetcher_.get()->Start();
Nico 2014/02/05 05:53:17 http://google-styleguide.googlecode.com/svn/trunk/
27 }
28
29 AppBannerIconFetcher::~AppBannerIconFetcher() {
30 delegate_ = NULL;
31 fetcher_.reset();
32 }
33
34 void AppBannerIconFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
35 std::string image_data;
36 if (source->GetURL() != image_url_ ||
37 !source->GetStatus().is_success() ||
38 !source->GetResponseAsString(&image_data)) {
39 AlertDelegateAboutFailure();
40 return;
41 }
42
43 // Begin converting the raw image data into a usable SkBitmap.
44 scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder(
45 this,
46 image_data,
47 ImageDecoder::DEFAULT_CODEC);
Nico 2014/02/05 05:53:17 (`git cl format` formats this as scoped_refptr<
48 scoped_refptr<base::MessageLoopProxy> task_runner =
49 content::BrowserThread::GetMessageLoopProxyForThread(
50 content::BrowserThread::UI);
51 image_decoder->Start(task_runner);
52 }
53
54 void AppBannerIconFetcher::OnImageDecoded(const ImageDecoder* decoder,
55 const SkBitmap& decoded_image) {
56 if (!delegate_) return;
57
58 if (decoded_image.getSize())
59 delegate_->OnIconFetchSuccessful(image_url_, decoded_image);
60 else
61 AlertDelegateAboutFailure();
62 }
63
64 void AppBannerIconFetcher::OnDecodeImageFailed(const ImageDecoder* decoder) {
65 AlertDelegateAboutFailure();
66 }
67
68 void AppBannerIconFetcher::AlertDelegateAboutFailure() {
69 if (delegate_)
70 delegate_->OnIconFetchFailed(image_url_);
71 }
OLDNEW
« no previous file with comments | « chrome/browser/android/banners/app_banner_icon_fetcher.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698