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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/bitmap_fetcher.h ('k') | chrome/browser/bitmap_fetcher_browsertest.cc » ('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 2013 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.h"
6
7 #include "chrome/browser/profiles/profile.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "net/url_request/url_fetcher.h"
10 #include "net/url_request/url_request_status.h"
11
12 namespace chrome {
13
14 BitmapFetcher::BitmapFetcher(const GURL& url,
15 BitmapFetcherDelegate* delegate)
16 : url_(url),
17 delegate_(delegate) {
18 }
19
20 BitmapFetcher::~BitmapFetcher() {}
21
22 void BitmapFetcher::Start(Profile* profile) {
23 DCHECK(url_fetcher_ == NULL);
24 url_fetcher_.reset(net::URLFetcher::Create(url_, net::URLFetcher::GET, this));
25 url_fetcher_->SetRequestContext(profile->GetRequestContext());
26 url_fetcher_->Start();
27 }
28
29 // Methods inherited from URLFetcherDelegate.
30
31 void BitmapFetcher::OnURLFetchComplete(const net::URLFetcher* source) {
32 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
33
34 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS) {
35 ReportFailure();
36 return;
37 }
38
39 std::string image_data;
40 source->GetResponseAsString(&image_data);
41 image_decoder_ =
42 new ImageDecoder(this, image_data, ImageDecoder::DEFAULT_CODEC);
43
44 // Call start to begin decoding. The ImageDecoder will call OnImageDecoded
45 // with the data when it is done.
46 scoped_refptr<base::MessageLoopProxy> task_runner =
47 content::BrowserThread::GetMessageLoopProxyForThread(
48 content::BrowserThread::UI);
49 image_decoder_->Start(task_runner);
50 }
51
52 void BitmapFetcher::OnURLFetchDownloadProgress(const net::URLFetcher* source,
53 int64 current,
54 int64 total) {
55 // Do nothing here.
56 }
57
58 // Methods inherited from ImageDecoder::Delegate.
59
60 void BitmapFetcher::OnImageDecoded(const ImageDecoder* decoder,
61 const SkBitmap& decoded_image) {
62 // Make a copy of the bitmap which we pass back to the UI thread.
63 scoped_ptr<SkBitmap> bitmap(new SkBitmap());
64 decoded_image.deepCopyTo(bitmap.get(), decoded_image.getConfig());
65
66 // Report success.
67 delegate_->OnFetchComplete(url_, bitmap.get());
68 }
69
70 void BitmapFetcher::OnDecodeImageFailed(const ImageDecoder* decoder) {
71 ReportFailure();
72 }
73
74 void BitmapFetcher::ReportFailure() {
75 delegate_->OnFetchComplete(url_, NULL);
76 }
77
78 } // namespace chrome
OLDNEW
« 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