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

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 - refactor to use delegates instead of notifications Created 7 years, 7 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 "chrome/common/chrome_notification_types.h"
dcheng 2013/05/28 20:11:34 Nit: None of the content notification headers are
Pete Williamson 2013/05/29 18:05:00 Done.
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/notification_details.h"
10 #include "content/public/browser/notification_service.h"
11 #include "net/url_request/url_fetcher.h"
12
13 namespace notifier {
14
15 NotificationBitmapFetcher::NotificationBitmapFetcher(
16 const GURL& url,
17 NotificationBitmapFetcherDelegate* delegate)
18 : url_(url), delegate_(delegate), image_ready_(false) {}
19
20 NotificationBitmapFetcher::~NotificationBitmapFetcher() {}
21
22 void NotificationBitmapFetcher::StartImageFetch() {
23 if (url_fetcher_ == NULL)
24 url_fetcher_.reset(
25 net::URLFetcher::Create(url_, net::URLFetcher::GET, this));
26 url_fetcher_->Start();
27 }
28
29 void NotificationBitmapFetcher::SetURLFetcherForTest(
30 scoped_ptr<net::URLFetcher>& url_fetcher) {
31 url_fetcher_ = url_fetcher.Pass();
32 }
33
34 // Methods inherited from URLFetcherDelegate.
35
36 void NotificationBitmapFetcher::OnURLFetchComplete(
37 const net::URLFetcher* source) {
38 std::string image_data;
39
40 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
41
42 // Copy the data into the string. Keep in mind it may have embedded nulls.
43 source->GetResponseAsString(&image_data);
44
45 // Handle fetch failure. If it failed, set failed to true, and fire
46 // notification to listeners.
47 if (image_data.length() == 0) {
48 OnDecodeImageFailed(NULL);
49 }
50
51 // Create an ImageDecoder with the data and assign it to the refptr.
52 image_decoder_ = new ImageDecoder(this, image_data,
53 ImageDecoder::DEFAULT_CODEC);
54
55 // Call start to begin decoding. The ImageDecoder will call OnImageDecoded
56 // with the data when it is done.
57 scoped_refptr<base::MessageLoopProxy> task_runner =
58 content::BrowserThread::GetMessageLoopProxyForThread(
59 content::BrowserThread::UI);
60 image_decoder_->Start(task_runner);
61 }
62
63 void NotificationBitmapFetcher::OnURLFetchDownloadProgress(
64 const net::URLFetcher* source, int64 current, int64 total) {
65 // Do nothing here.
66 }
67
68 // Methods inherited from ImageDecoder::Delegate.
69
70 // This comes in on another thread, so we send the bitmap back to the UI
71 // thread so that the object stays thread safe.
72 void NotificationBitmapFetcher::OnImageDecoded(
73 const ImageDecoder* decoder, const SkBitmap& decoded_image) {
74 // Make a copy of the bitmap which we pass back to the UI thread.
75 bitmap_.reset(new SkBitmap());
dcheng 2013/05/28 20:11:34 Is it still necessary to make a copy of the bitmap
Pete Williamson 2013/05/29 18:05:00 I think so. I don't know that ImageDecoder provid
dcheng 2013/05/29 20:40:29 Can we just use SkBitmap's operator=?
Pete Williamson 2013/05/30 00:13:18 I tried this without the additional call to deep c
dcheng 2013/05/30 00:38:14 I see. I misinterpreted the comment (which remarks
76 decoded_image.deepCopyTo(bitmap_.get(), decoded_image.getConfig());
77 image_ready_ = true;
78
79 // Report success.
80 delegate_->OnFetchComplete(image_ready_, bitmap_.get());
dcheng 2013/05/28 20:11:34 Rather than using image_ready_, is it possible to
Pete Williamson 2013/05/29 18:05:00 Done (using NULL)
81 }
82
83 void NotificationBitmapFetcher::OnDecodeImageFailed(
84 const ImageDecoder* decoder) {
85
86 // Report failure.
87 delegate_->OnFetchComplete(image_ready_, NULL);
88 }
89
90 } // namespace notifier
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698