Objects that derive from RefCounted/RefCountedThreadSafe should not have public dtors.

BUG=none
TEST=compiles


Review URL: http://codereview.chromium.org/9997007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131088 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/base/message_loop_proxy_impl.h b/base/message_loop_proxy_impl.h
index 88e1d45..140c244 100644
--- a/base/message_loop_proxy_impl.h
+++ b/base/message_loop_proxy_impl.h
@@ -16,11 +16,8 @@
 // A stock implementation of MessageLoopProxy that is created and managed by a
 // MessageLoop. For now a MessageLoopProxyImpl can only be created as part of a
 // MessageLoop.
-class BASE_EXPORT MessageLoopProxyImpl
-    : public MessageLoopProxy {
+class BASE_EXPORT MessageLoopProxyImpl : public MessageLoopProxy {
  public:
-  virtual ~MessageLoopProxyImpl();
-
   // MessageLoopProxy implementation
   virtual bool PostDelayedTask(const tracked_objects::Location& from_here,
                                const base::Closure& task,
@@ -39,11 +36,17 @@
   virtual bool RunsTasksOnCurrentThread() const OVERRIDE;
 
  protected:
+  virtual ~MessageLoopProxyImpl();
+
   // Override OnDestruct so that we can delete the object on the target message
   // loop if it still exists.
   virtual void OnDestruct() const OVERRIDE;
 
  private:
+  // Allow the MessageLoop to create a MessageLoopProxyImpl.
+  friend class ::MessageLoop;
+  friend class DeleteHelper<MessageLoopProxyImpl>;
+
   MessageLoopProxyImpl();
 
   // Called directly by MessageLoop::~MessageLoop.
@@ -55,9 +58,6 @@
                       base::TimeDelta delay,
                       bool nestable);
 
-  // Allow the messageLoop to create a MessageLoopProxyImpl.
-  friend class ::MessageLoop;
-
   // The lock that protects access to target_message_loop_.
   mutable base::Lock message_loop_lock_;
   MessageLoop* target_message_loop_;
diff --git a/base/message_pump.h b/base/message_pump.h
index d7aaf0c..16941eb 100644
--- a/base/message_pump.h
+++ b/base/message_pump.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -43,7 +43,6 @@
   };
 
   MessagePump();
-  virtual ~MessagePump();
 
   // The Run method is called to enter the message pump's run loop.
   //
@@ -120,6 +119,10 @@
   // cancelling any pending DoDelayedWork callback.  This method may only be
   // used on the thread that called Run.
   virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) = 0;
+
+ protected:
+  virtual ~MessagePump();
+  friend class RefCountedThreadSafe<MessagePump>;
 };
 
 }  // namespace base
diff --git a/base/message_pump_default.h b/base/message_pump_default.h
index c16abcf..4efb1c5 100644
--- a/base/message_pump_default.h
+++ b/base/message_pump_default.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -15,7 +15,6 @@
 class MessagePumpDefault : public MessagePump {
  public:
   MessagePumpDefault();
-  virtual ~MessagePumpDefault() {}
 
   // MessagePump methods:
   virtual void Run(Delegate* delegate) OVERRIDE;
@@ -23,6 +22,9 @@
   virtual void ScheduleWork() OVERRIDE;
   virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE;
 
+ protected:
+  virtual ~MessagePumpDefault() {}
+
  private:
   // This flag is set to false when Run should return.
   bool keep_running_;
diff --git a/base/message_pump_libevent.h b/base/message_pump_libevent.h
index b12af70..e477036 100644
--- a/base/message_pump_libevent.h
+++ b/base/message_pump_libevent.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -100,7 +100,6 @@
   };
 
   MessagePumpLibevent();
-  virtual ~MessagePumpLibevent();
 
   // Have the current thread's message loop watch for a a situation in which
   // reading/writing to the FD can be performed without blocking.
@@ -129,6 +128,9 @@
   virtual void ScheduleWork() OVERRIDE;
   virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE;
 
+ protected:
+  virtual ~MessagePumpLibevent();
+
  private:
   friend class MessagePumpLibeventTest;
 
diff --git a/base/message_pump_mac.h b/base/message_pump_mac.h
index baf9071..3d1ac35 100644
--- a/base/message_pump_mac.h
+++ b/base/message_pump_mac.h
@@ -59,7 +59,6 @@
   friend class MessagePumpScopedAutoreleasePool;
  public:
   MessagePumpCFRunLoopBase();
-  virtual ~MessagePumpCFRunLoopBase();
 
   // Subclasses should implement the work they need to do in MessagePump::Run
   // in the DoRun method.  MessagePumpCFRunLoopBase::Run calls DoRun directly.
@@ -72,6 +71,8 @@
   virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE;
 
  protected:
+  virtual ~MessagePumpCFRunLoopBase();
+
   // Accessors for private data members to be used by subclasses.
   CFRunLoopRef run_loop() const { return run_loop_; }
   int nesting_level() const { return nesting_level_; }
@@ -194,6 +195,9 @@
   virtual void DoRun(Delegate* delegate) OVERRIDE;
   virtual void Quit() OVERRIDE;
 
+ protected:
+  virtual ~MessagePumpCFRunLoop();
+
  private:
   virtual void EnterExitRunLoop(CFRunLoopActivity activity) OVERRIDE;
 
