Revert 206507 "Move message_pump to base/message_loop."

> Move message_pump to base/message_loop.
> 
> This also fixes some namespace usage inside the message pump files and updates all users of these files to use the new location.
> 
> BUG=
> R=sky@chromium.org
> 
> Review URL: https://codereview.chromium.org/17078005

TBR=brettw@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@206513 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: 9bf0b36044584756132943f37a06f2fcaef7e5fb
diff --git a/base/android/base_jni_registrar.cc b/base/android/base_jni_registrar.cc
index 36d638b..468e297 100644
--- a/base/android/base_jni_registrar.cc
+++ b/base/android/base_jni_registrar.cc
@@ -16,7 +16,7 @@
 #include "base/android/thread_utils.h"
 #include "base/basictypes.h"
 #include "base/debug/trace_event.h"
-#include "base/message_loop/message_pump_android.h"
+#include "base/message_pump_android.h"
 #include "base/power_monitor/power_monitor_android.h"
 
 #if defined(GOOGLE_TV)
diff --git a/base/base.gyp b/base/base.gyp
index 54ed4b7..fa4b00e 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -247,21 +247,21 @@
         'linux_util.h',
         'md5.cc',
         'md5.h',
-        'message_loop/message_pump_android.cc',
-        'message_loop/message_pump_android.h',
-        'message_loop/message_pump_glib.cc',
-        'message_loop/message_pump_glib.h',
-        'message_loop/message_pump_gtk.cc',
-        'message_loop/message_pump_gtk.h',
-        'message_loop/message_pump_io_ios.cc',
-        'message_loop/message_pump_io_ios.h',
-        'message_loop/message_pump_observer.h',
-        'message_loop/message_pump_aurax11.cc',
-        'message_loop/message_pump_aurax11.h',
-        'message_loop/message_pump_libevent.cc',
-        'message_loop/message_pump_libevent.h',
-        'message_loop/message_pump_mac.h',
-        'message_loop/message_pump_mac.mm',
+        'message_pump_android.cc',
+        'message_pump_android.h',
+        'message_pump_glib.cc',
+        'message_pump_glib.h',
+        'message_pump_gtk.cc',
+        'message_pump_gtk.h',
+        'message_pump_io_ios.cc',
+        'message_pump_io_ios.h',
+        'message_pump_observer.h',
+        'message_pump_aurax11.cc',
+        'message_pump_aurax11.h',
+        'message_pump_libevent.cc',
+        'message_pump_libevent.h',
+        'message_pump_mac.h',
+        'message_pump_mac.mm',
         'metrics/field_trial.cc',
         'metrics/field_trial.h',
         'posix/file_descriptor_shuffle.cc',
@@ -526,9 +526,9 @@
         'message_loop/message_loop_proxy_impl_unittest.cc',
         'message_loop/message_loop_proxy_unittest.cc',
         'message_loop/message_loop_unittest.cc',
-        'message_loop/message_pump_glib_unittest.cc',
-        'message_loop/message_pump_io_ios_unittest.cc',
-        'message_loop/message_pump_libevent_unittest.cc',
+        'message_pump_glib_unittest.cc',
+        'message_pump_io_ios_unittest.cc',
+        'message_pump_libevent_unittest.cc',
         'metrics/sample_map_unittest.cc',
         'metrics/sample_vector_unittest.cc',
         'metrics/bucket_ranges_unittest.cc',
@@ -684,7 +684,7 @@
             # Requires spawning processes.
             ['exclude', '^metrics/stats_table_unittest\\.cc$'],
             # iOS does not use message_pump_libevent.
