Skip to content

Commit

Permalink
Move MessageLoop to base namespace.
Browse files Browse the repository at this point in the history
This adds a "using" to the header to avoid having to update everything at once. However, all forward declares and the locations that use the forward declares need to be updated (since they don't see the using in message_loop.h).

BUG=

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191566 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
brettw@chromium.org committed Mar 31, 2013
1 parent 16efcd1 commit 5e9e96a
Show file tree
Hide file tree
Showing 88 changed files with 465 additions and 382 deletions.
4 changes: 3 additions & 1 deletion android_webview/browser/aw_browser_main_parts.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include "base/memory/scoped_ptr.h"
#include "content/public/browser/browser_main_parts.h"

namespace base {
class MessageLoop;
}

namespace android_webview {

Expand All @@ -33,7 +35,7 @@ class AwBrowserMainParts : public content::BrowserMainParts {

private:
// Android specific UI MessageLoop.
scoped_ptr<MessageLoop> main_message_loop_;
scoped_ptr<base::MessageLoop> main_message_loop_;

AwBrowserContext* browser_context_; // weak
AwDevToolsDelegate* devtools_delegate_;
Expand Down
86 changes: 43 additions & 43 deletions base/message_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@
#include <gdk/gdkx.h>
#endif

using base::PendingTask;
using base::TimeDelta;
using base::TimeTicks;
namespace base {

namespace {

// A lazily created thread local storage for quick access to a thread's message
// loop, if one exists. This should be safe and free of static constructors.
base::LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr =
LazyInstance<base::ThreadLocalPointer<MessageLoop> > lazy_tls_ptr =
LAZY_INSTANCE_INITIALIZER;

// Logical events for Histogram profiling. Run with -message-loop-histogrammer
Expand Down Expand Up @@ -76,7 +74,7 @@ const int kNumberOfDistinctMessagesDisplayed = 1100;
// in the pair (i.e., the quoted string) when printing out a histogram.
#define VALUE_TO_NUMBER_AND_NAME(name) {name, #name},

const base::LinearHistogram::DescriptionPair event_descriptions_[] = {
const LinearHistogram::DescriptionPair event_descriptions_[] = {
// Provide some pretty print capability in our histogram for our internal
// messages.

Expand Down Expand Up @@ -149,30 +147,30 @@ MessageLoop::MessageLoop(Type type)
DCHECK(!current()) << "should only have one message loop per thread";
lazy_tls_ptr.Pointer()->Set(this);

message_loop_proxy_ = new base::MessageLoopProxyImpl();
message_loop_proxy_ = new MessageLoopProxyImpl();
thread_task_runner_handle_.reset(
new base::ThreadTaskRunnerHandle(message_loop_proxy_));
new ThreadTaskRunnerHandle(message_loop_proxy_));

// TODO(rvargas): Get rid of the OS guards.
#if defined(OS_WIN)
#define MESSAGE_PUMP_UI new base::MessagePumpForUI()
#define MESSAGE_PUMP_IO new base::MessagePumpForIO()
#define MESSAGE_PUMP_UI new MessagePumpForUI()
#define MESSAGE_PUMP_IO new MessagePumpForIO()
#elif defined(OS_IOS)
#define MESSAGE_PUMP_UI base::MessagePumpMac::Create()
#define MESSAGE_PUMP_IO new base::MessagePumpIOSForIO()
#define MESSAGE_PUMP_UI MessagePumpMac::Create()
#define MESSAGE_PUMP_IO new MessagePumpIOSForIO()
#elif defined(OS_MACOSX)
#define MESSAGE_PUMP_UI base::MessagePumpMac::Create()
#define MESSAGE_PUMP_IO new base::MessagePumpLibevent()
#define MESSAGE_PUMP_UI MessagePumpMac::Create()
#define MESSAGE_PUMP_IO new MessagePumpLibevent()
#elif defined(OS_NACL)
// Currently NaCl doesn't have a UI MessageLoop.
// TODO(abarth): Figure out if we need this.
#define MESSAGE_PUMP_UI NULL
// ipc_channel_nacl.cc uses a worker thread to do socket reads currently, and
// doesn't require extra support for watching file descriptors.
#define MESSAGE_PUMP_IO new base::MessagePumpDefault();
#define MESSAGE_PUMP_IO new MessagePumpDefault();
#elif defined(OS_POSIX) // POSIX but not MACOSX.
#define MESSAGE_PUMP_UI new base::MessagePumpForUI()
#define MESSAGE_PUMP_IO new base::MessagePumpLibevent()
#define MESSAGE_PUMP_UI new MessagePumpForUI()
#define MESSAGE_PUMP_IO new MessagePumpLibevent()
#else
#error Not implemented
#endif
Expand All @@ -186,7 +184,7 @@ MessageLoop::MessageLoop(Type type)
pump_ = MESSAGE_PUMP_IO;
} else {
DCHECK_EQ(TYPE_DEFAULT, type_);
pump_ = new base::MessagePumpDefault();
pump_ = new MessagePumpDefault();
}
}

Expand Down Expand Up @@ -219,7 +217,7 @@ MessageLoop::~MessageLoop() {
thread_task_runner_handle_.reset();

// Tell the message_loop_proxy that we are dying.
static_cast<base::MessageLoopProxyImpl*>(message_loop_proxy_.get())->
static_cast<MessageLoopProxyImpl*>(message_loop_proxy_.get())->
WillDestroyCurrentMessageLoop();
message_loop_proxy_ = NULL;

Expand All @@ -231,8 +229,8 @@ MessageLoop::~MessageLoop() {
// Doing this is not-critical, it is mainly to make sure we track
// the high resolution timer activations properly in our unit tests.
if (!high_resolution_timer_expiration_.is_null()) {
base::Time::ActivateHighResolutionTimer(false);
high_resolution_timer_expiration_ = base::TimeTicks();
Time::ActivateHighResolutionTimer(false);
high_resolution_timer_expiration_ = TimeTicks();
}
#endif
}
Expand Down Expand Up @@ -272,7 +270,7 @@ void MessageLoop::RemoveDestructionObserver(
}

void MessageLoop::PostTask(
const tracked_objects::Location& from_here, const base::Closure& task) {
const tracked_objects::Location& from_here, const Closure& task) {
DCHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(
from_here, task, CalculateDelayedRuntime(TimeDelta()), true);
Expand All @@ -281,7 +279,7 @@ void MessageLoop::PostTask(

void MessageLoop::PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
const Closure& task,
TimeDelta delay) {
DCHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(
Expand All @@ -291,7 +289,7 @@ void MessageLoop::PostDelayedTask(

void MessageLoop::PostNonNestableTask(
const tracked_objects::Location& from_here,
const base::Closure& task) {
const Closure& task) {
DCHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(
from_here, task, CalculateDelayedRuntime(TimeDelta()), false);
Expand All @@ -300,7 +298,7 @@ void MessageLoop::PostNonNestableTask(

void MessageLoop::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
const Closure& task,
TimeDelta delay) {
DCHECK(!task.is_null()) << from_here.ToString();
PendingTask pending_task(
Expand All @@ -309,12 +307,12 @@ void MessageLoop::PostNonNestableDelayedTask(
}

void MessageLoop::Run() {
base::RunLoop run_loop;
RunLoop run_loop;
run_loop.Run();
}

void MessageLoop::RunUntilIdle() {
base::RunLoop run_loop;
RunLoop run_loop;
run_loop.RunUntilIdle();
}

Expand Down Expand Up @@ -345,8 +343,8 @@ static void QuitCurrentWhenIdle() {
}

// static
base::Closure MessageLoop::QuitWhenIdleClosure() {
return base::Bind(&QuitCurrentWhenIdle);
Closure MessageLoop::QuitWhenIdleClosure() {
return Bind(&QuitCurrentWhenIdle);
}

void MessageLoop::SetNestableTasksAllowed(bool allowed) {
Expand Down Expand Up @@ -379,7 +377,7 @@ void MessageLoop::RemoveTaskObserver(TaskObserver* task_observer) {

void MessageLoop::AssertIdle() const {
// We only check |incoming_queue_|, since we don't want to lock |work_queue_|.
base::AutoLock lock(incoming_queue_lock_);
AutoLock lock(incoming_queue_lock_);
DCHECK(incoming_queue_.empty());
}

Expand Down Expand Up @@ -424,7 +422,7 @@ void MessageLoop::RunInternal() {

#if !defined(OS_MACOSX) && !defined(OS_ANDROID)
if (run_loop_->dispatcher_ && type() == TYPE_UI) {
static_cast<base::MessagePumpForUI*>(pump_.get())->
static_cast<MessagePumpForUI*>(pump_.get())->
RunWithDispatcher(this, run_loop_->dispatcher_);
return;
}
Expand Down Expand Up @@ -464,7 +462,7 @@ void MessageLoop::RunTask(const PendingTask& pending_task) {
// Look at a memory dump of the stack.
const void* program_counter =
pending_task.posted_from.program_counter();
base::debug::Alias(&program_counter);
debug::Alias(&program_counter);

HistogramEvent(kTaskRunEvent);

Expand Down Expand Up @@ -512,7 +510,7 @@ void MessageLoop::ReloadWorkQueue() {

// Acquire all we can from the inter-thread queue with one lock acquisition.
{
base::AutoLock lock(incoming_queue_lock_);
AutoLock lock(incoming_queue_lock_);
if (incoming_queue_.empty())
return;
incoming_queue_.Swap(&work_queue_); // Constant time
Expand Down Expand Up @@ -562,9 +560,9 @@ TimeTicks MessageLoop::CalculateDelayedRuntime(TimeDelta delay) {
// res timers for any timer which is within 2x of the granularity.
// This is a tradeoff between accuracy and power management.
bool needs_high_res_timers = delay.InMilliseconds() <
(2 * base::Time::kMinLowResolutionThresholdMs);
(2 * Time::kMinLowResolutionThresholdMs);
if (needs_high_res_timers) {
if (base::Time::ActivateHighResolutionTimer(true)) {
if (Time::ActivateHighResolutionTimer(true)) {
high_resolution_timer_expiration_ = TimeTicks::Now() +
TimeDelta::FromMilliseconds(kHighResolutionTimerModeLeaseTimeMs);
}
Expand All @@ -578,7 +576,7 @@ TimeTicks MessageLoop::CalculateDelayedRuntime(TimeDelta delay) {
#if defined(OS_WIN)
if (!high_resolution_timer_expiration_.is_null()) {
if (TimeTicks::Now() > high_resolution_timer_expiration_) {
base::Time::ActivateHighResolutionTimer(false);
Time::ActivateHighResolutionTimer(false);
high_resolution_timer_expiration_ = TimeTicks();
}
}
Expand All @@ -593,9 +591,9 @@ void MessageLoop::AddToIncomingQueue(PendingTask* pending_task) {
// directly, as it could starve handling of foreign threads. Put every task
// into this queue.

scoped_refptr<base::MessagePump> pump;
scoped_refptr<MessagePump> pump;
{
base::AutoLock locked(incoming_queue_lock_);
AutoLock locked(incoming_queue_lock_);

// Initialize the sequence number. The sequence number is used for delayed
// tasks (to faciliate FIFO sorting when two tasks have the same
Expand Down Expand Up @@ -628,9 +626,9 @@ void MessageLoop::AddToIncomingQueue(PendingTask* pending_task) {
void MessageLoop::StartHistogrammer() {
#if !defined(OS_NACL) // NaCl build has no metrics code.
if (enable_histogrammer_ && !message_histogram_
&& base::StatisticsRecorder::IsActive()) {
&& StatisticsRecorder::IsActive()) {
DCHECK(!thread_name_.empty());
message_histogram_ = base::LinearHistogram::FactoryGetWithRangeDescription(
message_histogram_ = LinearHistogram::FactoryGetWithRangeDescription(
"MsgLoop:" + thread_name_,
kLeastNonZeroMessageId, kMaxMessageId,
kNumberOfDistinctMessagesDisplayed,
Expand Down Expand Up @@ -722,14 +720,14 @@ bool MessageLoop::DoIdleWork() {
void MessageLoop::DeleteSoonInternal(const tracked_objects::Location& from_here,
void(*deleter)(const void*),
const void* object) {
PostNonNestableTask(from_here, base::Bind(deleter, object));
PostNonNestableTask(from_here, Bind(deleter, object));
}

void MessageLoop::ReleaseSoonInternal(
const tracked_objects::Location& from_here,
void(*releaser)(const void*),
const void* object) {
PostNonNestableTask(from_here, base::Bind(releaser, object));
PostNonNestableTask(from_here, Bind(releaser, object));
}

//------------------------------------------------------------------------------
Expand All @@ -744,13 +742,13 @@ void MessageLoopForUI::DidProcessMessage(const MSG& message) {
#if defined(OS_ANDROID)
void MessageLoopForUI::Start() {
// No Histogram support for UI message loop as it is managed by Java side
static_cast<base::MessagePumpForUI*>(pump_.get())->Start(this);
static_cast<MessagePumpForUI*>(pump_.get())->Start(this);
}
#endif

#if defined(OS_IOS)
void MessageLoopForUI::Attach() {
static_cast<base::MessagePumpUIApplication*>(pump_.get())->Attach(this);
static_cast<MessagePumpUIApplication*>(pump_.get())->Attach(this);
}
#endif

Expand Down Expand Up @@ -813,3 +811,5 @@ bool MessageLoopForIO::WatchFileDescriptor(int fd,
}

#endif

} // namespace base
10 changes: 9 additions & 1 deletion base/message_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
#endif

namespace base {

class HistogramBase;
class RunLoop;
class ThreadTaskRunnerHandle;
#if defined(OS_ANDROID)
class MessagePumpForUI;
#endif
} // namespace base

// A MessageLoop is used to process events for a particular thread. There is
// at most one MessageLoop instance per thread.
Expand Down Expand Up @@ -705,4 +705,12 @@ class BASE_EXPORT MessageLoopForIO : public MessageLoop {
COMPILE_ASSERT(sizeof(MessageLoop) == sizeof(MessageLoopForIO),
MessageLoopForIO_should_not_have_extra_member_variables);

} // namespace base

// TODO(brettw) remove this when all users are updated to explicitly use the
// namespace
using base::MessageLoop;
using base::MessageLoopForIO;
using base::MessageLoopForUI;

#endif // BASE_MESSAGE_LOOP_H_
Loading

0 comments on commit 5e9e96a

Please sign in to comment.