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

Side by Side Diff: chrome/browser/notifications/sync_notifier/notification_bitmap_fetcher.cc

Issue 15295018: Continue bitmap fetching for notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Synced Notification Bitmap Fetching - more DCheng feedback, change TestURLFetcher to FakeURLFetcher… Created 7 years, 6 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
OLDNEW
(Empty)
1 // Copyright (c) 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/notifications/sync_notifier/notification_bitmap_fetcher .h"
6
7 #include "content/public/browser/browser_thread.h"
8 #include "net/url_request/url_fetcher.h"
9
10 namespace notifier {
11
12 NotificationBitmapFetcher::NotificationBitmapFetcher(
13 const GURL& url,
14 NotificationBitmapFetcherDelegate* delegate)
15 : url_(url), delegate_(delegate) {}
16
17 NotificationBitmapFetcher::~NotificationBitmapFetcher() {}
18
19 void NotificationBitmapFetcher::Start() {
20 if (url_fetcher_ == NULL)
dcheng 2013/05/30 22:38:09 Style nit: Use {}s since the statement takes multi
Pete Williamson 2013/05/31 00:17:39 Done.
21 url_fetcher_.reset(
22 net::URLFetcher::Create(url_, net::URLFetcher::GET, this));
23 url_fetcher_->Start();
24 }
25
26 void NotificationBitmapFetcher::SetURLFetcherForTest(
27 scoped_ptr<net::URLFetcher> url_fetcher) {
28 url_fetcher_ = url_fetcher.Pass();
29 }
30
31 // Methods inherited from URLFetcherDelegate.
32
33 void NotificationBitmapFetcher::OnURLFetchComplete(
34 const net::URLFetcher* source) {
35 std::string image_data;
36
37 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
38
39 // Copy the data into the string. Keep in mind it may have embedded nulls.
40 source->GetResponseAsString(&image_data);
41
42 // Handle fetch failure. If it failed, set failed to true, and fire
43 // notification to listeners.
44 if (image_data.length() == 0) {
45 OnDecodeImageFailed(NULL);
46 return;
47 }
48
49 // Create an ImageDecoder with the data and assign it to the refptr.
50 image_decoder_ = new ImageDecoder(this, image_data,
51 ImageDecoder::DEFAULT_CODEC);
52
53 // Call start to begin decoding. The ImageDecoder will call OnImageDecoded
54 // with the data when it is done.
55 scoped_refptr<base::MessageLoopProxy> task_runner =
56 content::BrowserThread::GetMessageLoopProxyForThread(
57 content::BrowserThread::UI);
58 image_decoder_->Start(task_runner);
59 }
60
61 void NotificationBitmapFetcher::OnURLFetchDownloadProgress(
62 const net::URLFetcher* source, int64 current, int64 total) {
63 // Do nothing here.
64 }
65
66 // Methods inherited from ImageDecoder::Delegate.
67
68 void NotificationBitmapFetcher::OnImageDecoded(
69 const ImageDecoder* decoder, const SkBitmap& decoded_image) {
70 // Make a copy of the bitmap which we pass back to the UI thread.
71 bitmap_.reset(new SkBitmap());
72 decoded_image.deepCopyTo(bitmap_.get(), decoded_image.getConfig());
73
74 // Report success.
75 delegate_->OnFetchComplete(bitmap_.get());
76 }
77
78 void NotificationBitmapFetcher::OnDecodeImageFailed(
79 const ImageDecoder* decoder) {
80
81 // Report failure.
82 delegate_->OnFetchComplete(NULL);
83 }
84
85 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698