-            ['exclude', '^message_loop/message_pump_libevent_unittest\\.cc$'],
+            ['exclude', '^message_pump_libevent_unittest\\.cc$'],
           ],
           'conditions': [
             ['coverage != 0', {
@@ -746,12 +746,12 @@
           ],
         }, {  # use_glib!=1
           'sources!': [
-            'message_loop/message_pump_glib_unittest.cc',
+            'message_pump_glib_unittest.cc',
           ]
         }],
         ['use_ozone == 1', {
           'sources!': [
-            'message_loop/message_pump_glib_unittest.cc',
+            'message_pump_glib_unittest.cc',
           ]
         }],
         ['OS == "win"', {
@@ -764,7 +764,7 @@
             'file_descriptor_shuffle_unittest.cc',
             'files/dir_reader_posix_unittest.cc',
             'threading/worker_pool_posix_unittest.cc',
-            'message_loop/message_pump_libevent_unittest.cc',
+            'message_pump_libevent_unittest.cc',
           ],
           # TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
           'msvs_disabled_warnings': [
diff --git a/base/base.gypi b/base/base.gypi
index b96038b..0a580fd 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -301,16 +301,16 @@
           'message_loop/message_loop_proxy.h',
           'message_loop/message_loop_proxy_impl.cc',
           'message_loop/message_loop_proxy_impl.h',
-          'message_loop/message_pump.cc',
-          'message_loop/message_pump.h',
-          'message_loop/message_pump_android.cc',
-          'message_loop/message_pump_android.h',
-          'message_loop/message_pump_default.cc',
-          'message_loop/message_pump_default.h',
-          'message_loop/message_pump_ozone.cc',
-          'message_loop/message_pump_ozone.h',
-          'message_loop/message_pump_win.cc',
-          'message_loop/message_pump_win.h',
+          'message_pump.cc',
+          'message_pump.h',
+          'message_pump_android.cc',
+          'message_pump_android.h',
+          'message_pump_default.cc',
+          'message_pump_default.h',
+          'message_pump_ozone.cc',
+          'message_pump_ozone.h',
+          'message_pump_win.cc',
+          'message_pump_win.h',
           'metrics/sample_map.cc',
           'metrics/sample_map.h',
           'metrics/sample_vector.cc',
@@ -648,12 +648,12 @@
               ],
               'sources!': [
                 'atomicops_internals_x86_gcc.cc',
-                'message_loop/message_pump_glib.cc',
-                'message_loop/message_pump_aurax11.cc',
+                'message_pump_glib.cc',
+                'message_pump_aurax11.cc',
               ],
           }],
           ['<(toolkit_uses_gtk)==0 or >(nacl_untrusted_build)==1', {
-            'sources!': ['message_loop/message_pump_gtk.cc'],
+            'sources!': ['message_pump_gtk.cc'],
           }],
           ['(OS != "linux" and <(os_bsd) != 1 and OS != "android") or >(nacl_untrusted_build)==1', {
               'sources!': [
@@ -736,7 +736,7 @@
               ['include', '^mac/scoped_mach_port\\.'],
               ['include', '^mac/scoped_nsautorelease_pool\\.'],
               ['include', '^memory/discardable_memory_mac\\.'],
-              ['include', '^message_loop/message_pump_mac\\.'],
+              ['include', '^message_pump_mac\\.'],
               ['include', '^threading/platform_thread_mac\\.'],
               ['include', '^strings/sys_string_conversions_mac\\.'],
               ['include', '^time_mac\\.'],
@@ -747,7 +747,7 @@
               ['include', '^process_util_ios\\.mm$'],
             ],
             'sources!': [
-              'message_loop/message_pump_libevent.cc'
+              'message_pump_libevent.cc'
             ],
           }],
           ['OS == "ios" and _toolset == "host"', {
@@ -790,7 +790,7 @@
               'event_recorder_stubs.cc',
               'files/file_path_watcher_kqueue.cc',
               'files/file_path_watcher_stub.cc',
-              'message_loop/message_pump_libevent.cc',
+              'message_pump_libevent.cc',
               'posix/file_descriptor_shuffle.cc',
               # Not using sha1_win.cc because it may have caused a
               # regression to page cycler moz.
@@ -800,8 +800,8 @@
           },],
           ['<(use_ozone) == 1', {
             'sources!': [
-              'message_loop/message_pump_glib.cc',
-              'message_loop/message_pump_aurax11.cc',
+              'message_pump_glib.cc',
+              'message_pump_aurax11.cc',
             ]
           }],
           ['OS == "linux" and >(nacl_untrusted_build)==0', {
diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc
index 4e0c5f6..0364a52 100644
--- a/base/message_loop/message_loop.cc
+++ b/base/message_loop/message_loop.cc
@@ -14,7 +14,7 @@
 #include "base/logging.h"
 #include "base/memory/scoped_ptr.h"
 #include "base/message_loop/message_loop_proxy_impl.h"
-#include "base/message_loop/message_pump_default.h"
+#include "base/message_pump_default.h"
 #include "base/metrics/histogram.h"
 #include "base/metrics/statistics_recorder.h"
 #include "base/run_loop.h"
@@ -25,13 +25,13 @@
 #include "base/tracked_objects.h"
 
 #if defined(OS_MACOSX)
-#include "base/message_loop/message_pump_mac.h"
+#include "base/message_pump_mac.h"
 #endif
 #if defined(OS_POSIX) && !defined(OS_IOS)
-#include "base/message_loop/message_pump_libevent.h"
+#include "base/message_pump_libevent.h"
 #endif
 #if defined(OS_ANDROID)
-#include "base/message_loop/message_pump_android.h"
+#include "base/message_pump_android.h"
 #endif
 
 #if defined(TOOLKIT_GTK)
diff --git a/base/message_loop/message_loop.h b/base/message_loop/message_loop.h
index e765cef..d26b673 100644
--- a/base/message_loop/message_loop.h
+++ b/base/message_loop/message_loop.h
@@ -14,7 +14,7 @@
 #include "base/location.h"
 #include "base/memory/ref_counted.h"
 #include "base/message_loop/message_loop_proxy.h"
-#include "base/message_loop/message_pump.h"
+#include "base/message_pump.h"
 #include "base/observer_list.h"
 #include "base/pending_task.h"
 #include "base/sequenced_task_runner_helpers.h"
@@ -25,26 +25,25 @@
 #if defined(OS_WIN)
 // We need this to declare base::MessagePumpWin::Dispatcher, which we should
 // really just eliminate.
-#include "base/message_loop/message_pump_win.h"
+#include "base/message_pump_win.h"
 #elif defined(OS_IOS)
-#include "base/message_loop/message_pump_io_ios.h"
+#include "base/message_pump_io_ios.h"
 #elif defined(OS_POSIX)
-#include "base/message_loop/message_pump_libevent.h"
+#include "base/message_pump_libevent.h"
 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
 
 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_NACL)
-#include "base/message_loop/message_pump_aurax11.h"
+#include "base/message_pump_aurax11.h"
 #elif defined(USE_OZONE) && !defined(OS_NACL)
-#include "base/message_loop/message_pump_ozone.h"
+#include "base/message_pump_ozone.h"
 #else
-#include "base/message_loop/message_pump_gtk.h"
+#include "base/message_pump_gtk.h"
 #endif
 
 #endif
 #endif
 
 namespace base {
-
 class HistogramBase;
 class MessageLoopLockTest;
 class RunLoop;
@@ -84,12 +83,12 @@
 // Please be SURE your task is reentrant (nestable) and all global variables
 // are stable and accessible before calling SetNestableTasksAllowed(true).
 //
-class BASE_EXPORT MessageLoop : public MessagePump::Delegate {
+class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
  public:
 
 #if !defined(OS_MACOSX) && !defined(OS_ANDROID)
-  typedef MessagePumpDispatcher Dispatcher;
-  typedef MessagePumpObserver Observer;
+  typedef base::MessagePumpDispatcher Dispatcher;
+  typedef base::MessagePumpObserver Observer;
 #endif
 
   // A MessageLoop has a particular type, which indicates the set of
@@ -122,7 +121,7 @@
 
   static void EnableHistogrammer(bool enable_histogrammer);
 
-  typedef MessagePump* (MessagePumpFactory)();
+  typedef base::MessagePump* (MessagePumpFactory)();
   // Uses the given base::MessagePumpForUIFactory to override the default
   // MessagePump implementation for 'TYPE_UI'. Returns true if the factory
   // was successfully registered.
@@ -175,22 +174,27 @@
   //
   // NOTE: These methods may be called on any thread.  The Task will be invoked
   // on the thread that executes MessageLoop::Run().
-  void PostTask(const tracked_objects::Location& from_here,
-                const Closure& task);
+  void PostTask(
+      const tracked_objects::Location& from_here,
+      const base::Closure& task);
 
-  bool TryPostTask(const tracked_objects::Location& from_here,
-                   const Closure& task);
+  bool TryPostTask(
+      const tracked_objects::Location& from_here,
+      const base::Closure& task);
 
-  void PostDelayedTask(const tracked_objects::Location& from_here,
-                       const Closure& task,
-                       TimeDelta delay);
+  void PostDelayedTask(
+      const tracked_objects::Location& from_here,
+      const base::Closure& task,
+      base::TimeDelta delay);
 
-  void PostNonNestableTask(const tracked_objects::Location& from_here,
-                           const Closure& task);
+  void PostNonNestableTask(
+      const tracked_objects::Location& from_here,
+      const base::Closure& task);
 
-  void PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
-                                  const Closure& task,
-                                  TimeDelta delay);
+  void PostNonNestableDelayedTask(
+      const tracked_objects::Location& from_here,
+      const base::Closure& task,
+      base::TimeDelta delay);
 
   // A variant on PostTask that deletes the given object.  This is useful
   // if the object needs to live until the next run of the MessageLoop (for
@@ -260,12 +264,12 @@
   void QuitNow();
 
   // TODO(jbates) remove this. crbug.com/131220. See QuitWhenIdleClosure().
-  static Closure QuitClosure() { return QuitWhenIdleClosure(); }
+  static base::Closure QuitClosure() { return QuitWhenIdleClosure(); }
 
   // Deprecated: use RunLoop instead.
   // Construct a Closure that will call QuitWhenIdle(). Useful to schedule an
   // arbitrary MessageLoop to QuitWhenIdle.
-  static Closure QuitWhenIdleClosure();
+  static base::Closure QuitWhenIdleClosure();
 
   // Returns true if this loop is |type|. This allows subclasses (especially
   // those in tests) to specialize how they are identified.
@@ -282,7 +286,7 @@
   const std::string& thread_name() const { return thread_name_; }
 
   // Gets the message loop proxy associated with this message loop.
-  scoped_refptr<MessageLoopProxy> message_loop_proxy() {
+  scoped_refptr<base::MessageLoopProxy> message_loop_proxy() {
     return message_loop_proxy_.get();
   }
 
@@ -345,10 +349,10 @@
     TaskObserver();
 
     // This method is called before processing a task.
-    virtual void WillProcessTask(const PendingTask& pending_task) = 0;
+    virtual void WillProcessTask(const base::PendingTask& pending_task) = 0;
 
     // This method is called after processing a task.
-    virtual void DidProcessTask(const PendingTask& pending_task) = 0;
+    virtual void DidProcessTask(const base::PendingTask& pending_task) = 0;
 
    protected:
     virtual ~TaskObserver();
@@ -393,20 +397,20 @@
  protected:
 
 #if defined(OS_WIN)
-  MessagePumpWin* pump_win() {
-    return static_cast<MessagePumpWin*>(pump_.get());
+  base::MessagePumpWin* pump_win() {
+    return static_cast<base::MessagePumpWin*>(pump_.get());
   }
 #elif defined(OS_POSIX) && !defined(OS_IOS)
-  MessagePumpLibevent* pump_libevent() {
-    return static_cast<MessagePumpLibevent*>(pump_.get());
+  base::MessagePumpLibevent* pump_libevent() {
+    return static_cast<base::MessagePumpLibevent*>(pump_.get());
   }
 #endif
 
-  scoped_refptr<MessagePump> pump_;
+  scoped_refptr<base::MessagePump> pump_;
 
  private:
-  friend class RunLoop;
-  friend class MessageLoopLockTest;
+  friend class base::RunLoop;
+  friend class base::MessageLoopLockTest;
 
   // A function to encapsulate all the exception handling capability in the
   // stacks around the running of a main message loop.  It will run the message
@@ -427,14 +431,14 @@
   bool ProcessNextDelayedNonNestableTask();
 
   // Runs the specified PendingTask.
-  void RunTask(const PendingTask& pending_task);
+  void RunTask(const base::PendingTask& pending_task);
 
   // Calls RunTask or queues the pending_task on the deferred task list if it
   // cannot be run right now.  Returns true if the task was run.
-  bool DeferOrRunPendingTask(const PendingTask& pending_task);
+  bool DeferOrRunPendingTask(const base::PendingTask& pending_task);
 
   // Adds the pending task to delayed_work_queue_.
-  void AddToDelayedWorkQueue(const PendingTask& pending_task);
+  void AddToDelayedWorkQueue(const base::PendingTask& pending_task);
 
   // This function attempts to add pending task to our incoming_queue_.
   // The append can only possibly fail when |use_try_lock| is true.
@@ -450,7 +454,7 @@
   // function will reset the value of pending_task->task.  This is needed to
   // ensure that the posting call stack does not retain pending_task->task
   // beyond this function call.
-  bool AddToIncomingQueue(PendingTask* pending_task, bool use_try_lock);
+  bool AddToIncomingQueue(base::PendingTask* pending_task, bool use_try_lock);
 
   // Load tasks from the incoming_queue_ into work_queue_ if the latter is
   // empty.  The former requires a lock to access, while the latter is directly
@@ -463,7 +467,7 @@
   bool DeletePendingTasks();
 
   // Calculates the time at which a PendingTask should run.
-  TimeTicks CalculateDelayedRuntime(TimeDelta delay);
+  base::TimeTicks CalculateDelayedRuntime(base::TimeDelta delay);
 
   // Start recording histogram info about events and action IF it was enabled
   // and IF the statistics recorder can accept a registration of our histogram.
@@ -474,27 +478,27 @@
   // If message_histogram_ is NULL, this is a no-op.
   void HistogramEvent(int event);
 
-  // MessagePump::Delegate methods:
+  // base::MessagePump::Delegate methods:
   virtual bool DoWork() OVERRIDE;
-  virtual bool DoDelayedWork(TimeTicks* next_delayed_work_time) OVERRIDE;
+  virtual bool DoDelayedWork(base::TimeTicks* next_delayed_work_time) OVERRIDE;
   virtual bool DoIdleWork() OVERRIDE;
 
   Type type_;
 
   // A list of tasks that need to be processed by this instance.  Note that
   // this queue is only accessed (push/pop) by our current thread.
-  TaskQueue work_queue_;
+  base::TaskQueue work_queue_;
 
   // Contains delayed tasks, sorted by their 'delayed_run_time' property.
-  DelayedTaskQueue delayed_work_queue_;
+  base::DelayedTaskQueue delayed_work_queue_;
 
   // A recent snapshot of Time::Now(), used to check delayed_work_queue_.
-  TimeTicks recent_time_;
+  base::TimeTicks recent_time_;
 
   // A queue of non-nestable tasks that we had to defer because when it came
   // time to execute them we were in a nested message loop.  They will execute
   // once we're out of nested message loops.
-  TaskQueue deferred_non_nestable_work_queue_;
+  base::TaskQueue deferred_non_nestable_work_queue_;
 
   ObserverList<DestructionObserver> destruction_observers_;
 
@@ -506,19 +510,19 @@
 
   std::string thread_name_;
   // A profiling histogram showing the counts of various messages and events.
-  HistogramBase* message_histogram_;
+  base::HistogramBase* message_histogram_;
 
   // An incoming queue of tasks that are acquired under a mutex for processing
   // on this instance's thread. These tasks have not yet been sorted out into
   // items for our work_queue_ vs delayed_work_queue_.
-  TaskQueue incoming_queue_;
+  base::TaskQueue incoming_queue_;
   // Protect access to incoming_queue_.
-  mutable Lock incoming_queue_lock_;
+  mutable base::Lock incoming_queue_lock_;
 
-  RunLoop* run_loop_;
+  base::RunLoop* run_loop_;
 
 #if defined(OS_WIN)
-  TimeTicks high_resolution_timer_expiration_;
+  base::TimeTicks high_resolution_timer_expiration_;
   // Should be set to true before calling Windows APIs like TrackPopupMenu, etc
   // which enter a modal message loop.
   bool os_modal_loop_;
@@ -531,8 +535,8 @@
   ObserverList<TaskObserver> task_observers_;
 
   // The message loop proxy associated with this message loop, if one exists.
-  scoped_refptr<MessageLoopProxy> message_loop_proxy_;
-  scoped_ptr<ThreadTaskRunnerHandle> thread_task_runner_handle_;
+  scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
+  scoped_ptr<base::ThreadTaskRunnerHandle> thread_task_runner_handle_;
 
   template <class T, class R> friend class base::subtle::DeleteHelperInternal;
   template <class T, class R> friend class base::subtle::ReleaseHelperInternal;
@@ -557,7 +561,7 @@
 class BASE_EXPORT MessageLoopForUI : public MessageLoop {
  public:
 #if defined(OS_WIN)
-  typedef MessagePumpForUI::MessageFilter MessageFilter;
+  typedef base::MessagePumpForUI::MessageFilter MessageFilter;
 #endif
 
   MessageLoopForUI() : MessageLoop(TYPE_UI) {
@@ -603,15 +607,15 @@
 
  protected:
 #if defined(USE_AURA) && defined(USE_X11) && !defined(OS_NACL)
-  friend class MessagePumpAuraX11;
+  friend class base::MessagePumpAuraX11;
 #endif
 #if defined(USE_OZONE) && !defined(OS_NACL)
-  friend class MessagePumpOzone;
+  friend class base::MessagePumpOzone;
 #endif
 
   // TODO(rvargas): Make this platform independent.
-  MessagePumpForUI* pump_ui() {
-    return static_cast<MessagePumpForUI*>(pump_.get());
+  base::MessagePumpForUI* pump_ui() {
+    return static_cast<base::MessagePumpForUI*>(pump_.get());
   }
 #endif  // !defined(OS_MACOSX)
 };
@@ -632,30 +636,30 @@
 class BASE_EXPORT MessageLoopForIO : public MessageLoop {
  public:
 #if defined(OS_WIN)
-  typedef MessagePumpForIO::IOHandler IOHandler;
-  typedef MessagePumpForIO::IOContext IOContext;
-  typedef MessagePumpForIO::IOObserver IOObserver;
+  typedef base::MessagePumpForIO::IOHandler IOHandler;
+  typedef base::MessagePumpForIO::IOContext IOContext;
+  typedef base::MessagePumpForIO::IOObserver IOObserver;
 #elif defined(OS_IOS)
-  typedef MessagePumpIOSForIO::Watcher Watcher;
-  typedef MessagePumpIOSForIO::FileDescriptorWatcher
+  typedef base::MessagePumpIOSForIO::Watcher Watcher;
+  typedef base::MessagePumpIOSForIO::FileDescriptorWatcher
       FileDescriptorWatcher;
-  typedef MessagePumpIOSForIO::IOObserver IOObserver;
+  typedef base::MessagePumpIOSForIO::IOObserver IOObserver;
 
   enum Mode {
-    WATCH_READ = MessagePumpIOSForIO::WATCH_READ,
-    WATCH_WRITE = MessagePumpIOSForIO::WATCH_WRITE,
-    WATCH_READ_WRITE = MessagePumpIOSForIO::WATCH_READ_WRITE
+    WATCH_READ = base::MessagePumpIOSForIO::WATCH_READ,
+    WATCH_WRITE = base::MessagePumpIOSForIO::WATCH_WRITE,
+    WATCH_READ_WRITE = base::MessagePumpIOSForIO::WATCH_READ_WRITE
   };
 #elif defined(OS_POSIX)
-  typedef MessagePumpLibevent::Watcher Watcher;
-  typedef MessagePumpLibevent::FileDescriptorWatcher
+  typedef base::MessagePumpLibevent::Watcher Watcher;
+  typedef base::MessagePumpLibevent::FileDescriptorWatcher
       FileDescriptorWatcher;
-  typedef MessagePumpLibevent::IOObserver IOObserver;
+  typedef base::MessagePumpLibevent::IOObserver IOObserver;
 
   enum Mode {
-    WATCH_READ = MessagePumpLibevent::WATCH_READ,
-    WATCH_WRITE = MessagePumpLibevent::WATCH_WRITE,
-    WATCH_READ_WRITE = MessagePumpLibevent::WATCH_READ_WRITE
+    WATCH_READ = base::MessagePumpLibevent::WATCH_READ,
+    WATCH_WRITE = base::MessagePumpLibevent::WATCH_WRITE,
+    WATCH_READ_WRITE = base::MessagePumpLibevent::WATCH_READ_WRITE
   };
 
 #endif
@@ -686,8 +690,8 @@
 
  protected:
   // TODO(rvargas): Make this platform independent.
-  MessagePumpForIO* pump_io() {
-    return static_cast<MessagePumpForIO*>(pump_.get());
+  base::MessagePumpForIO* pump_io() {
+    return static_cast<base::MessagePumpForIO*>(pump_.get());
   }
 
 #elif defined(OS_IOS)
@@ -699,8 +703,8 @@
                            Watcher *delegate);
 
  private:
-  MessagePumpIOSForIO* pump_io() {
-    return static_cast<MessagePumpIOSForIO*>(pump_.get());
+  base::MessagePumpIOSForIO* pump_io() {
+    return static_cast<base::MessagePumpIOSForIO*>(pump_.get());
   }
 
 #elif defined(OS_POSIX)
@@ -712,8 +716,8 @@
                            Watcher* delegate);
 
  private:
-  MessagePumpLibevent* pump_io() {
-    return static_cast<MessagePumpLibevent*>(pump_.get());
+  base::MessagePumpLibevent* pump_io() {
+    return static_cast<base::MessagePumpLibevent*>(pump_.get());
   }
 #endif  // defined(OS_POSIX)
 };
diff --git a/base/message_loop/message_loop_unittest.cc b/base/message_loop/message_loop_unittest.cc
index 504c8e3..0f85b14 100644
--- a/base/message_loop/message_loop_unittest.cc
+++ b/base/message_loop/message_loop_unittest.cc
@@ -9,7 +9,7 @@
 #include "base/compiler_specific.h"
 #include "base/logging.h"
 #include "base/memory/ref_counted.h"
-#include "base/message_loop/message_loop.h"
+#include "base/message_loop.h"
 #include "base/pending_task.h"
 #include "base/posix/eintr_wrapper.h"
 #include "base/run_loop.h"
@@ -20,7 +20,7 @@
 #include "testing/gtest/include/gtest/gtest.h"
 
 #if defined(OS_WIN)
-#include "base/message_loop/message_pump_win.h"
+#include "base/message_pump_win.h"
 #include "base/win/scoped_handle.h"
 #endif
 
@@ -29,8 +29,8 @@
 class MessageLoopLockTest {
  public:
   static void LockWaitUnLock(MessageLoop* loop,
-                             WaitableEvent* caller_wait,
-                             WaitableEvent* caller_signal) {
+                             base::WaitableEvent* caller_wait,
+                             base::WaitableEvent* caller_signal) {
 
     loop->incoming_queue_lock_.Acquire();
     caller_wait->Signal();
@@ -121,7 +121,7 @@
   thread.Start();
   thread.message_loop()->PostTask(
       FROM_HERE,
-      Bind(&MessageLoopLockTest::LockWaitUnLock,
+      base::Bind(&MessageLoopLockTest::LockWaitUnLock,
       MessageLoop::current(),
       &wait,
       &signal));
@@ -1419,7 +1419,7 @@
 
 #if defined(OS_WIN)
 
-class DispatcherImpl : public MessageLoopForUI::Dispatcher {
+class DispatcherImpl : public base::MessageLoopForUI::Dispatcher {
  public:
   DispatcherImpl() : dispatch_count_(0) {}
 
diff --git a/base/message_loop/message_pump.cc b/base/message_pump.cc
similarity index 85%
rename from base/message_loop/message_pump.cc
rename to base/message_pump.cc
index 7ffc2b1..de7c517 100644
--- a/base/message_loop/message_pump.cc
+++ b/base/message_pump.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/message_loop/message_pump.h"
+#include "base/message_pump.h"
 
 namespace base {
 
diff --git a/base/message_loop/message_pump.h b/base/message_pump.h
similarity index 97%
rename from base/message_loop/message_pump.h
rename to base/message_pump.h
index 5b72232..b2e0a42 100644
--- a/base/message_loop/message_pump.h
+++ b/base/message_pump.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_H_
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_H_
+#ifndef BASE_MESSAGE_PUMP_H_
+#define BASE_MESSAGE_PUMP_H_
 
 #include "base/base_export.h"
 #include "base/memory/ref_counted.h"
@@ -126,4 +126,4 @@
 
 }  // namespace base
 
-#endif  // BASE_MESSAGE_LOOP_MESSAGE_PUMP_H_
+#endif  // BASE_MESSAGE_PUMP_H_
diff --git a/base/message_loop/message_pump_android.cc b/base/message_pump_android.cc
similarity index 94%
rename from base/message_loop/message_pump_android.cc
rename to base/message_pump_android.cc
index 7374d9c..f02da67 100644
--- a/base/message_loop/message_pump_android.cc
+++ b/base/message_pump_android.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/message_loop/message_pump_android.h"
+#include "base/message_pump_android.h"
 
 #include <jni.h>
 
@@ -18,7 +18,7 @@
 
 namespace {
 
-LazyInstance<android::ScopedJavaGlobalRef<jobject> >
+base::LazyInstance<base::android::ScopedJavaGlobalRef<jobject> >
     g_system_message_handler_obj = LAZY_INSTANCE_INITIALIZER;
 
 }  // namespace
@@ -75,7 +75,7 @@
 }
 
 void MessagePumpForUI::Start(Delegate* delegate) {
-  run_loop_ = new RunLoop();
+  run_loop_ = new base::RunLoop();
   // Since the RunLoop was just created above, BeforeRun should be guaranteed to
   // return true (it only returns false if the RunLoop has been Quit already).
   if (!run_loop_->BeforeRun())
@@ -124,7 +124,7 @@
   DCHECK(env);
 
   jlong millis =
-      (delayed_work_time - TimeTicks::Now()).InMillisecondsRoundedUp();
+      (delayed_work_time - base::TimeTicks::Now()).InMillisecondsRoundedUp();
   // Note that we're truncating to milliseconds as required by the java side,
   // even though delayed_work_time is microseconds resolution.
   Java_SystemMessageHandler_setDelayedTimer(env,
diff --git a/base/message_loop/message_pump_android.h b/base/message_pump_android.h
similarity index 80%
rename from base/message_loop/message_pump_android.h
rename to base/message_pump_android.h
index fd934a7..5ef4bd6 100644
--- a/base/message_loop/message_pump_android.h
+++ b/base/message_pump_android.h
@@ -2,14 +2,14 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_
+#ifndef BASE_MESSAGE_PUMP_ANDROID_H_
+#define BASE_MESSAGE_PUMP_ANDROID_H_
 
 #include <jni.h>
 
 #include "base/base_export.h"
 #include "base/compiler_specific.h"
-#include "base/message_loop/message_pump.h"
+#include "base/message_pump.h"
 
 namespace base {
 
@@ -35,11 +35,11 @@
   virtual ~MessagePumpForUI();
 
  private:
-  RunLoop* run_loop_;
+  base::RunLoop* run_loop_;
 
   DISALLOW_COPY_AND_ASSIGN(MessagePumpForUI);
 };
 
 }  // namespace base
 
-#endif  // BASE_MESSAGE_LOOP_MESSAGE_PUMP_ANDROID_H_
+#endif  // BASE_MESSAGE_PUMP_ANDROID_H_
diff --git a/base/message_loop/message_pump_aurax11.cc b/base/message_pump_aurax11.cc
similarity index 93%
rename from base/message_loop/message_pump_aurax11.cc
rename to base/message_pump_aurax11.cc
index 70cae64..9ba7989 100644
--- a/base/message_loop/message_pump_aurax11.cc
+++ b/base/message_pump_aurax11.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/message_loop/message_pump_aurax11.h"
+#include "base/message_pump_aurax11.h"
 
 #include <glib.h>
 #include <X11/X.h>
@@ -12,12 +12,10 @@
 #include "base/basictypes.h"
 #include "base/message_loop.h"
 
-namespace base {
-
 namespace {
 
 gboolean XSourcePrepare(GSource* source, gint* timeout_ms) {
-  if (XPending(MessagePumpAuraX11::GetDefaultXDisplay()))
+  if (XPending(base::MessagePumpAuraX11::GetDefaultXDisplay()))
     *timeout_ms = 0;
   else
     *timeout_ms = -1;
@@ -25,13 +23,13 @@
 }
 
 gboolean XSourceCheck(GSource* source) {
-  return XPending(MessagePumpAuraX11::GetDefaultXDisplay());
+  return XPending(base::MessagePumpAuraX11::GetDefaultXDisplay());
 }
 
 gboolean XSourceDispatch(GSource* source,
                          GSourceFunc unused_func,
                          gpointer data) {
-  MessagePumpAuraX11* pump = static_cast<MessagePumpAuraX11*>(data);
+  base::MessagePumpAuraX11* pump = static_cast<base::MessagePumpAuraX11*>(data);
   return pump->DispatchXEvents();
 }
 
@@ -54,7 +52,7 @@
 int g_xinput_opcode = -1;
 
 bool InitializeXInput2Internal() {
-  Display* display = MessagePumpAuraX11::GetDefaultXDisplay();
+  Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay();
   if (!display)
     return false;
 
@@ -88,7 +86,7 @@
   return true;
 }
 
-Window FindEventTarget(const NativeEvent& xev) {
+Window FindEventTarget(const base::NativeEvent& xev) {
   Window target = xev->xany.window;
   if (xev->type == GenericEvent &&
       static_cast<XIEvent*>(xev->xcookie.data)->extension == g_xinput_opcode) {
@@ -103,7 +101,7 @@
 }
 
 bool InitializeXkb() {
-  Display* display = MessagePumpAuraX11::GetDefaultXDisplay();
+  Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay();
   if (!display)
     return false;
 
@@ -128,6 +126,8 @@
 
 }  // namespace
 
+namespace base {
+
 MessagePumpAuraX11::MessagePumpAuraX11() : MessagePumpGlib(),
     x_source_(NULL) {
   InitializeXInput2();
@@ -277,13 +277,13 @@
 }
 
 MessagePumpDispatcher* MessagePumpAuraX11::GetDispatcherForXEvent(
-    const NativeEvent& xev) const {
+    const base::NativeEvent& xev) const {
   ::Window x_window = FindEventTarget(xev);
   DispatchersMap::const_iterator it = dispatchers_.find(x_window);
   return it != dispatchers_.end() ? it->second : NULL;
 }
 
-bool MessagePumpAuraX11::Dispatch(const NativeEvent& xev) {
+bool MessagePumpAuraX11::Dispatch(const base::NativeEvent& xev) {
   // MappingNotify events (meaning that the keyboard or pointer buttons have
   // been remapped) aren't associated with a window; send them to all
   // dispatchers.
diff --git a/base/message_loop/message_pump_aurax11.h b/base/message_pump_aurax11.h
similarity index 88%
rename from base/message_loop/message_pump_aurax11.h
rename to base/message_pump_aurax11.h
index cec6934..486de4f 100644
--- a/base/message_loop/message_pump_aurax11.h
+++ b/base/message_pump_aurax11.h
@@ -2,17 +2,17 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_AURAX11_H
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_AURAX11_H
+#ifndef BASE_MESSAGE_PUMP_AURAX11_H
+#define BASE_MESSAGE_PUMP_AURAX11_H
 
 #include <bitset>
 #include <map>
 
 #include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_pump.h"
-#include "base/message_loop/message_pump_dispatcher.h"
-#include "base/message_loop/message_pump_glib.h"
-#include "base/message_loop/message_pump_observer.h"
+#include "base/message_pump.h"
+#include "base/message_pump_glib.h"
+#include "base/message_pump_dispatcher.h"
+#include "base/message_pump_observer.h"
 #include "base/observer_list.h"
 
 // It would be nice to include the X11 headers here so that we use Window
@@ -92,10 +92,11 @@
   void DidProcessXEvent(XEvent* xevent);
 
   // Returns the Dispatcher based on the event's target window.
-  MessagePumpDispatcher* GetDispatcherForXEvent(const NativeEvent& xev) const;
+  MessagePumpDispatcher* GetDispatcherForXEvent(
+      const base::NativeEvent& xev) const;
 
   // Overridden from MessagePumpDispatcher:
-  virtual bool Dispatch(const NativeEvent& event) OVERRIDE;
+  virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE;
 
   // The event source for X events.
   GSource* x_source_;
@@ -119,4 +120,4 @@
 
 }  // namespace base
 
-#endif  // BASE_MESSAGE_LOOP_MESSAGE_PUMP_AURAX11_H
+#endif  // BASE_MESSAGE_PUMP_AURAX11_H
diff --git a/base/message_loop/message_pump_default.cc b/base/message_pump_default.cc
similarity index 94%
rename from base/message_loop/message_pump_default.cc
rename to base/message_pump_default.cc
index b36ff21..649e2aa 100644
--- a/base/message_loop/message_pump_default.cc
+++ b/base/message_pump_default.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/message_loop/message_pump_default.h"
+#include "base/message_pump_default.h"
 
 #include "base/logging.h"
 #include "base/threading/thread_restrictions.h"
@@ -44,7 +44,7 @@
     if (did_work)
       continue;
 
-    ThreadRestrictions::ScopedAllowWait allow_wait;
+    base::ThreadRestrictions::ScopedAllowWait allow_wait;
     if (delayed_work_time_.is_null()) {
       event_.Wait();
     } else {
diff --git a/base/message_loop/message_pump_default.h b/base/message_pump_default.h
similarity index 82%
rename from base/message_loop/message_pump_default.h
rename to base/message_pump_default.h
index dd65973..6deec99 100644
--- a/base/message_loop/message_pump_default.h
+++ b/base/message_pump_default.h
@@ -2,12 +2,12 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_DEFAULT_H_
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_DEFAULT_H_
+#ifndef BASE_MESSAGE_PUMP_DEFAULT_H_
+#define BASE_MESSAGE_PUMP_DEFAULT_H_
 
-#include "base/message_loop/message_pump.h"
-#include "base/synchronization/waitable_event.h"
+#include "base/message_pump.h"
 #include "base/time.h"
+#include "base/synchronization/waitable_event.h"
 
 namespace base {
 
@@ -39,4 +39,4 @@
 
 }  // namespace base
 
-#endif  // BASE__MESSAGE_LOOPMESSAGE_PUMP_DEFAULT_H_
+#endif  // BASE_MESSAGE_PUMP_DEFAULT_H_
diff --git a/base/message_loop/message_pump_dispatcher.h b/base/message_pump_dispatcher.h
similarity index 86%
rename from base/message_loop/message_pump_dispatcher.h
rename to base/message_pump_dispatcher.h
index e49fa4f..c3ccf3c 100644
--- a/base/message_loop/message_pump_dispatcher.h
+++ b/base/message_pump_dispatcher.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_DISPATCHER_H
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_DISPATCHER_H
+#ifndef BASE_MESSAGE_PUMP_DISPATCHER_H
+#define BASE_MESSAGE_PUMP_DISPATCHER_H
 
 #include "base/base_export.h"
 #include "base/event_types.h"
@@ -29,4 +29,4 @@
 
 }  // namespace base
 
-#endif  // BASE_MESSAGE_LOOP_MESSAGE_PUMP_DISPATCHER_H
+#endif  // BASE_MESSAGE_PUMP_DISPATCHER_H
diff --git a/base/message_loop/message_pump_glib.cc b/base/message_pump_glib.cc
similarity index 96%
rename from base/message_loop/message_pump_glib.cc
rename to base/message_pump_glib.cc
index de012fd..7436558 100644
--- a/base/message_loop/message_pump_glib.cc
+++ b/base/message_pump_glib.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/message_loop/message_pump_glib.h"
+#include "base/message_pump_glib.h"
 
 #include <fcntl.h>
 #include <math.h>
@@ -13,13 +13,11 @@
 #include "base/posix/eintr_wrapper.h"
 #include "base/threading/platform_thread.h"
 
-namespace base {
-
 namespace {
 
 // Return a timeout suitable for the glib loop, -1 to block forever,
 // 0 to return right away, or a timeout in milliseconds from now.
-int GetTimeIntervalMilliseconds(const TimeTicks& from) {
+int GetTimeIntervalMilliseconds(const base::TimeTicks& from) {
   if (from.is_null())
     return -1;
 
@@ -27,7 +25,7 @@
   // value in milliseconds.  If there are 5.5ms left, should the delay be 5 or
   // 6?  It should be 6 to avoid executing delayed work too early.
   int delay = static_cast<int>(
-      ceil((from - TimeTicks::Now()).InMillisecondsF()));
+      ceil((from - base::TimeTicks::Now()).InMillisecondsF()));
 
   // If this value is negative, then we need to run delayed work soon.
   return delay < 0 ? 0 : delay;
@@ -83,7 +81,7 @@
 // loop, around event handling.
 
 struct WorkSource : public GSource {
-  MessagePumpGlib* pump;
+  base::MessagePumpGlib* pump;
 };
 
 gboolean WorkSourcePrepare(GSource* source,
@@ -119,6 +117,9 @@
 
 }  // namespace
 
+
+namespace base {
+
 struct MessagePumpGlib::RunState {
   Delegate* delegate;
   MessagePumpDispatcher* dispatcher;
@@ -165,8 +166,8 @@
 #ifndef NDEBUG
   // Make sure we only run this on one thread. X/GTK only has one message pump
   // so we can only have one UI loop per process.
-  static PlatformThreadId thread_id = PlatformThread::CurrentId();
-  DCHECK(thread_id == PlatformThread::CurrentId()) <<
+  static base::PlatformThreadId thread_id = base::PlatformThread::CurrentId();
+  DCHECK(thread_id == base::PlatformThread::CurrentId()) <<
       "Running MessagePumpGlib on two different threads; "
       "this is unsupported by GLib!";
 #endif
diff --git a/base/message_loop/message_pump_glib.h b/base/message_pump_glib.h
similarity index 95%
rename from base/message_loop/message_pump_glib.h
rename to base/message_pump_glib.h
index e45591b..48afb55 100644
--- a/base/message_loop/message_pump_glib.h
+++ b/base/message_pump_glib.h
@@ -2,12 +2,12 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_GLIB_H_
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_GLIB_H_
+#ifndef BASE_MESSAGE_PUMP_GLIB_H_
+#define BASE_MESSAGE_PUMP_GLIB_H_
 
 #include "base/base_export.h"
 #include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_pump.h"
+#include "base/message_pump.h"
 #include "base/observer_list.h"
 #include "base/time.h"
 
@@ -107,4 +107,4 @@
 
 }  // namespace base
 
-#endif  // BASE_MESSAGE_LOOP_MESSAGE_PUMP_GLIB_H_
+#endif  // BASE_MESSAGE_PUMP_GLIB_H_
diff --git a/base/message_loop/message_pump_glib_unittest.cc b/base/message_pump_glib_unittest.cc
similarity index 77%
rename from base/message_loop/message_pump_glib_unittest.cc
rename to base/message_pump_glib_unittest.cc
index cb30bb0..be11c2f 100644
--- a/base/message_loop/message_pump_glib_unittest.cc
+++ b/base/message_pump_glib_unittest.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/message_loop/message_pump_glib.h"
+#include "base/message_pump_glib.h"
 
 #include <glib.h>
 #include <math.h>
@@ -47,14 +47,14 @@
     // If the queue is empty, block.
     if (events_.empty())
       return -1;
-    TimeDelta delta = events_[0].time - Time::NowFromSystemTime();
+    base::TimeDelta delta = events_[0].time - base::Time::NowFromSystemTime();
     return std::max(0, static_cast<int>(ceil(delta.InMillisecondsF())));
   }
 
   bool HandleCheck() {
     if (events_.empty())
       return false;
-    return events_[0].time <= Time::NowFromSystemTime();
+    return events_[0].time <= base::Time::NowFromSystemTime();
   }
 
   void HandleDispatch() {
@@ -71,16 +71,16 @@
 
   // Adds an event to the queue. When "handled", executes |callback|.
   // delay_ms is relative to the last event if any, or to Now() otherwise.
-  void AddEvent(int delay_ms, const Closure& callback) {
-    AddEventHelper(delay_ms, callback, Closure());
+  void AddEvent(int delay_ms, const base::Closure& callback) {
+    AddEventHelper(delay_ms, callback, base::Closure());
   }
 
   void AddDummyEvent(int delay_ms) {
-    AddEventHelper(delay_ms, Closure(), Closure());
+    AddEventHelper(delay_ms, base::Closure(), base::Closure());
   }
 
-  void AddEventAsTask(int delay_ms, const Closure& task) {
-    AddEventHelper(delay_ms, Closure(), task);
+  void AddEventAsTask(int delay_ms, const base::Closure& task) {
+    AddEventHelper(delay_ms, base::Closure(), task);
   }
 
   void Reset() {
@@ -92,9 +92,9 @@
 
  private:
   struct Event {
-    Time time;
-    Closure callback;
-    Closure task;
+    base::Time time;
+    base::Closure callback;
+    base::Closure task;
   };
 
   struct Source : public GSource {
@@ -102,14 +102,14 @@
   };
 
   void AddEventHelper(
-      int delay_ms, const Closure& callback, const Closure& task) {
-    Time last_time;
+      int delay_ms, const base::Closure& callback, const base::Closure& task) {
+    base::Time last_time;
     if (!events_.empty())
       last_time = (events_.end()-1)->time;
     else
-      last_time = Time::NowFromSystemTime();
+      last_time = base::Time::NowFromSystemTime();
 
-    Time future = last_time + TimeDelta::FromMilliseconds(delay_ms);
+    base::Time future = last_time + base::TimeDelta::FromMilliseconds(delay_ms);
     EventInjector::Event event = {future, callback, task};
     events_.push_back(event);
   }
@@ -155,7 +155,7 @@
 
 // Posts a task on the current message loop.
 void PostMessageLoopTask(const tracked_objects::Location& from_here,
-                         const Closure& task) {
+                         const base::Closure& task) {
   MessageLoop::current()->PostTask(from_here, task);
 }
 
@@ -209,24 +209,24 @@
   // If changes cause this test to fail, it is reasonable to change it, but
   // TestWorkWhileWaitingForEvents and TestEventsWhileWaitingForWork have to be
   // changed accordingly, otherwise they can become flaky.
-  injector()->AddEventAsTask(0, Bind(&DoNothing));
-  Closure check_task =
-      Bind(&ExpectProcessedEvents, Unretained(injector()), 2);
-  Closure posted_task =
-      Bind(&PostMessageLoopTask, FROM_HERE, check_task);
+  injector()->AddEventAsTask(0, base::Bind(&base::DoNothing));
+  base::Closure check_task =
+      base::Bind(&ExpectProcessedEvents, base::Unretained(injector()), 2);
+  base::Closure posted_task =
+      base::Bind(&PostMessageLoopTask, FROM_HERE, check_task);
   injector()->AddEventAsTask(0, posted_task);
-  injector()->AddEventAsTask(0, Bind(&DoNothing));
+  injector()->AddEventAsTask(0, base::Bind(&base::DoNothing));
   injector()->AddEvent(0, MessageLoop::QuitWhenIdleClosure());
   loop()->Run();
   EXPECT_EQ(4, injector()->processed_events());
 
   injector()->Reset();
-  injector()->AddEventAsTask(0, Bind(&DoNothing));
+  injector()->AddEventAsTask(0, base::Bind(&base::DoNothing));
   check_task =
-      Bind(&ExpectProcessedEvents, Unretained(injector()), 2);
-  posted_task = Bind(&PostMessageLoopTask, FROM_HERE, check_task);
+      base::Bind(&ExpectProcessedEvents, base::Unretained(injector()), 2);
+  posted_task = base::Bind(&PostMessageLoopTask, FROM_HERE, check_task);
   injector()->AddEventAsTask(0, posted_task);
-  injector()->AddEventAsTask(10, Bind(&DoNothing));
+  injector()->AddEventAsTask(10, base::Bind(&base::DoNothing));
   injector()->AddEvent(0, MessageLoop::QuitWhenIdleClosure());
   loop()->Run();
   EXPECT_EQ(4, injector()->processed_events());
@@ -237,13 +237,13 @@
   // Tests that we process tasks while waiting for new events.
   // The event queue is empty at first.
   for (int i = 0; i < 10; ++i) {
-    loop()->PostTask(FROM_HERE, Bind(&IncrementInt, &task_count));
+    loop()->PostTask(FROM_HERE, base::Bind(&IncrementInt, &task_count));
   }
   // After all the previous tasks have executed, enqueue an event that will
   // quit.
   loop()->PostTask(
       FROM_HERE,
-      Bind(&EventInjector::AddEvent, Unretained(injector()), 0,
+      base::Bind(&EventInjector::AddEvent, base::Unretained(injector()), 0,
                  MessageLoop::QuitWhenIdleClosure()));
   loop()->Run();
   ASSERT_EQ(10, task_count);
@@ -255,8 +255,8 @@
   for (int i = 0; i < 10; ++i) {
     loop()->PostDelayedTask(
         FROM_HERE,
-        Bind(&IncrementInt, &task_count),
-        TimeDelta::FromMilliseconds(10*i));
+        base::Bind(&IncrementInt, &task_count),
+        base::TimeDelta::FromMilliseconds(10*i));
   }
   // After all the previous tasks have executed, enqueue an event that will
   // quit.
@@ -264,9 +264,9 @@
   // That is verified in message_loop_unittest.cc.
   loop()->PostDelayedTask(
       FROM_HERE,
-      Bind(&EventInjector::AddEvent, Unretained(injector()), 10,
+      base::Bind(&EventInjector::AddEvent, base::Unretained(injector()), 10,
                  MessageLoop::QuitWhenIdleClosure()),
-      TimeDelta::FromMilliseconds(150));
+      base::TimeDelta::FromMilliseconds(150));
   loop()->Run();
   ASSERT_EQ(10, task_count);
   EXPECT_EQ(1, injector()->processed_events());
@@ -281,10 +281,10 @@
   // After all the events have been processed, post a task that will check that
   // the events have been processed (note: the task executes after the event
   // that posted it has been handled, so we expect 11 at that point).
-  Closure check_task =
-      Bind(&ExpectProcessedEvents, Unretained(injector()), 11);
-  Closure posted_task =
-      Bind(&PostMessageLoopTask, FROM_HERE, check_task);
+  base::Closure check_task =
+      base::Bind(&ExpectProcessedEvents, base::Unretained(injector()), 11);
+  base::Closure posted_task =
+      base::Bind(&PostMessageLoopTask, FROM_HERE, check_task);
   injector()->AddEventAsTask(10, posted_task);
 
   // And then quit (relies on the condition tested by TestEventTaskInterleave).
@@ -299,7 +299,7 @@
 // This class is a helper for the concurrent events / posted tasks test below.
 // It will quit the main loop once enough tasks and events have been processed,
 // while making sure there is always work to do and events in the queue.
-class ConcurrentHelper : public RefCounted<ConcurrentHelper>  {
+class ConcurrentHelper : public base::RefCounted<ConcurrentHelper>  {
  public:
   explicit ConcurrentHelper(EventInjector* injector)
       : injector_(injector),
@@ -315,7 +315,7 @@
         MessageLoop::current()->QuitWhenIdle();
     } else {
       MessageLoop::current()->PostTask(
-          FROM_HERE, Bind(&ConcurrentHelper::FromTask, this));
+          FROM_HERE, base::Bind(&ConcurrentHelper::FromTask, this));
     }
   }
 
@@ -327,7 +327,7 @@
         MessageLoop::current()->QuitWhenIdle();
     } else {
       injector_->AddEventAsTask(
-          0, Bind(&ConcurrentHelper::FromEvent, this));
+          0, base::Bind(&ConcurrentHelper::FromEvent, this));
     }
   }
 
@@ -335,7 +335,7 @@
   int task_count() const { return task_count_; }
 
  private:
-  friend class RefCounted<ConcurrentHelper>;
+  friend class base::RefCounted<ConcurrentHelper>;
 
   ~ConcurrentHelper() {}
 
@@ -360,15 +360,15 @@
   // Add 2 events to the queue to make sure it is always full (when we remove
   // the event before processing it).
   injector()->AddEventAsTask(
-      0, Bind(&ConcurrentHelper::FromEvent, helper.get()));
+      0, base::Bind(&ConcurrentHelper::FromEvent, helper.get()));
   injector()->AddEventAsTask(
-      0, Bind(&ConcurrentHelper::FromEvent, helper.get()));
+      0, base::Bind(&ConcurrentHelper::FromEvent, helper.get()));
 
   // Similarly post 2 tasks.
   loop()->PostTask(
-      FROM_HERE, Bind(&ConcurrentHelper::FromTask, helper.get()));
+      FROM_HERE, base::Bind(&ConcurrentHelper::FromTask, helper.get()));
   loop()->PostTask(
-      FROM_HERE, Bind(&ConcurrentHelper::FromTask, helper.get()));
+      FROM_HERE, base::Bind(&ConcurrentHelper::FromTask, helper.get()));
 
   loop()->Run();
   EXPECT_EQ(0, helper->event_count());
@@ -385,8 +385,8 @@
   injector->AddEvent(0, MessageLoop::QuitWhenIdleClosure());
 
   // Post a couple of dummy tasks
-  MessageLoop::current()->PostTask(FROM_HERE, Bind(&DoNothing));
-  MessageLoop::current()->PostTask(FROM_HERE, Bind(&DoNothing));
+  MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&base::DoNothing));
+  MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&base::DoNothing));
 
   // Drain the events
   while (g_main_context_pending(NULL)) {
@@ -400,7 +400,7 @@
   // Tests that draining events using GLib works.
   loop()->PostTask(
       FROM_HERE,
-      Bind(&AddEventsAndDrainGLib, Unretained(injector())));
+      base::Bind(&AddEventsAndDrainGLib, base::Unretained(injector())));
   loop()->Run();
 
   EXPECT_EQ(3, injector()->processed_events());
@@ -418,8 +418,8 @@
   injector->AddEvent(0, MessageLoop::QuitWhenIdleClosure());
 
   // Post a couple of dummy tasks
-  MessageLoop::current()->PostTask(FROM_HERE, Bind(&DoNothing));
-  MessageLoop::current()->PostTask(FROM_HERE, Bind(&DoNothing));
+  MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&base::DoNothing));
+  MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&base::DoNothing));
 
   // Drain the events
   while (gtk_events_pending()) {
@@ -435,7 +435,7 @@
   // Tests that draining events using Gtk works.
   loop()->PostTask(
       FROM_HERE,
-      Bind(&AddEventsAndDrainGtk, Unretained(injector())));
+      base::Bind(&AddEventsAndDrainGtk, base::Unretained(injector())));
   loop()->Run();
 
   EXPECT_EQ(3, injector()->processed_events());
@@ -445,7 +445,7 @@
 namespace {
 
 // Helper class that lets us run the GLib message loop.
-class GLibLoopRunner : public RefCounted<GLibLoopRunner> {
+class GLibLoopRunner : public base::RefCounted<GLibLoopRunner> {
  public:
   GLibLoopRunner() : quit_(false) { }
 
@@ -476,7 +476,7 @@
   }
 
  private:
-  friend class RefCounted<GLibLoopRunner>;
+  friend class base::RefCounted<GLibLoopRunner>;
 
   ~GLibLoopRunner() {}
 
@@ -494,21 +494,21 @@
   injector->AddDummyEvent(0);
   // Post a couple of dummy tasks
   MessageLoop::current()->PostTask(
-      FROM_HERE, Bind(&IncrementInt, &task_count));
+      FROM_HERE, base::Bind(&IncrementInt, &task_count));
   MessageLoop::current()->PostTask(
-      FROM_HERE, Bind(&IncrementInt, &task_count));
+      FROM_HERE, base::Bind(&IncrementInt, &task_count));
   // Delayed events
   injector->AddDummyEvent(10);
   injector->AddDummyEvent(10);
   // Delayed work
   MessageLoop::current()->PostDelayedTask(
       FROM_HERE,
-      Bind(&IncrementInt, &task_count),
-      TimeDelta::FromMilliseconds(30));
+      base::Bind(&IncrementInt, &task_count),
+      base::TimeDelta::FromMilliseconds(30));
   MessageLoop::current()->PostDelayedTask(
       FROM_HERE,
-      Bind(&GLibLoopRunner::Quit, runner.get()),
-      TimeDelta::FromMilliseconds(40));
+      base::Bind(&GLibLoopRunner::Quit, runner.get()),
+      base::TimeDelta::FromMilliseconds(40));
 
   // Run a nested, straight GLib message loop.
   runner->RunGLib();
@@ -529,21 +529,21 @@
   injector->AddDummyEvent(0);
   // Post a couple of dummy tasks
   MessageLoop::current()->PostTask(
-      FROM_HERE, Bind(&IncrementInt, &task_count));
+      FROM_HERE, base::Bind(&IncrementInt, &task_count));
   MessageLoop::current()->PostTask(
-      FROM_HERE, Bind(&IncrementInt, &task_count));
+      FROM_HERE, base::Bind(&IncrementInt, &task_count));
   // Delayed events
   injector->AddDummyEvent(10);
   injector->AddDummyEvent(10);
   // Delayed work
   MessageLoop::current()->PostDelayedTask(
       FROM_HERE,
-      Bind(&IncrementInt, &task_count),
-      TimeDelta::FromMilliseconds(30));
+      base::Bind(&IncrementInt, &task_count),
+      base::TimeDelta::FromMilliseconds(30));
   MessageLoop::current()->PostDelayedTask(
       FROM_HERE,
-      Bind(&GLibLoopRunner::Quit, runner.get()),
-      TimeDelta::FromMilliseconds(40));
+      base::Bind(&GLibLoopRunner::Quit, runner.get()),
+      base::TimeDelta::FromMilliseconds(40));
 
   // Run a nested, straight Gtk message loop.
   runner->RunLoop();
@@ -562,7 +562,7 @@
   // between events and posted tasks.
   loop()->PostTask(
       FROM_HERE,
-      Bind(&TestGLibLoopInternal, Unretained(injector())));
+      base::Bind(&TestGLibLoopInternal, base::Unretained(injector())));
   loop()->Run();
 }
 
@@ -573,7 +573,7 @@
   // between events and posted tasks.
   loop()->PostTask(
       FROM_HERE,
-      Bind(&TestGtkLoopInternal, Unretained(injector())));
+      base::Bind(&TestGtkLoopInternal, base::Unretained(injector())));
   loop()->Run();
 }
 
