Index: content/child/notifications/notification_image_loader.cc |
diff --git a/content/child/notifications/notification_image_loader.cc b/content/child/notifications/notification_image_loader.cc |
index 009f04ce4348303c3eefdfc0afbd2ea174184903..c97d4a9bee2f4d4d5dc2767227df05a8e946d2c5 100644 |
--- a/content/child/notifications/notification_image_loader.cc |
+++ b/content/child/notifications/notification_image_loader.cc |
@@ -11,6 +11,7 @@ |
#include "third_party/WebKit/public/platform/Platform.h" |
#include "third_party/WebKit/public/platform/WebURL.h" |
#include "third_party/WebKit/public/platform/WebURLLoader.h" |
+#include "third_party/WebKit/public/platform/WebURLRequest.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
using blink::WebURL; |
@@ -21,8 +22,11 @@ using blink::WebURLRequest; |
namespace content { |
NotificationImageLoader::NotificationImageLoader( |
- const NotificationImageLoadedCallback& callback) |
+ const ImageLoadCompletedCallback& callback, |
+ const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner) |
: callback_(callback), |
+ worker_task_runner_(worker_task_runner), |
+ notification_id_(0), |
completed_(false) {} |
NotificationImageLoader::~NotificationImageLoader() { |
@@ -32,31 +36,22 @@ NotificationImageLoader::~NotificationImageLoader() { |
main_thread_task_runner_->DeleteSoon(FROM_HERE, url_loader_.release()); |
} |
-void NotificationImageLoader::StartOnMainThread( |
- const WebURL& image_url, |
- const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner) { |
+void NotificationImageLoader::StartOnMainThread(int notification_id, |
+ const GURL& image_url) { |
DCHECK(ChildThreadImpl::current()); |
DCHECK(!url_loader_); |
- DCHECK(worker_task_runner); |
mlamouri (slow - plz ping)
2015/02/18 14:53:58
Would it make sense to have:
DCHECK(!worker_task_r
Peter Beverloo
2015/02/18 15:11:50
No, because it's possible for the worker_task_runn
|
- worker_task_runner_ = worker_task_runner; |
main_thread_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
+ notification_id_ = notification_id; |
- WebURLRequest request(image_url); |
+ WebURL imageUrl(image_url); |
mlamouri (slow - plz ping)
2015/02/18 14:53:58
nit: coding style.
Peter Beverloo
2015/02/18 15:11:50
Done.
|
+ WebURLRequest request(imageUrl); |
request.setRequestContext(WebURLRequest::RequestContextImage); |
url_loader_.reset(blink::Platform::current()->createURLLoader()); |
url_loader_->loadAsynchronously(request, this); |
} |
-SkBitmap NotificationImageLoader::GetDecodedImage() const { |
- if (buffer_.empty()) |
- return SkBitmap(); |
- |
- ImageDecoder decoder; |
- return decoder.Decode(&buffer_[0], buffer_.size()); |
-} |
- |
void NotificationImageLoader::didReceiveData( |
WebURLLoader* loader, |
const char* data, |
@@ -86,11 +81,21 @@ void NotificationImageLoader::didFail(WebURLLoader* loader, |
} |
void NotificationImageLoader::RunCallbackOnWorkerThread() { |
- scoped_refptr<NotificationImageLoader> loader = make_scoped_refptr(this); |
- if (worker_task_runner_->BelongsToCurrentThread()) |
- callback_.Run(loader); |
- else |
- worker_task_runner_->PostTask(FROM_HERE, base::Bind(callback_, loader)); |
+ SkBitmap icon; |
+ if (!buffer_.empty()) { |
+ ImageDecoder decoder; |
+ icon = decoder.Decode(&buffer_[0], buffer_.size()); |
+ } |
mlamouri (slow - plz ping)
2015/02/18 14:53:58
What was wrong with GetDecodedImage? Maybe you cou
mlamouri (slow - plz ping)
2015/02/18 14:53:58
What was wrong with GetDecodedImage? Maybe you cou
Peter Beverloo
2015/02/18 15:11:50
Nothing. Restored.
|
+ |
+ url_loader_.reset(); |
+ completed_ = true; |
+ |
+ if (worker_task_runner_->BelongsToCurrentThread()) { |
+ callback_.Run(notification_id_, icon); |
+ } else { |
+ worker_task_runner_->PostTask( |
+ FROM_HERE, base::Bind(callback_, notification_id_, icon)); |
+ } |
} |
} // namespace content |