Bug 1048252 - Fix some bad implicit constructors in chromium IPC code; r=bent
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 05 Aug 2014 09:37:28 -0400
changeset 198057 e4750e8e7a21c888d0623935a90efdc1fc4fb06e
parent 198056 e885d8128d81f2f70cac422eea76a726b271c912
child 198058 eab45b9fa85134807ffadfd95c34956d68cd2344
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbent
bugs1048252
milestone34.0a1
Bug 1048252 - Fix some bad implicit constructors in chromium IPC code; r=bent
ipc/chromium/src/base/message_loop.h
ipc/chromium/src/base/observer_list.h
ipc/chromium/src/base/ref_counted.h
ipc/chromium/src/base/revocable_store.h
ipc/chromium/src/base/string_piece.h
ipc/chromium/src/base/thread_collision_warner.h
ipc/chromium/src/base/time.cc
ipc/chromium/src/base/time.h
ipc/chromium/src/base/time_posix.cc
ipc/chromium/src/base/time_win.cc
ipc/chromium/src/base/timer.h
--- a/ipc/chromium/src/base/message_loop.h
+++ b/ipc/chromium/src/base/message_loop.h
@@ -453,17 +453,17 @@ public:
 // MessageLoopForUI extends MessageLoop with methods that are particular to a
 // MessageLoop instantiated with TYPE_UI.
 //
 // This class is typically used like so:
 //   MessageLoopForUI::current()->...call some method...
 //
 class MessageLoopForUI : public MessageLoop {
  public:
-  MessageLoopForUI(Type type=TYPE_UI) : MessageLoop(type) {
+  explicit MessageLoopForUI(Type type=TYPE_UI) : MessageLoop(type) {
   }
 
   // Returns the MessageLoopForUI of the current thread.
   static MessageLoopForUI* current() {
     MessageLoop* loop = MessageLoop::current();
     if (!loop)
       return NULL;
     Type type = loop->type();
--- a/ipc/chromium/src/base/observer_list.h
+++ b/ipc/chromium/src/base/observer_list.h
@@ -72,17 +72,17 @@ class ObserverList {
     NOTIFY_ALL,
 
     // Specifies that observers added while sending out notification are not
     // notified.
     NOTIFY_EXISTING_ONLY
   };
 
   ObserverList() : notify_depth_(0), type_(NOTIFY_ALL) {}
-  ObserverList(NotificationType type) : notify_depth_(0), type_(type) {}
+  explicit ObserverList(NotificationType type) : notify_depth_(0), type_(type) {}
   ~ObserverList() {
     // When check_empty is true, assert that the list is empty on destruction.
     if (check_empty) {
       Compact();
       DCHECK_EQ(observers_.size(), 0U);
     }
   }
 
@@ -113,17 +113,17 @@ class ObserverList {
   ObserverType* GetElementAt(int index) const {
     return observers_[index];
   }
 
   // An iterator class that can be used to access the list of observers.  See
   // also the FOREACH_OBSERVER macro defined below.
   class Iterator {
    public:
-    Iterator(const ObserverList<ObserverType>& list)
+    explicit Iterator(const ObserverList<ObserverType>& list)
         : list_(list),
           index_(0),
           max_index_(list.type_ == NOTIFY_ALL ?
                      std::numeric_limits<size_t>::max() :
                      list.observers_.size()) {
       ++list_.notify_depth_;
     }
 
--- a/ipc/chromium/src/base/ref_counted.h
+++ b/ipc/chromium/src/base/ref_counted.h
@@ -115,17 +115,17 @@ class RefCountedThreadSafe : public subt
 //
 // A wrapper for some piece of data so we can place other things in
 // scoped_refptrs<>.
 //
 template<typename T>
 class RefCountedData : public base::RefCounted< base::RefCountedData<T> > {
  public:
   RefCountedData() : data() {}
-  RefCountedData(const T& in_value) : data(in_value) {}
+  explicit RefCountedData(const T& in_value) : data(in_value) {}
 
   T data;
 };
 
 }  // namespace base
 
 //
 // A smart pointer class for reference counted objects.  Use this class instead
@@ -176,17 +176,17 @@ class RefCountedData : public base::RefC
 //   }
 //
 template <class T>
 class scoped_refptr {
  public:
   scoped_refptr() : ptr_(NULL) {
   }
 
-  scoped_refptr(T* p) : ptr_(p) {
+  MOZ_IMPLICIT scoped_refptr(T* p) : ptr_(p) {
     if (ptr_)
       ptr_->AddRef();
   }
 
   scoped_refptr(const scoped_refptr<T>& r) : ptr_(r.ptr_) {
     if (ptr_)
       ptr_->AddRef();
   }
--- a/ipc/chromium/src/base/revocable_store.h
+++ b/ipc/chromium/src/base/revocable_store.h
@@ -12,32 +12,32 @@ class RevocableStore {
  public:
   // A |StoreRef| is used to link the |RevocableStore| to its items.  There is
   // one StoreRef per store, and each item holds a reference to it.  If the
   // store wishes to revoke its items, it sets |store_| to null.  Items are
   // permitted to release their reference to the |StoreRef| when they no longer
   // require the store.
   class StoreRef : public base::RefCounted<StoreRef> {
    public:
-    StoreRef(RevocableStore* store) : store_(store) { }
+    explicit StoreRef(RevocableStore* store) : store_(store) { }
 
     void set_store(RevocableStore* store) { store_ = store; }
     RevocableStore* store() const { return store_; }
 
    private:
     RevocableStore* store_;
 
     DISALLOW_EVIL_CONSTRUCTORS(StoreRef);
   };
 
   // An item in the store.  On construction, the object adds itself to the
   // store.
   class Revocable {
    public:
-    Revocable(RevocableStore* store);
+    explicit Revocable(RevocableStore* store);
     ~Revocable();
 
     // This item has been revoked if it no longer has a pointer to the store.
     bool revoked() const { return !store_reference_->store(); }
 
   private:
     // We hold a reference to the store through this ref pointer.  We release
     // this reference on destruction.
--- a/ipc/chromium/src/base/string_piece.h
+++ b/ipc/chromium/src/base/string_piece.h
@@ -32,19 +32,19 @@ class StringPiece {
   const char*   ptr_;
   size_type     length_;
 
  public:
   // We provide non-explicit singleton constructors so users can pass
   // in a "const char*" or a "string" wherever a "StringPiece" is
   // expected.
   StringPiece() : ptr_(NULL), length_(0) { }
-  StringPiece(const char* str)
+  MOZ_IMPLICIT StringPiece(const char* str)
     : ptr_(str), length_((str == NULL) ? 0 : strlen(str)) { }
-  StringPiece(const std::string& str)
+  MOZ_IMPLICIT StringPiece(const std::string& str)
     : ptr_(str.data()), length_(str.size()) { }
   StringPiece(const char* offset, size_type len)
     : ptr_(offset), length_(len) { }
 
   // data() may return a pointer to a buffer with embedded NULs, and the
   // returned buffer may or may not be null terminated.  Therefore it is
   // typically a mistake to pass data() to a routine that expects a NUL
   // terminated string.
--- a/ipc/chromium/src/base/thread_collision_warner.h
+++ b/ipc/chromium/src/base/thread_collision_warner.h
@@ -137,17 +137,17 @@ struct AsserterBase {
 struct DCheckAsserter : public AsserterBase {
   virtual ~DCheckAsserter() {}
   virtual void warn();
 };
 
 class ThreadCollisionWarner {
  public:
   // The parameter asserter is there only for test purpose
-  ThreadCollisionWarner(AsserterBase* asserter = new DCheckAsserter())
+  explicit ThreadCollisionWarner(AsserterBase* asserter = new DCheckAsserter())
       : valid_thread_id_(0),
         counter_(0),
         asserter_(asserter) {}
 
   ~ThreadCollisionWarner() {
     delete asserter_;
   }
 
--- a/ipc/chromium/src/base/time.cc
+++ b/ipc/chromium/src/base/time.cc
@@ -46,29 +46,29 @@ int64_t TimeDelta::InMicroseconds() cons
 }
 
 // Time -----------------------------------------------------------------------
 
 // static
 Time Time::FromTimeT(time_t tt) {
   if (tt == 0)
     return Time();  // Preserve 0 so we can tell it doesn't exist.
-  return (tt * kMicrosecondsPerSecond) + kTimeTToMicrosecondsOffset;
+  return Time((tt * kMicrosecondsPerSecond) + kTimeTToMicrosecondsOffset);
 }
 
 time_t Time::ToTimeT() const {
   if (us_ == 0)
     return 0;  // Preserve 0 so we can tell it doesn't exist.
   return (us_ - kTimeTToMicrosecondsOffset) / kMicrosecondsPerSecond;
 }
 
 // static
 Time Time::FromDoubleT(double dt) {
-  return (dt * static_cast<double>(kMicrosecondsPerSecond)) +
-      kTimeTToMicrosecondsOffset;
+  return Time((dt * static_cast<double>(kMicrosecondsPerSecond)) +
+      kTimeTToMicrosecondsOffset);
 }
 
 double Time::ToDoubleT() const {
   if (us_ == 0)
     return 0;  // Preserve 0 so we can tell it doesn't exist.
   return (static_cast<double>(us_ - kTimeTToMicrosecondsOffset) /
           static_cast<double>(kMicrosecondsPerSecond));
 }
--- a/ipc/chromium/src/base/time.h
+++ b/ipc/chromium/src/base/time.h
@@ -292,20 +292,20 @@ class Time {
   }
   Time& operator-=(TimeDelta delta) {
     us_ -= delta.delta_;
     return *this;
   }
 
   // Return a new time modified by some delta.
   Time operator+(TimeDelta delta) const {
-    return us_ + delta.delta_;
+    return Time(us_ + delta.delta_);
   }
   Time operator-(TimeDelta delta) const {
-    return us_ - delta.delta_;
+    return Time(us_ - delta.delta_);
   }
 
   // Comparison operators
   bool operator==(Time other) const {
     return us_ == other.us_;
   }
   bool operator!=(Time other) const {
     return us_ != other.us_;
@@ -329,17 +329,17 @@ class Time {
   // Explodes the given time to either local time |is_local = true| or UTC
   // |is_local = false|.
   void Explode(bool is_local, Exploded* exploded) const;
 
   // Unexplodes a given time assuming the source is either local time
   // |is_local = true| or UTC |is_local = false|.
   static Time FromExploded(bool is_local, const Exploded& exploded);
 
-  Time(int64_t us) : us_(us) {
+  explicit Time(int64_t us) : us_(us) {
   }
 
   // The representation of Jan 1, 1970 UTC in microseconds since the
   // platform-dependent epoch.
   static const int64_t kTimeTToMicrosecondsOffset;
 
   // Time in microseconds in UTC.
   int64_t us_;
--- a/ipc/chromium/src/base/time_posix.cc
+++ b/ipc/chromium/src/base/time_posix.cc
@@ -39,17 +39,17 @@ const int64_t Time::kTimeTToMicroseconds
 Time Time::Now() {
   struct timeval tv;
   struct timezone tz = { 0, 0 };  // UTC
   if (gettimeofday(&tv, &tz) != 0) {
     DCHECK(0) << "Could not determine time of day";
   }
   // Combine seconds and microseconds in a 64-bit field containing microseconds
   // since the epoch.  That's enough for nearly 600 centuries.
-  return tv.tv_sec * kMicrosecondsPerSecond + tv.tv_usec;
+  return Time(tv.tv_sec * kMicrosecondsPerSecond + tv.tv_usec);
 }
 
 // static
 Time Time::NowFromSystemTime() {
   // Just use Now() because Now() returns the system time.
   return Now();
 }
 
--- a/ipc/chromium/src/base/time_win.cc
+++ b/ipc/chromium/src/base/time_win.cc
@@ -123,17 +123,17 @@ Time Time::Now() {
     TimeDelta elapsed = ticks - initial_ticks;
 
     // Check if enough time has elapsed that we need to resync the clock.
     if (elapsed.InMilliseconds() > kMaxMillisecondsToAvoidDrift) {
       InitializeClock();
       continue;
     }
 
-    return Time(elapsed + initial_time);
+    return Time(elapsed + Time(initial_time));
   }
 }
 
 // static
 Time Time::NowFromSystemTime() {
   // Force resync.
   InitializeClock();
   return Time(initial_time);
--- a/ipc/chromium/src/base/timer.h
+++ b/ipc/chromium/src/base/timer.h
@@ -80,17 +80,17 @@ class BaseTimer_Helper {
   }
 
  protected:
   BaseTimer_Helper() : delayed_task_(NULL) {}
 
   // We have access to the timer_ member so we can orphan this task.
   class TimerTask : public Task {
    public:
-    TimerTask(TimeDelta delay) : delay_(delay) {
+    explicit TimerTask(TimeDelta delay) : delay_(delay) {
       // timer_ is set in InitiateDelayedTask.
     }
     virtual ~TimerTask() {}
     BaseTimer_Helper* timer_;
     TimeDelta delay_;
   };
 
   // Used to orphan delayed_task_ so that when it runs it does nothing.