diff --git a/base/message_loop/message_pump_gtk.cc b/base/message_pump_gtk.cc
similarity index 98%
rename from base/message_loop/message_pump_gtk.cc
rename to base/message_pump_gtk.cc
index 8fa8cf2..780b4d8 100644
--- a/base/message_loop/message_pump_gtk.cc
+++ b/base/message_pump_gtk.cc
@@ -2,15 +2,13 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/message_loop/message_pump_gtk.h"
+#include "base/message_pump_gtk.h"
 
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 
-#include "base/debug/trace_event.h"
 #include "base/profiler/scoped_profile.h"
-
-namespace base {
+#include "base/debug/trace_event.h"
 
 namespace {
 
@@ -59,7 +57,9 @@
   }
 }
 
-}  // namespace
+}
+
+namespace base {
 
 MessagePumpGtk::MessagePumpGtk() : MessagePumpGlib() {
   gdk_event_handler_set(&EventDispatcher, this, NULL);
diff --git a/base/message_loop/message_pump_gtk.h b/base/message_pump_gtk.h
similarity index 91%
rename from base/message_loop/message_pump_gtk.h
rename to base/message_pump_gtk.h
index e22e04f..ba5cff1 100644
--- a/base/message_loop/message_pump_gtk.h
+++ b/base/message_pump_gtk.h
@@ -2,10 +2,10 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_
+#ifndef BASE_MESSAGE_PUMP_GTK_H_
+#define BASE_MESSAGE_PUMP_GTK_H_
 
-#include "base/message_loop/message_pump_glib.h"
+#include "base/message_pump_glib.h"
 
 typedef union _GdkEvent GdkEvent;
 typedef struct _XDisplay Display;
@@ -73,4 +73,4 @@
 
 }  // namespace base
 
-#endif  // BASE_MESSAGE_LOOP_MESSAGE_PUMP_GTK_H_
+#endif  // BASE_MESSAGE_PUMP_GTK_H_
diff --git a/base/message_loop/message_pump_libevent.cc b/base/message_pump_libevent.cc
similarity index 96%
rename from base/message_loop/message_pump_libevent.cc
rename to base/message_pump_libevent.cc
index 8de0db2..364f44a 100644
--- a/base/message_loop/message_pump_libevent.cc
+++ b/base/message_pump_libevent.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/message_loop/message_pump_libevent.h"
+#include "base/message_pump_libevent.h"
 
 #include <errno.h>
 #include <fcntl.h>
@@ -11,6 +11,9 @@
 #include "base/auto_reset.h"
 #include "base/compiler_specific.h"
 #include "base/logging.h"
+#if defined(OS_MACOSX)
+#include "base/mac/scoped_nsautorelease_pool.h"
+#endif
 #include "base/memory/scoped_ptr.h"
 #include "base/observer_list.h"
 #include "base/posix/eintr_wrapper.h"
@@ -218,7 +221,7 @@
 // Reentrant!
 void MessagePumpLibevent::Run(Delegate* delegate) {
   DCHECK(keep_running_) << "Quit must have been called outside of Run!";
-  AutoReset<bool> auto_reset_in_run(&in_run_, true);
+  base::AutoReset<bool> auto_reset_in_run(&in_run_, true);
 
   // event_base_loopexit() + EVLOOP_ONCE is leaky, see http://crbug.com/25641.
   // Instead, make our own timer and reuse it on each call to event_base_loop().
@@ -340,7 +343,7 @@
 // static
 void MessagePumpLibevent::OnLibeventNotification(int fd, short flags,
                                                  void* context) {
-  WeakPtr<FileDescriptorWatcher> controller =
+  base::WeakPtr<FileDescriptorWatcher> controller =
       static_cast<FileDescriptorWatcher*>(context)->weak_factory_.GetWeakPtr();
   DCHECK(controller.get());
 
@@ -360,7 +363,8 @@
 // Called if a byte is received on the wakeup pipe.
 // static
 void MessagePumpLibevent::OnWakeup(int socket, short flags, void* context) {
-  MessagePumpLibevent* that = static_cast<MessagePumpLibevent*>(context);
+  base::MessagePumpLibevent* that =
+              static_cast<base::MessagePumpLibevent*>(context);
   DCHECK(that->wakeup_pipe_out_ == socket);
 
   // Remove and discard the wakeup byte.
diff --git a/base/message_loop/message_pump_libevent.h b/base/message_pump_libevent.h
similarity index 95%
rename from base/message_loop/message_pump_libevent.h
rename to base/message_pump_libevent.h
index a54ef88..90e8510 100644
--- a/base/message_loop/message_pump_libevent.h
+++ b/base/message_pump_libevent.h
@@ -2,13 +2,13 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_
+#ifndef BASE_MESSAGE_PUMP_LIBEVENT_H_
+#define BASE_MESSAGE_PUMP_LIBEVENT_H_
 
 #include "base/basictypes.h"
 #include "base/compiler_specific.h"
 #include "base/memory/weak_ptr.h"
-#include "base/message_loop/message_pump.h"
+#include "base/message_pump.h"
 #include "base/observer_list.h"
 #include "base/threading/thread_checker.h"
 #include "base/time.h"
@@ -86,7 +86,7 @@
     event* event_;
     MessagePumpLibevent* pump_;
     Watcher* watcher_;
-    WeakPtrFactory<FileDescriptorWatcher> weak_factory_;
+    base::WeakPtrFactory<FileDescriptorWatcher> weak_factory_;
 
     DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher);
   };
@@ -176,4 +176,4 @@
 
 }  // namespace base
 
-#endif  // BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_
+#endif  // BASE_MESSAGE_PUMP_LIBEVENT_H_
diff --git a/base/message_loop/message_pump_libevent_unittest.cc b/base/message_pump_libevent_unittest.cc
similarity index 97%
rename from base/message_loop/message_pump_libevent_unittest.cc
rename to base/message_pump_libevent_unittest.cc
index 657ac7d..cd423af 100644
--- a/base/message_loop/message_pump_libevent_unittest.cc
+++ b/base/message_pump_libevent_unittest.cc
@@ -2,11 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/message_loop/message_pump_libevent.h"
+#include "base/message_pump_libevent.h"
 
 #include <unistd.h>
 
-#include "base/message_loop/message_loop.h"
+#include "base/message_loop.h"
 #include "base/posix/eintr_wrapper.h"
 #include "base/threading/thread.h"
 #include "testing/gtest/include/gtest/gtest.h"
diff --git a/base/message_loop/message_pump_observer.h b/base/message_pump_observer.h
similarity index 90%
rename from base/message_loop/message_pump_observer.h
rename to base/message_pump_observer.h
index cb46fa3..a7d2aa7 100644
--- a/base/message_loop/message_pump_observer.h
+++ b/base/message_pump_observer.h
@@ -2,8 +2,8 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_OBSERVER_H
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_OBSERVER_H
+#ifndef BASE_MESSAGE_PUMP_OBSERVER_H
+#define BASE_MESSAGE_PUMP_OBSERVER_H
 
 #include "base/base_export.h"
 #include "base/event_types.h"
@@ -44,4 +44,4 @@
 
 }  // namespace base
 
