Skip to content

Commit

Permalink
Remove MessageLoop::current() from ppapi/proxy.
Browse files Browse the repository at this point in the history
Whenever possible, use ThreadTaskRunnerHandle::Get() instead of
MessageLoop::current(). ThreadTaskRunnerHandle::Get() works within
TaskScheduler while MessageLoop::current() doesn't.

Good reasons to use MessageLoop::current():
- Add destruction, nesting or task observers.
- Run nested loops.

Bad reasons to use MessageLoop::current():
- Post tasks. Use ThreadTaskRunnerHandle::Get() instead.
- Watch a file descriptor. Use FileDescriptorWatcher instead.
- Verify that it is possible to post tasks to the current thread.
  Use ThreadTaskRunnerHandle::IsSet() instead.
- Verify that code runs on a specific thread. Use
  SingleThreadTaskRunner::BelongsToCurrentThread() instead.

BUG=650723

Review-Url: https://codereview.chromium.org/2407393002
Cr-Commit-Position: refs/heads/master@{#424863}
  • Loading branch information
fdoray authored and Commit bot committed Oct 12, 2016
1 parent ef28a21 commit 2111a57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
5 changes: 2 additions & 3 deletions ppapi/proxy/plugin_globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

#include "ppapi/proxy/plugin_globals.h"

#include "base/location.h"
#include "base/macros.h"
#include "base/single_thread_task_runner.h"
#include "base/task_runner.h"
#include "base/threading/thread.h"
#include "base/threading/thread_task_runner_handle.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_sender.h"
#include "ppapi/proxy/plugin_dispatcher.h"
Expand Down Expand Up @@ -189,7 +188,7 @@ base::TaskRunner* PluginGlobals::GetFileTaskRunner() {
void PluginGlobals::MarkPluginIsActive() {
if (!plugin_recently_active_) {
plugin_recently_active_ = true;
if (!GetBrowserSender() || !base::MessageLoop::current())
if (!GetBrowserSender() || !base::ThreadTaskRunnerHandle::IsSet())
return;
GetBrowserSender()->Send(new PpapiHostMsg_Keepalive());
DCHECK(keepalive_throttle_interval_milliseconds_);
Expand Down
24 changes: 6 additions & 18 deletions ppapi/proxy/proxy_completion_callback_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <stdint.h>

#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/sequence_checker.h"
#include "ppapi/cpp/completion_callback.h"
#include "ppapi/utility/completion_callback_factory.h"

Expand All @@ -21,38 +21,26 @@ class ProxyNonThreadSafeThreadTraits {
public:
class RefCount {
public:
RefCount() : ref_(0) {
#ifndef NDEBUG
message_loop_ = base::MessageLoop::current();
#endif
}
RefCount() : ref_(0) {}

~RefCount() {
#ifndef NDEBUG
DCHECK(message_loop_ == base::MessageLoop::current());
#endif
DCHECK(sequence_checker_.CalledOnValidSequence());
}

int32_t AddRef() {
#ifndef NDEBUG
DCHECK(message_loop_ == base::MessageLoop::current());
#endif
DCHECK(sequence_checker_.CalledOnValidSequence());
return ++ref_;
}

int32_t Release() {
#ifndef NDEBUG
DCHECK(message_loop_ == base::MessageLoop::current());
#endif
DCHECK(sequence_checker_.CalledOnValidSequence());
DCHECK(ref_ > 0);
return --ref_;
}

private:
int32_t ref_;
#ifndef NDEBUG
base::MessageLoop* message_loop_;
#endif
base::SequenceChecker sequence_checker_;
};

// No-op lock class.
Expand Down

0 comments on commit 2111a57

Please sign in to comment.