C++ Readability Review for caitkp

BUG=10927483

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

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


CrOS-Libchrome-Original-Commit: abdd66eb4bdd81f8a5e64cc0d4d7810b70027afa
diff --git a/base/callback_list.h b/base/callback_list.h
index ead92ea..cb44c25 100644
--- a/base/callback_list.h
+++ b/base/callback_list.h
@@ -45,6 +45,8 @@
 //   }
 //
 //   base::CallbackList<void(const Foo&)> callback_list_;
+//
+//   DISALLOW_COPY_AND_ASSIGN(MyWidget);
 // };
 //
 //
@@ -67,6 +69,8 @@
 //
 //   scoped_ptr<base::CallbackList<void(const Foo&)>::Subscription>
 //       foo_subscription_;
+//
+//   DISALLOW_COPY_AND_ASSIGN(MyWidgetListener);
 // };
 
 namespace base {
@@ -81,11 +85,12 @@
     Subscription(CallbackListBase<CallbackType>* list,
                  typename std::list<CallbackType>::iterator iter)
         : list_(list),
-          iter_(iter) {}
+          iter_(iter) {
+    }
 
     ~Subscription() {
       if (list_->active_iterator_count_)
-        (*iter_).Reset();
+        iter_->Reset();
       else
         list_->callbacks_.erase(iter_);
     }
@@ -145,8 +150,7 @@
     typename std::list<CallbackType>::iterator list_iter_;
   };
 