-#endif  // BASE_MESSAGE_LOOP_MESSAGE_PUMP_OBSERVER_H
+#endif  // BASE_MESSAGE_PUMP_OBSERVER_VIEWS_H
diff --git a/base/message_loop/message_pump_ozone.cc b/base/message_pump_ozone.cc
similarity index 92%
rename from base/message_loop/message_pump_ozone.cc
rename to base/message_pump_ozone.cc
index 5c0bf83..ca7f45d 100644
--- a/base/message_loop/message_pump_ozone.cc
+++ b/base/message_pump_ozone.cc
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "base/message_loop/message_pump_ozone.h"
+#include "base/message_pump_ozone.h"
 
 #include "base/logging.h"
 #include "base/message_loop.h"
@@ -43,7 +43,7 @@
   dispatcher_.pop_back();
 }
 
-bool MessagePumpOzone::Dispatch(const NativeEvent& dev) {
+bool MessagePumpOzone::Dispatch(const base::NativeEvent& dev) {
   if (dispatcher_.size() > 0)
     return dispatcher_[0]->Dispatch(dev);
   else
diff --git a/base/message_loop/message_pump_ozone.h b/base/message_pump_ozone.h
similarity index 78%
rename from base/message_loop/message_pump_ozone.h
rename to base/message_pump_ozone.h
index de75ab4..8fb2f1d 100644
--- a/base/message_loop/message_pump_ozone.h
+++ b/base/message_pump_ozone.h
@@ -2,14 +2,14 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_OZONE_H_
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_OZONE_H_
+#ifndef BASE_MESSAGE_PUMP_OZONE_H_
+#define BASE_MESSAGE_PUMP_OZONE_H_
 
 #include "base/memory/scoped_ptr.h"
 #include "base/memory/scoped_vector.h"
-#include "base/message_loop/message_pump_dispatcher.h"
-#include "base/message_loop/message_pump_libevent.h"
-#include "base/message_loop/message_pump_observer.h"
+#include "base/message_pump_dispatcher.h"
+#include "base/message_pump_libevent.h"
+#include "base/message_pump_observer.h"
 #include "base/observer_list.h"
 
 namespace base {
@@ -36,7 +36,7 @@
   void RemoveObserver(MessagePumpObserver* observer);
 
   // Overridden from MessagePumpDispatcher.
-  virtual bool Dispatch(const NativeEvent& event) OVERRIDE;
+  virtual bool Dispatch(const base::NativeEvent& event) OVERRIDE;
 
  private:
   virtual ~MessagePumpOzone();
@@ -49,4 +49,4 @@
 
 }  // namespace base
 
-#endif  // BASE_MESSAGE_LOOP_MESSAGE_PUMP_OZONE_H_
+#endif  // BASE_MESSAGE_PUMP_OZONE_H_
diff --git a/base/test/test_support_android.cc b/base/test/test_support_android.cc
index 5180333..64da18a 100644
--- a/base/test/test_support_android.cc
+++ b/base/test/test_support_android.cc
@@ -9,8 +9,8 @@
 #include "base/files/file_path.h"
 #include "base/logging.h"
 #include "base/memory/singleton.h"
-#include "base/message_loop/message_loop.h"
-#include "base/message_loop/message_pump_android.h"
+#include "base/message_loop.h"
+#include "base/message_pump_android.h"
 #include "base/path_service.h"
 #include "base/synchronization/waitable_event.h"