@@ -208,11 +212,13 @@
 class MessagePumpNSRunLoop : public MessagePumpCFRunLoopBase {
  public:
   BASE_EXPORT MessagePumpNSRunLoop();
-  virtual ~MessagePumpNSRunLoop();
 
   virtual void DoRun(Delegate* delegate) OVERRIDE;
   virtual void Quit() OVERRIDE;
 
+ protected:
+  virtual ~MessagePumpNSRunLoop();
+
  private:
   // A source that doesn't do anything but provide something signalable
   // attached to the run loop.  This source will be signalled when Quit
@@ -232,6 +238,9 @@
   virtual void DoRun(Delegate* delegate) OVERRIDE;
   virtual void Quit() OVERRIDE;
 
+ protected:
+  virtual ~MessagePumpNSApplication();
+
  private:
   // False after Quit is called.
   bool keep_running_;
@@ -250,6 +259,8 @@
   MessagePumpCrApplication();
 
  protected:
+  virtual ~MessagePumpCrApplication() {}
+
   // Returns nil if NSApp is currently in the middle of calling
   // -sendEvent.  Requires NSApp implementing CrAppProtocol.
   virtual NSAutoreleasePool* CreateAutoreleasePool() OVERRIDE;
diff --git a/base/message_pump_mac.mm b/base/message_pump_mac.mm
index 0e12b74..e7c422ba 100644
--- a/base/message_pump_mac.mm
+++ b/base/message_pump_mac.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -460,6 +460,8 @@
     : quit_pending_(false) {
 }
 
+MessagePumpCFRunLoop::~MessagePumpCFRunLoop() {}
+
 // Called by MessagePumpCFRunLoopBase::DoRun.  If other CFRunLoopRun loops were
 // running lower on the run loop thread's stack when this object was created,
 // the same number of CFRunLoopRun loops must be running for the outermost call
@@ -542,6 +544,8 @@
       running_own_loop_(false) {
 }
 
+MessagePumpNSApplication::~MessagePumpNSApplication() {}
+
 void MessagePumpNSApplication::DoRun(Delegate* delegate) {
   bool last_running_own_loop_ = running_own_loop_;
 
diff --git a/base/sequenced_task_runner.h b/base/sequenced_task_runner.h
index f44b622e..0db9128f 100644
--- a/base/sequenced_task_runner.h
+++ b/base/sequenced_task_runner.h
@@ -143,7 +143,10 @@
             this, from_here, object);
   }
 
-private:
+ protected:
+  virtual ~SequencedTaskRunner() {}
+
+ private:
   template <class T, class R> friend class subtle::DeleteHelperInternal;
   template <class T, class R> friend class subtle::ReleaseHelperInternal;
 
diff --git a/base/single_thread_task_runner.h b/base/single_thread_task_runner.h
index 93f694e..c87e5f7 100644
--- a/base/single_thread_task_runner.h
+++ b/base/single_thread_task_runner.h
@@ -26,11 +26,14 @@
 //     order that must be run only from the thread the
 //     SingleThreadTaskRunner was created on.
 class BASE_EXPORT SingleThreadTaskRunner : public SequencedTaskRunner {
-public:
+ public:
   // A more explicit alias to RunsTasksOnCurrentThread().
   bool BelongsToCurrentThread() const {
     return RunsTasksOnCurrentThread();
   }
+
+ protected:
+  virtual ~SingleThreadTaskRunner() {}
 };
 
 }  // namespace base
diff --git a/base/synchronization/waitable_event.h b/base/synchronization/waitable_event.h
index 6c91701..018f318 100644
--- a/base/synchronization/waitable_event.h
+++ b/base/synchronization/waitable_event.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -145,7 +145,6 @@
       public RefCountedThreadSafe<WaitableEventKernel> {
    public:
     WaitableEventKernel(bool manual_reset, bool initially_signaled);
-    virtual ~WaitableEventKernel();
 
     bool Dequeue(Waiter* waiter, void* tag);
 
@@ -153,6 +152,10 @@
     const bool manual_reset_;
     bool signaled_;
     std::list<Waiter*> waiters_;
+
+   private:
+    friend class RefCountedThreadSafe<WaitableEventKernel>;
+    ~WaitableEventKernel();
   };
 
   typedef std::pair<WaitableEvent*, size_t> WaiterAndIndex;
diff --git a/base/synchronization/waitable_event_watcher_posix.cc b/base/synchronization/waitable_event_watcher_posix.cc
index 3b0ba70..5a17999 100644
--- a/base/synchronization/waitable_event_watcher_posix.cc
+++ b/base/synchronization/waitable_event_watcher_posix.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
@@ -43,8 +43,13 @@
   }
 
  private:
+  friend class RefCountedThreadSafe<Flag>;
+  ~Flag() {}
+
   mutable Lock lock_;
   bool flag_;
+
+  DISALLOW_COPY_AND_ASSIGN(Flag);
 };
 
 // -----------------------------------------------------------------------------
diff --git a/base/threading/worker_pool_posix.h b/base/threading/worker_pool_posix.h
index f56582d..eca113a 100644
--- a/base/threading/worker_pool_posix.h
+++ b/base/threading/worker_pool_posix.h
@@ -53,7 +53,6 @@
   // |idle_seconds_before_exit|.
   PosixDynamicThreadPool(const std::string& name_prefix,
                          int idle_seconds_before_exit);
-  ~PosixDynamicThreadPool();
 
   // Indicates that the thread pool is going away.  Stops handing out tasks to
   // worker threads.  Wakes up all the idle threads to let them exit.
@@ -68,8 +67,11 @@
   PendingTask WaitForTask();
 
  private:
+  friend class RefCountedThreadSafe<PosixDynamicThreadPool>;
   friend class PosixDynamicThreadPoolPeer;
 
+  ~PosixDynamicThreadPool();
+
   // Adds pending_task to the thread pool.  This function will clear
   // |pending_task->task|.
   void AddTask(PendingTask* pending_task);