-  CallbackListBase()
-      : active_iterator_count_(0) {}
+  CallbackListBase() : active_iterator_count_(0) {}
 
   ~CallbackListBase() {
     DCHECK_EQ(0, active_iterator_count_);
@@ -194,7 +198,7 @@
     internal::CallbackListBase<CallbackType>::Iterator it =
         this->GetIterator();
     CallbackType* cb;
-    while((cb = it.GetNext()) != NULL) {
+    while ((cb = it.GetNext()) != NULL) {
       cb->Run();
     }
   }
@@ -205,8 +209,7 @@
 
 template <typename A1>
 class CallbackList<void(A1)>
-    : public internal::CallbackListBase<
-        Callback<void(A1)> > {
+    : public internal::CallbackListBase<Callback<void(A1)> > {
  public:
   typedef Callback<void(A1)> CallbackType;
 
@@ -216,7 +219,7 @@
     typename internal::CallbackListBase<CallbackType>::Iterator it =
         this->GetIterator();
     CallbackType* cb;
-    while((cb = it.GetNext()) != NULL) {
+    while ((cb = it.GetNext()) != NULL) {
       cb->Run(a1);
     }
   }
@@ -227,8 +230,7 @@
 
 template <typename A1, typename A2>
 class CallbackList<void(A1, A2)>
-    : public internal::CallbackListBase<
-        Callback<void(A1, A2)> > {
+    : public internal::CallbackListBase<Callback<void(A1, A2)> > {
  public:
   typedef Callback<void(A1, A2)> CallbackType;
 
@@ -239,7 +241,7 @@
     typename internal::CallbackListBase<CallbackType>::Iterator it =
         this->GetIterator();
     CallbackType* cb;
-    while((cb = it.GetNext()) != NULL) {
+    while ((cb = it.GetNext()) != NULL) {
       cb->Run(a1, a2);
     }
   }
@@ -250,8 +252,7 @@
 
 template <typename A1, typename A2, typename A3>
 class CallbackList<void(A1, A2, A3)>
-    : public internal::CallbackListBase<
-        Callback<void(A1, A2, A3)> > {
+    : public internal::CallbackListBase<Callback<void(A1, A2, A3)> > {
  public:
   typedef Callback<void(A1, A2, A3)> CallbackType;
 
@@ -263,7 +264,7 @@
     typename internal::CallbackListBase<CallbackType>::Iterator it =
         this->GetIterator();
     CallbackType* cb;
-    while((cb = it.GetNext()) != NULL) {
+    while ((cb = it.GetNext()) != NULL) {
       cb->Run(a1, a2, a3);
     }
   }
@@ -274,8 +275,7 @@
 
 template <typename A1, typename A2, typename A3, typename A4>
 class CallbackList<void(A1, A2, A3, A4)>
-    : public internal::CallbackListBase<
-        Callback<void(A1, A2, A3, A4)> > {
+    : public internal::CallbackListBase<Callback<void(A1, A2, A3, A4)> > {
  public:
   typedef Callback<void(A1, A2, A3, A4)> CallbackType;
 
@@ -288,7 +288,7 @@
     typename internal::CallbackListBase<CallbackType>::Iterator it =
         this->GetIterator();
     CallbackType* cb;
-    while((cb = it.GetNext()) != NULL) {
+    while ((cb = it.GetNext()) != NULL) {
       cb->Run(a1, a2, a3, a4);
     }
   }
@@ -299,8 +299,7 @@
 
 template <typename A1, typename A2, typename A3, typename A4, typename A5>
 class CallbackList<void(A1, A2, A3, A4, A5)>
-    : public internal::CallbackListBase<
-        Callback<void(A1, A2, A3, A4, A5)> > {
+    : public internal::CallbackListBase<Callback<void(A1, A2, A3, A4, A5)> > {
  public:
   typedef Callback<void(A1, A2, A3, A4, A5)> CallbackType;
 
@@ -314,7 +313,7 @@
     typename internal::CallbackListBase<CallbackType>::Iterator it =
         this->GetIterator();
     CallbackType* cb;
-    while((cb = it.GetNext()) != NULL) {
+    while ((cb = it.GetNext()) != NULL) {
       cb->Run(a1, a2, a3, a4, a5);
     }
   }
@@ -326,8 +325,8 @@
 template <typename A1, typename A2, typename A3, typename A4, typename A5,
     typename A6>
 class CallbackList<void(A1, A2, A3, A4, A5, A6)>
-    : public internal::CallbackListBase<
-        Callback<void(A1, A2, A3, A4, A5, A6)> > {
+    : public internal::CallbackListBase<Callback<void(A1, A2, A3, A4, A5,
+        A6)> > {
  public:
   typedef Callback<void(A1, A2, A3, A4, A5, A6)> CallbackType;
 
@@ -342,7 +341,7 @@
     typename internal::CallbackListBase<CallbackType>::Iterator it =
         this->GetIterator();
     CallbackType* cb;
-    while((cb = it.GetNext()) != NULL) {
+    while ((cb = it.GetNext()) != NULL) {
       cb->Run(a1, a2, a3, a4, a5, a6);
     }
   }
@@ -354,8 +353,8 @@
 template <typename A1, typename A2, typename A3, typename A4, typename A5,
     typename A6, typename A7>
 class CallbackList<void(A1, A2, A3, A4, A5, A6, A7)>
-    : public internal::CallbackListBase<
-        Callback<void(A1, A2, A3, A4, A5, A6, A7)> > {
+    : public internal::CallbackListBase<Callback<void(A1, A2, A3, A4, A5, A6,
+        A7)> > {
  public:
   typedef Callback<void(A1, A2, A3, A4, A5, A6, A7)> CallbackType;
 
@@ -371,7 +370,7 @@
     typename internal::CallbackListBase<CallbackType>::Iterator it =
         this->GetIterator();
     CallbackType* cb;
-    while((cb = it.GetNext()) != NULL) {
+    while ((cb = it.GetNext()) != NULL) {
       cb->Run(a1, a2, a3, a4, a5, a6, a7);
     }
   }
diff --git a/base/callback_list.h.pump b/base/callback_list.h.pump
index 66295ec..168c70c 100644
--- a/base/callback_list.h.pump
+++ b/base/callback_list.h.pump
@@ -50,6 +50,8 @@
 //   }
 //
 //   base::CallbackList<void(const Foo&)> callback_list_;
+//
+//   DISALLOW_COPY_AND_ASSIGN(MyWidget);
 // };
 //
 //
@@ -72,6 +74,8 @@
 //
 //   scoped_ptr<base::CallbackList<void(const Foo&)>::Subscription>
 //       foo_subscription_;
+//
+//   DISALLOW_COPY_AND_ASSIGN(MyWidgetListener);
 // };
 
 namespace base {
@@ -86,11 +90,12 @@
     Subscription(CallbackListBase<CallbackType>* list,
                  typename std::list<CallbackType>::iterator iter)
         : list_(list),
-          iter_(iter) {}
+          iter_(iter) {
+    }
 
     ~Subscription() {
       if (list_->active_iterator_count_)
-        (*iter_).Reset();
+        iter_->Reset();
       else
         list_->callbacks_.erase(iter_);
     }
@@ -150,8 +155,7 @@
     typename std::list<CallbackType>::iterator list_iter_;
   };
 
-  CallbackListBase()
-      : active_iterator_count_(0) {}
+  CallbackListBase() : active_iterator_count_(0) {}
 
   ~CallbackListBase() {
     DCHECK_EQ(0, active_iterator_count_);
@@ -199,8 +203,7 @@
 ]] $else [[
 template <$for ARG , [[typename A$(ARG)]]>
 class CallbackList<void($for ARG , [[A$(ARG)]])>
-    : public internal::CallbackListBase<
-        Callback<void($for ARG , [[A$(ARG)]])> > {
+    : public internal::CallbackListBase<Callback<void($for ARG , [[A$(ARG)]])> > {
 ]]
 
  public:
@@ -228,7 +231,7 @@
 ]]
 
     CallbackType* cb;
-    while((cb = it.GetNext()) != NULL) {
+    while ((cb = it.GetNext()) != NULL) {
       cb->Run($for ARG , [[a$(ARG)]]);
     }
   }
diff --git a/base/callback_list_unittest.cc b/base/callback_list_unittest.cc
index 4607129..9adbabb 100644
--- a/base/callback_list_unittest.cc
+++ b/base/callback_list_unittest.cc
@@ -20,9 +20,10 @@
   void IncrementTotal() { total_++; }
   void IncrementByMultipleOfScaler(int x) { total_ += x * scaler_; }
 
-  int total_;
+  int total() const { return total_; }
 
  private:
+  int total_;
   int scaler_;
   DISALLOW_COPY_AND_ASSIGN(Listener);
 };
@@ -39,9 +40,10 @@
     removal_subscription_ = sub.Pass();
   }
 
-  int total_;
+  int total() const { return total_; }
 
  private:
+  int total_;
   scoped_ptr<CallbackList<void(void)>::Subscription> removal_subscription_;
   DISALLOW_COPY_AND_ASSIGN(Remover);
 };
@@ -51,7 +53,8 @@
   explicit Adder(CallbackList<void(void)>* cb_reg)
       : added_(false),
         total_(0),
-        cb_reg_(cb_reg) {}
+        cb_reg_(cb_reg) {
+  }
   void AddCallback() {
     if (!added_) {
       added_ = true;
@@ -61,10 +64,13 @@
   }
   void IncrementTotal() { total_++; }
 
-  bool added_;
-  int total_;
+  bool added() const { return added_; }
+
+  int total() const { return total_; }
 
  private:
+  bool added_;
+  int total_;
   CallbackList<void(void)>* cb_reg_;
   scoped_ptr<CallbackList<void(void)>::Subscription> subscription_;
   DISALLOW_COPY_AND_ASSIGN(Adder);
@@ -85,9 +91,10 @@
     value_ = a + b + c + d + e + f;
   }
 
-  int value_;
+  int value() const { return value_; }
 
  private:
+  int value_;
   DISALLOW_COPY_AND_ASSIGN(Summer);
 };
 
@@ -100,42 +107,42 @@
       c1.Add(Bind(&Summer::AddOneParam, Unretained(&s)));
 
   c1.Notify(1);
-  EXPECT_EQ(1, s.value_);
+  EXPECT_EQ(1, s.value());
 
   CallbackList<void(int, int)> c2;
   scoped_ptr<CallbackList<void(int, int)>::Subscription> subscription2 =
       c2.Add(Bind(&Summer::AddTwoParam, Unretained(&s)));
 
   c2.Notify(1, 2);
-  EXPECT_EQ(3, s.value_);
+  EXPECT_EQ(3, s.value());
 
   CallbackList<void(int, int, int)> c3;
   scoped_ptr<CallbackList<void(int, int, int)>::Subscription>
       subscription3 = c3.Add(Bind(&Summer::AddThreeParam, Unretained(&s)));
 
   c3.Notify(1, 2, 3);
-  EXPECT_EQ(6, s.value_);
+  EXPECT_EQ(6, s.value());
 
   CallbackList<void(int, int, int, int)> c4;
   scoped_ptr<CallbackList<void(int, int, int, int)>::Subscription>
       subscription4 = c4.Add(Bind(&Summer::AddFourParam, Unretained(&s)));
 
   c4.Notify(1, 2, 3, 4);
-  EXPECT_EQ(10, s.value_);
+  EXPECT_EQ(10, s.value());
 
   CallbackList<void(int, int, int, int, int)> c5;
   scoped_ptr<CallbackList<void(int, int, int, int, int)>::Subscription>
       subscription5 = c5.Add(Bind(&Summer::AddFiveParam, Unretained(&s)));
 
   c5.Notify(1, 2, 3, 4, 5);
-  EXPECT_EQ(15, s.value_);
+  EXPECT_EQ(15, s.value());
 
   CallbackList<void(int, int, int, int, int, int)> c6;
   scoped_ptr<CallbackList<void(int, int, int, int, int, int)>::Subscription>
       subscription6 = c6.Add(Bind(&Summer::AddSixParam, Unretained(&s)));
 
   c6.Notify(1, 2, 3, 4, 5, 6);
-  EXPECT_EQ(21, s.value_);
+  EXPECT_EQ(21, s.value());
 }
 
 // Sanity check that closures added to the list will be run, and those removed
@@ -154,8 +161,8 @@
 
   cb_reg.Notify();
 
-  EXPECT_EQ(1, a.total_);
-  EXPECT_EQ(1, b.total_);
+  EXPECT_EQ(1, a.total());
+  EXPECT_EQ(1, b.total());
 
   b_subscription.reset();
 
@@ -164,9 +171,9 @@
 
   cb_reg.Notify();
 
-  EXPECT_EQ(2, a.total_);
-  EXPECT_EQ(1, b.total_);
-  EXPECT_EQ(1, c.total_);
+  EXPECT_EQ(2, a.total());
+  EXPECT_EQ(1, b.total());
+  EXPECT_EQ(1, c.total());
 
   a_subscription.reset();
   b_subscription.reset();
@@ -189,8 +196,8 @@
 
   cb_reg.Notify(10);
 
-  EXPECT_EQ(10, a.total_);
-  EXPECT_EQ(-10, b.total_);
+  EXPECT_EQ(10, a.total());
+  EXPECT_EQ(-10, b.total());
 
   b_subscription.reset();
 
@@ -199,9 +206,9 @@
 
   cb_reg.Notify(10);
 
-  EXPECT_EQ(20, a.total_);
-  EXPECT_EQ(-10, b.total_);
-  EXPECT_EQ(10, c.total_);
+  EXPECT_EQ(20, a.total());
+  EXPECT_EQ(-10, b.total());
+  EXPECT_EQ(10, c.total());
 
   a_subscription.reset();
   b_subscription.reset();
@@ -235,18 +242,18 @@
 
   // |remover_1| runs once (and removes itself), |remover_2| runs once (and
   // removes a), |a| never runs, and |b| runs once.
-  EXPECT_EQ(1, remover_1.total_);
-  EXPECT_EQ(1, remover_2.total_);
-  EXPECT_EQ(0, a.total_);
-  EXPECT_EQ(1, b.total_);
+  EXPECT_EQ(1, remover_1.total());
+  EXPECT_EQ(1, remover_2.total());
+  EXPECT_EQ(0, a.total());
+  EXPECT_EQ(1, b.total());
 
   cb_reg.Notify();
 
   // Only |remover_2| and |b| run this time.
-  EXPECT_EQ(1, remover_1.total_);
-  EXPECT_EQ(2, remover_2.total_);
-  EXPECT_EQ(0, a.total_);
-  EXPECT_EQ(2, b.total_);
+  EXPECT_EQ(1, remover_1.total());
+  EXPECT_EQ(2, remover_2.total());
+  EXPECT_EQ(0, a.total());
+  EXPECT_EQ(2, b.total());
 }
 
 // Test that a callback can add another callback to the list durning iteration
@@ -263,14 +270,14 @@
 
   cb_reg.Notify();
 
-  EXPECT_EQ(1, a.total_);
-  EXPECT_EQ(1, b.total_);
-  EXPECT_TRUE(a.added_);
+  EXPECT_EQ(1, a.total());
+  EXPECT_EQ(1, b.total());
+  EXPECT_TRUE(a.added());
 
   cb_reg.Notify();
 
-  EXPECT_EQ(2, a.total_);
-  EXPECT_EQ(2, b.total_);
+  EXPECT_EQ(2, a.total());
+  EXPECT_EQ(2, b.total());
 }
 
 // Sanity check: notifying an empty list is a no-op.