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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/banners/app_banner_icon_fetcher.cc
diff --git a/chrome/browser/android/banners/app_banner_icon_fetcher.cc b/chrome/browser/android/banners/app_banner_icon_fetcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f5e298e5338c5b0f7a4be2efeabcfac89c103889
--- /dev/null
+++ b/chrome/browser/android/banners/app_banner_icon_fetcher.cc
@@ -0,0 +1,71 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/banners/app_banner_icon_fetcher.h"
+
+#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/web_contents.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_request_status.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+AppBannerIconFetcher::AppBannerIconFetcher(Delegate* delegate,
+ content::WebContents* web_contents,
+ const GURL& image_url)
+ : delegate_(delegate),
+ image_url_(image_url) {
+ DCHECK(delegate_);
+ Profile* profile =
+ Profile::FromBrowserContext(web_contents->GetBrowserContext());
+ fetcher_.reset(net::URLFetcher::Create(image_url,
+ net::URLFetcher::GET,
+ this));
+ fetcher_.get()->SetRequestContext(profile->GetRequestContext());
+ fetcher_.get()->Start();
Nico 2014/02/05 05:53:17 http://google-styleguide.googlecode.com/svn/trunk/
+}
+
+AppBannerIconFetcher::~AppBannerIconFetcher() {
+ delegate_ = NULL;
+ fetcher_.reset();
+}
+
+void AppBannerIconFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
+ std::string image_data;
+ if (source->GetURL() != image_url_ ||
+ !source->GetStatus().is_success() ||
+ !source->GetResponseAsString(&image_data)) {
+ AlertDelegateAboutFailure();
+ return;
+ }
+
+ // Begin converting the raw image data into a usable SkBitmap.
+ scoped_refptr<ImageDecoder> image_decoder = new ImageDecoder(
+ this,
+ image_data,
+ ImageDecoder::DEFAULT_CODEC);
Nico 2014/02/05 05:53:17 (`git cl format` formats this as scoped_refptr<
+ scoped_refptr<base::MessageLoopProxy> task_runner =
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::UI);
+ image_decoder->Start(task_runner);
+}
+
+void AppBannerIconFetcher::OnImageDecoded(const ImageDecoder* decoder,
+ const SkBitmap& decoded_image) {
+ if (!delegate_) return;
+
+ if (decoded_image.getSize())
+ delegate_->OnIconFetchSuccessful(image_url_, decoded_image);
+ else
+ AlertDelegateAboutFailure();
+}
+
+void AppBannerIconFetcher::OnDecodeImageFailed(const ImageDecoder* decoder) {
+ AlertDelegateAboutFailure();
+}
+
+void AppBannerIconFetcher::AlertDelegateAboutFailure() {
+ if (delegate_)
+ delegate_->OnIconFetchFailed(image_url_);
+}
« 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