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

Unified Diff: chrome/browser/bitmap_fetcher.cc

Issue 155273002: Repurpose NotificationBitmapFetcher to BitmapFetcher (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Appease windows bot 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/bitmap_fetcher.h ('k') | chrome/browser/bitmap_fetcher_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/bitmap_fetcher.cc
diff --git a/chrome/browser/bitmap_fetcher.cc b/chrome/browser/bitmap_fetcher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0591ce4f4c2ac564f31ff20a7ecce3d6e20f97e7
--- /dev/null
+++ b/chrome/browser/bitmap_fetcher.cc
@@ -0,0 +1,78 @@
+// Copyright 2013 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/bitmap_fetcher.h"
+
+#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/browser_thread.h"
+#include "net/url_request/url_fetcher.h"
+#include "net/url_request/url_request_status.h"
+
+namespace chrome {
+
+BitmapFetcher::BitmapFetcher(const GURL& url,
+ BitmapFetcherDelegate* delegate)
+ : url_(url),
+ delegate_(delegate) {
+}
+
+BitmapFetcher::~BitmapFetcher() {}
+
+void BitmapFetcher::Start(Profile* profile) {
+ DCHECK(url_fetcher_ == NULL);
+ url_fetcher_.reset(net::URLFetcher::Create(url_, net::URLFetcher::GET, this));
+ url_fetcher_->SetRequestContext(profile->GetRequestContext());
+ url_fetcher_->Start();
+}
+
+// Methods inherited from URLFetcherDelegate.
+
+void BitmapFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS) {
+ ReportFailure();
+ return;
+ }
+
+ std::string image_data;
+ source->GetResponseAsString(&image_data);
+ image_decoder_ =
+ new ImageDecoder(this, image_data, ImageDecoder::DEFAULT_CODEC);
+
+ // Call start to begin decoding. The ImageDecoder will call OnImageDecoded
+ // with the data when it is done.
+ scoped_refptr<base::MessageLoopProxy> task_runner =
+ content::BrowserThread::GetMessageLoopProxyForThread(
+ content::BrowserThread::UI);
+ image_decoder_->Start(task_runner);
+}
+
+void BitmapFetcher::OnURLFetchDownloadProgress(const net::URLFetcher* source,
+ int64 current,
+ int64 total) {
+ // Do nothing here.
+}
+
+// Methods inherited from ImageDecoder::Delegate.
+
+void BitmapFetcher::OnImageDecoded(const ImageDecoder* decoder,
+ const SkBitmap& decoded_image) {
+ // Make a copy of the bitmap which we pass back to the UI thread.
+ scoped_ptr<SkBitmap> bitmap(new SkBitmap());
+ decoded_image.deepCopyTo(bitmap.get(), decoded_image.getConfig());
+
+ // Report success.
+ delegate_->OnFetchComplete(url_, bitmap.get());
+}
+
+void BitmapFetcher::OnDecodeImageFailed(const ImageDecoder* decoder) {
+ ReportFailure();
+}
+
+void BitmapFetcher::ReportFailure() {
+ delegate_->OnFetchComplete(url_, NULL);
+}
+
+} // namespace chrome
« no previous file with comments | « chrome/browser/bitmap_fetcher.h ('k') | chrome/browser/bitmap_fetcher_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698