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 namespace chrome { |
13 | 13 |
14 NotificationBitmapFetcher::NotificationBitmapFetcher( | 14 BitmapFetcher::BitmapFetcher(const GURL& url, BitmapFetcherDelegate* delegate) |
15 const GURL& url, | |
16 NotificationBitmapFetcherDelegate* delegate) | |
17 : url_(url), delegate_(delegate) {} | 15 : url_(url), delegate_(delegate) {} |
sky
2014/02/13 18:55:05
nit: since everything doesn't fit on one line, wra
gone
2014/02/13 23:39:38
Done.
| |
18 | 16 |
19 NotificationBitmapFetcher::~NotificationBitmapFetcher() {} | 17 BitmapFetcher::~BitmapFetcher() {} |
20 | 18 |
21 void NotificationBitmapFetcher::Start(Profile* profile) { | 19 void BitmapFetcher::Start(Profile* profile) { |
22 url_fetcher_.reset( | 20 url_fetcher_.reset(net::URLFetcher::Create(url_, net::URLFetcher::GET, this)); |
sky
2014/02/13 18:55:05
I believe the expectation is this is only invoked
gone
2014/02/13 23:39:38
Done.
| |
23 net::URLFetcher::Create(url_, net::URLFetcher::GET, this)); | |
24 // The RequestContext is coming from the current profile. | 21 // The RequestContext is coming from the current profile. |
25 // TODO(petewil): Make sure this is the right profile to use. | 22 // TODO(petewil): Make sure this is the right profile to use. |
sky
2014/02/13 18:55:05
Is this comment still relevant? Seems obvious that
Pete Williamson
2014/02/13 21:30:31
It is OK to remove this comment. The feature is m
gone
2014/02/13 23:39:38
Done.
| |
26 // It seems to work, but we might prefer to use a blank profile with | 23 // It seems to work, but we might prefer to use a blank profile with |
27 // no cookies. | 24 // no cookies. |
28 url_fetcher_->SetRequestContext(profile->GetRequestContext()); | 25 url_fetcher_->SetRequestContext(profile->GetRequestContext()); |
29 url_fetcher_->Start(); | 26 url_fetcher_->Start(); |
30 } | 27 } |
31 | 28 |
32 // Methods inherited from URLFetcherDelegate. | 29 // Methods inherited from URLFetcherDelegate. |
33 | 30 |
34 void NotificationBitmapFetcher::OnURLFetchComplete( | 31 void BitmapFetcher::OnURLFetchComplete(const net::URLFetcher* source) { |
35 const net::URLFetcher* source) { | |
36 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 32 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
37 | 33 |
38 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS) { | 34 if (source->GetStatus().status() != net::URLRequestStatus::SUCCESS) { |
39 OnDecodeImageFailed(NULL); | 35 OnDecodeImageFailed(NULL); |
sky
2014/02/13 18:55:05
Less error prone if OnDecodeImageFailed and this c
gone
2014/02/13 23:39:38
Done.
| |
40 return; | 36 return; |
41 } | 37 } |
42 | 38 |
43 std::string image_data; | 39 std::string image_data; |
44 source->GetResponseAsString(&image_data); | 40 source->GetResponseAsString(&image_data); |
45 // Create an ImageDecoder with the data and assign it to the refptr. | 41 // Create an ImageDecoder with the data and assign it to the refptr. |
sky
2014/02/13 18:55:05
This comment just describes the code and so isn't
gone
2014/02/13 23:39:38
Done.
| |
46 image_decoder_ = new ImageDecoder(this, image_data, | 42 image_decoder_ = |
sky
2014/02/13 18:55:05
I thought we decoded images in the renderer for tw
gone
2014/02/13 19:28:31
Doesn't the ImageDecoder run in a sandboxed proces
Pete Williamson
2014/02/13 21:30:31
By all means check with security.
We do in fact r
gone
2014/02/13 23:39:38
Should be fine, according to a reply later on.
| |
47 ImageDecoder::DEFAULT_CODEC); | 43 new ImageDecoder(this, image_data, ImageDecoder::DEFAULT_CODEC); |
48 | 44 |
49 // Call start to begin decoding. The ImageDecoder will call OnImageDecoded | 45 // Call start to begin decoding. The ImageDecoder will call OnImageDecoded |
50 // with the data when it is done. | 46 // with the data when it is done. |
51 scoped_refptr<base::MessageLoopProxy> task_runner = | 47 scoped_refptr<base::MessageLoopProxy> task_runner = |
52 content::BrowserThread::GetMessageLoopProxyForThread( | 48 content::BrowserThread::GetMessageLoopProxyForThread( |
53 content::BrowserThread::UI); | 49 content::BrowserThread::UI); |
54 image_decoder_->Start(task_runner); | 50 image_decoder_->Start(task_runner); |
55 } | 51 } |
56 | 52 |
57 void NotificationBitmapFetcher::OnURLFetchDownloadProgress( | 53 void BitmapFetcher::OnURLFetchDownloadProgress(const net::URLFetcher* source, |
58 const net::URLFetcher* source, int64 current, int64 total) { | 54 int64 current, |
55 int64 total) { | |
59 // Do nothing here. | 56 // Do nothing here. |
60 } | 57 } |
61 | 58 |
62 // Methods inherited from ImageDecoder::Delegate. | 59 // Methods inherited from ImageDecoder::Delegate. |
63 | 60 |
64 void NotificationBitmapFetcher::OnImageDecoded( | 61 void BitmapFetcher::OnImageDecoded(const ImageDecoder* decoder, |
65 const ImageDecoder* decoder, const SkBitmap& decoded_image) { | 62 const SkBitmap& decoded_image) { |
66 // Make a copy of the bitmap which we pass back to the UI thread. | 63 // Make a copy of the bitmap which we pass back to the UI thread. |
67 bitmap_.reset(new SkBitmap()); | 64 bitmap_.reset(new SkBitmap()); |
68 decoded_image.deepCopyTo(bitmap_.get(), decoded_image.getConfig()); | 65 decoded_image.deepCopyTo(bitmap_.get(), decoded_image.getConfig()); |
69 | 66 |
70 // Report success. | 67 // Report success. |
71 delegate_->OnFetchComplete(url_, bitmap_.get()); | 68 delegate_->OnFetchComplete(url_, bitmap_.get()); |
72 } | 69 } |
73 | 70 |
74 void NotificationBitmapFetcher::OnDecodeImageFailed( | 71 void BitmapFetcher::OnDecodeImageFailed(const ImageDecoder* decoder) { |
75 const ImageDecoder* decoder) { | |
76 | |
77 // Report failure. | 72 // Report failure. |
78 delegate_->OnFetchComplete(url_, NULL); | 73 delegate_->OnFetchComplete(url_, NULL); |
79 } | 74 } |
80 | 75 |
81 } // namespace notifier | 76 } // namespace chrome |
OLD | NEW |