| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/child/notifications/notification_image_loader.h" | 5 #include "content/child/notifications/notification_image_loader.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/child/child_thread_impl.h" | 8 #include "content/child/child_thread_impl.h" |
| 9 #include "content/child/image_decoder.h" | 9 #include "content/child/image_decoder.h" |
| 10 #include "content/child/worker_task_runner.h" | |
| 11 #include "third_party/WebKit/public/platform/Platform.h" | 10 #include "third_party/WebKit/public/platform/Platform.h" |
| 12 #include "third_party/WebKit/public/platform/WebURL.h" | 11 #include "third_party/WebKit/public/platform/WebURL.h" |
| 13 #include "third_party/WebKit/public/platform/WebURLLoader.h" | 12 #include "third_party/WebKit/public/platform/WebURLLoader.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 | 14 |
| 16 using blink::WebURL; | 15 using blink::WebURL; |
| 17 using blink::WebURLError; | 16 using blink::WebURLError; |
| 18 using blink::WebURLLoader; | 17 using blink::WebURLLoader; |
| 19 using blink::WebURLRequest; | 18 using blink::WebURLRequest; |
| 20 | 19 |
| 21 namespace content { | 20 namespace content { |
| 22 | 21 |
| 23 NotificationImageLoader::NotificationImageLoader( | 22 NotificationImageLoader::NotificationImageLoader( |
| 24 const NotificationImageLoadedCallback& callback) | 23 const NotificationImageLoadedCallback& callback) |
| 25 : callback_(callback), | 24 : callback_(callback), |
| 26 completed_(false) {} | 25 completed_(false) {} |
| 27 | 26 |
| 28 NotificationImageLoader::~NotificationImageLoader() {} | 27 NotificationImageLoader::~NotificationImageLoader() {} |
| 29 | 28 |
| 30 void NotificationImageLoader::StartOnMainThread(const WebURL& image_url, | 29 void NotificationImageLoader::StartOnMainThread( |
| 31 int worker_thread_id) { | 30 const WebURL& image_url, |
| 31 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner) { |
| 32 DCHECK(ChildThreadImpl::current()); | 32 DCHECK(ChildThreadImpl::current()); |
| 33 DCHECK(!url_loader_); | 33 DCHECK(!url_loader_); |
| 34 DCHECK(worker_task_runner); |
| 34 | 35 |
| 35 worker_thread_id_ = worker_thread_id; | 36 worker_task_runner_ = worker_task_runner; |
| 36 | 37 |
| 37 WebURLRequest request(image_url); | 38 WebURLRequest request(image_url); |
| 38 request.setRequestContext(WebURLRequest::RequestContextImage); | 39 request.setRequestContext(WebURLRequest::RequestContextImage); |
| 39 | 40 |
| 40 url_loader_.reset(blink::Platform::current()->createURLLoader()); | 41 url_loader_.reset(blink::Platform::current()->createURLLoader()); |
| 41 url_loader_->loadAsynchronously(request, this); | 42 url_loader_->loadAsynchronously(request, this); |
| 42 } | 43 } |
| 43 | 44 |
| 44 SkBitmap NotificationImageLoader::GetDecodedImage() const { | 45 SkBitmap NotificationImageLoader::GetDecodedImage() const { |
| 45 if (buffer_.empty()) | 46 if (buffer_.empty()) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 72 void NotificationImageLoader::didFail(WebURLLoader* loader, | 73 void NotificationImageLoader::didFail(WebURLLoader* loader, |
| 73 const WebURLError& error) { | 74 const WebURLError& error) { |
| 74 if (completed_) | 75 if (completed_) |
| 75 return; | 76 return; |
| 76 | 77 |
| 77 RunCallbackOnWorkerThread(); | 78 RunCallbackOnWorkerThread(); |
| 78 } | 79 } |
| 79 | 80 |
| 80 void NotificationImageLoader::RunCallbackOnWorkerThread() { | 81 void NotificationImageLoader::RunCallbackOnWorkerThread() { |
| 81 scoped_refptr<NotificationImageLoader> loader = make_scoped_refptr(this); | 82 scoped_refptr<NotificationImageLoader> loader = make_scoped_refptr(this); |
| 82 if (!worker_thread_id_) { | 83 if (worker_task_runner_->BelongsToCurrentThread()) |
| 83 callback_.Run(loader); | 84 callback_.Run(loader); |
| 84 return; | 85 else |
| 85 } | 86 worker_task_runner_->PostTask(FROM_HERE, base::Bind(callback_, loader)); |
| 86 | |
| 87 WorkerTaskRunner::Instance()->PostTask( | |
| 88 worker_thread_id_, | |
| 89 base::Bind(callback_, loader)); | |
| 90 } | 87 } |
| 91 | 88 |
| 92 } // namespace content | 89 } // namespace content |
| OLD | NEW |