OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher .h" | 5 #include "chrome/browser/bitmap_fetcher.h" |
6 | 6 |
7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
9 #include "net/url_request/url_fetcher.h" | 9 #include "net/url_request/url_fetcher.h" |
10 #include "net/url_request/url_request_status.h" | 10 #include "net/url_request/url_request_status.h" |
11 | 11 |
12 namespace notifier { | 12 BitmapFetcher::BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate) |
13 | |
14 NotificationBitmapFetcher::NotificationBitmapFetcher( | |
15 const GURL& url, | |
16 NotificationBitmapFetcherDelegate* delegate) | |
17 : url_(url), delegate_(delegate) {} | 13 : url_(url), delegate_(delegate) {} |
18 | 14 |
19 NotificationBitmapFetcher::~NotificationBitmapFetcher() {} | 15 BitmapFetcher::~BitmapFetcher() {} |
20 | 16 |
21 void NotificationBitmapFetcher::Start(Profile* profile) { | 17 void BitmapFetcher::Start(Profile* profile) { |
22 url_fetcher_.reset( | 18 url_fetcher_.reset(net::URLFetcher::Create(url_, net::URLFetcher::GET, this)); |
23 net::URLFetcher::Create(url_, net::URLFetcher::GET, this)); | |
24 // The RequestContext is coming from the current profile. | 19 // The RequestContext is coming from the current profile. |
25 // TODO(petewil): Make sure this is the right profile to use. | 20 // TODO(petewil): Make sure this is the right profile to use. |
26 // It seems to work, but we might prefer to use a blank profile with | 21 // It seems to work, but we might prefer to use a blank profile with |
27 // no cookies. | 22 // no cookies. |
28 url_fetcher_->SetRequestContext(profile->GetRequestContext()); | 23 url_fetcher_->SetRequestContext(profile->GetRequestContext()); |
29 url_fetcher_->Start(); | 24 url_fetcher_->Start(); |
30 } | 25 } |
31 | 26 |
32 // Methods inherited from URLFetcherDelegate. | 27 // Methods inherited from URLFetcherDelegate. |
33 | 28 |
34 void NotificationBitmapFetcher::OnURLFetchComplete( | 29 void BitmapFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
Pete Williamson
2014/02/11 03:41:11
One thing that I never finished investigating that
gone
2014/02/11 05:32:07
Should be handled since functions like URLFetcherC
| |
35 const net::URLFetcher* source) { | |
36 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 30 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
37 | 31 |
38 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS) { | 32 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS) { |
39 OnDecodeImageFailed(NULL); | 33 OnDecodeImageFailed(NULL); |
40 return; | 34 return; |
41 } | 35 } |
42 | 36 |
43 std::string image_data; | 37 std::string image_data; |
44 source->GetResponseAsString(&image_data); | 38 source->GetResponseAsString(&image_data); |
45 // Create an ImageDecoder with the data and assign it to the refptr. | 39 // Create an ImageDecoder with the data and assign it to the refptr. |
46 image_decoder_ = new ImageDecoder(this, image_data, | 40 image_decoder_ = |
47 ImageDecoder::DEFAULT_CODEC); | 41 new ImageDecoder(this, image_data, ImageDecoder::DEFAULT_CODEC); |
48 | 42 |
49 // Call start to begin decoding. The ImageDecoder will call OnImageDecoded | 43 // Call start to begin decoding. The ImageDecoder will call OnImageDecoded |
50 // with the data when it is done. | 44 // with the data when it is done. |
51 scoped_refptr<base::MessageLoopProxy> task_runner = | 45 scoped_refptr<base::MessageLoopProxy> task_runner = |
52 content::BrowserThread::GetMessageLoopProxyForThread( | 46 content::BrowserThread::GetMessageLoopProxyForThread( |
53 content::BrowserThread::UI); | 47 content::BrowserThread::UI); |
54 image_decoder_->Start(task_runner); | 48 image_decoder_->Start(task_runner); |
55 } | 49 } |
56 | 50 |
57 void NotificationBitmapFetcher::OnURLFetchDownloadProgress( | 51 void BitmapFetcher::OnURLFetchDownloadProgress(const net::URLFetcher* source, |
58 const net::URLFetcher* source, int64 current, int64 total) { | 52 int64 current, |
53 int64 total) { | |
59 // Do nothing here. | 54 // Do nothing here. |
60 } | 55 } |
61 | 56 |
62 // Methods inherited from ImageDecoder::Delegate. | 57 // Methods inherited from ImageDecoder::Delegate. |
63 | 58 |
64 void NotificationBitmapFetcher::OnImageDecoded( | 59 void BitmapFetcher::OnImageDecoded(const ImageDecoder* decoder, |
65 const ImageDecoder* decoder, const SkBitmap& decoded_image) { | 60 const SkBitmap& decoded_image) { |
66 // Make a copy of the bitmap which we pass back to the UI thread. | 61 // Make a copy of the bitmap which we pass back to the UI thread. |
67 bitmap_.reset(new SkBitmap()); | 62 bitmap_.reset(new SkBitmap()); |
68 decoded_image.deepCopyTo(bitmap_.get(), decoded_image.getConfig()); | 63 decoded_image.deepCopyTo(bitmap_.get(), decoded_image.getConfig()); |
69 | 64 |
70 // Report success. | 65 // Report success. |
71 delegate_->OnFetchComplete(url_, bitmap_.get()); | 66 delegate_->OnFetchComplete(url_, bitmap_.get()); |
72 } | 67 } |
73 | 68 |
74 void NotificationBitmapFetcher::OnDecodeImageFailed( | 69 void BitmapFetcher::OnDecodeImageFailed(const ImageDecoder* decoder) { |
75 const ImageDecoder* decoder) { | |
76 | |
77 // Report failure. | 70 // Report failure. |
78 delegate_->OnFetchComplete(url_, NULL); | 71 delegate_->OnFetchComplete(url_, NULL); |
79 } | 72 } |
80 | |
81 } // namespace notifier | |
OLD | NEW |