notifications: Use standard task-runners to run image loader callbacks.

Instead of using the id of the worker-thread to keep track of the thread to
run the image-loader callbacks on, use the task-runner of the thread instead.

BUG=none
R=mkwst@chromium.org

Review URL: https://codereview.chromium.org/897733002

Cr-Commit-Position: refs/heads/master@{#315109}
parent 6ecf654f
......@@ -7,7 +7,6 @@
#include "base/logging.h"
#include "content/child/child_thread_impl.h"
#include "content/child/image_decoder.h"
#include "content/child/worker_task_runner.h"
#include "third_party/WebKit/public/platform/Platform.h"
#include "third_party/WebKit/public/platform/WebURL.h"
#include "third_party/WebKit/public/platform/WebURLLoader.h"
......@@ -27,12 +26,14 @@ NotificationImageLoader::NotificationImageLoader(
NotificationImageLoader::~NotificationImageLoader() {}
void NotificationImageLoader::StartOnMainThread(const WebURL& image_url,
int worker_thread_id) {
void NotificationImageLoader::StartOnMainThread(
const WebURL& image_url,
const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner) {
DCHECK(ChildThreadImpl::current());
DCHECK(!url_loader_);
DCHECK(worker_task_runner);
worker_thread_id_ = worker_thread_id;
worker_task_runner_ = worker_task_runner;
WebURLRequest request(image_url);
request.setRequestContext(WebURLRequest::RequestContextImage);
......@@ -79,14 +80,10 @@ void NotificationImageLoader::didFail(WebURLLoader* loader,
void NotificationImageLoader::RunCallbackOnWorkerThread() {
scoped_refptr<NotificationImageLoader> loader = make_scoped_refptr(this);
if (!worker_thread_id_) {
if (worker_task_runner_->BelongsToCurrentThread())
callback_.Run(loader);
return;
}
WorkerTaskRunner::Instance()->PostTask(
worker_thread_id_,
base::Bind(callback_, loader));
else
worker_task_runner_->PostTask(FROM_HERE, base::Bind(callback_, loader));
}
} // namespace content
......@@ -14,6 +14,10 @@
class SkBitmap;
namespace base {
class SingleThreadTaskRunner;
}
namespace blink {
class WebURL;
struct WebURLError;
......@@ -41,9 +45,11 @@ class NotificationImageLoader
const NotificationImageLoadedCallback& callback);
// Asynchronously starts loading |image_url|.
// Must be called on the main thread. |worker_thread_id| identifies the id
// of the thread on which the callback should be executed upon completion.
void StartOnMainThread(const blink::WebURL& image_url, int worker_thread_id);
// Must be called on the main thread. The callback should be executed by
// |worker_task_runner|.
void StartOnMainThread(
const blink::WebURL& image_url,
const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner);
// Returns the SkBitmap resulting from decoding the loaded buffer.
SkBitmap GetDecodedImage() const;
......@@ -71,7 +77,7 @@ class NotificationImageLoader
NotificationImageLoadedCallback callback_;
scoped_ptr<blink::WebURLLoader> url_loader_;
int worker_thread_id_;
scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_;
bool completed_;
std::vector<uint8_t> buffer_;
......
......@@ -6,6 +6,7 @@
#include "base/lazy_instance.h"
#include "base/strings/utf_string_conversions.h"
#include "base/thread_task_runner_handle.h"
#include "base/threading/thread_local.h"
#include "content/child/notifications/notification_data_conversions.h"
#include "content/child/notifications/notification_dispatcher.h"
......@@ -212,11 +213,9 @@ scoped_refptr<NotificationImageLoader> NotificationManager::CreateImageLoader(
new NotificationImageLoader(callback));
main_thread_task_runner_->PostTask(
FROM_HERE,
base::Bind(&NotificationImageLoader::StartOnMainThread,
pending_notification,
image_url,
CurrentWorkerId()));
FROM_HERE, base::Bind(&NotificationImageLoader::StartOnMainThread,
pending_notification, image_url,
base::ThreadTaskRunnerHandle::Get()));
return pending_notification;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment