Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / Timer.h
index 1f03cf1..7c31c18 100644 (file)
@@ -27,6 +27,7 @@
 #define Timer_h
 
 #include "platform/PlatformExport.h"
+#include "platform/TraceLocation.h"
 #include "wtf/Noncopyable.h"
 #include "wtf/Threading.h"
 #include "wtf/Vector.h"
@@ -43,13 +44,20 @@ public:
     TimerBase();
     virtual ~TimerBase();
 
-    void start(double nextFireInterval, double repeatInterval);
+    void start(double nextFireInterval, double repeatInterval, const TraceLocation&);
 
-    void startRepeating(double repeatInterval) { start(repeatInterval, repeatInterval); }
-    void startOneShot(double interval) { start(interval, 0); }
+    void startRepeating(double repeatInterval, const TraceLocation& caller)
+    {
+        start(repeatInterval, repeatInterval, caller);
+    }
+    void startOneShot(double interval, const TraceLocation& caller)
+    {
+        start(interval, 0, caller);
+    }
 
     void stop();
     bool isActive() const;
+    const TraceLocation& location() const { return m_location; }
 
     double nextFireInterval() const;
     double nextUnalignedFireInterval() const;
@@ -95,6 +103,7 @@ private:
     int m_heapIndex; // -1 if not in heap
     unsigned m_heapInsertionOrder; // Used to keep order among equal-fire-time timers
     Vector<TimerBase*>* m_cachedThreadGlobalTimerHeap;
+    TraceLocation m_location;
 
 #ifndef NDEBUG
     ThreadIdentifier m_thread;
@@ -106,7 +115,7 @@ private:
 };
 
 template <typename TimerFiredClass>
-class Timer : public TimerBase {
+class Timer FINAL : public TimerBase {
 public:
     typedef void (TimerFiredClass::*TimerFiredFunction)(Timer*);
 
@@ -114,8 +123,11 @@ public:
         : m_object(o), m_function(f) { }
 
 private:
-    virtual void fired() { (m_object->*m_function)(this); }
+    virtual void fired() OVERRIDE { (m_object->*m_function)(this); }
 
+    // FIXME: oilpan: TimerBase should be moved to the heap and m_object should be traced.
+    // This raw pointer is safe as long as Timer<X> is held by the X itself (That's the case
+    // in the current code base).
     TimerFiredClass* m_object;
     TimerFiredFunction m_function;
 };
@@ -127,7 +139,7 @@ inline bool TimerBase::isActive() const
 }
 
 template <typename TimerFiredClass>
-class DeferrableOneShotTimer : private TimerBase {
+class DeferrableOneShotTimer FINAL : private TimerBase {
 public:
     typedef void (TimerFiredClass::*TimerFiredFunction)(DeferrableOneShotTimer*);
 
@@ -139,7 +151,7 @@ public:
     {
     }
 
-    void restart()
+    void restart(const TraceLocation& caller)
     {
         // Setting this boolean is much more efficient than calling startOneShot
         // again, which might result in rescheduling the system timer which
@@ -149,24 +161,28 @@ public:
             m_shouldRestartWhenTimerFires = true;
             return;
         }
-        startOneShot(m_delay);
+        startOneShot(m_delay, caller);
     }
 
     using TimerBase::stop;
     using TimerBase::isActive;
 
 private:
-    virtual void fired()
+    virtual void fired() OVERRIDE
     {
         if (m_shouldRestartWhenTimerFires) {
             m_shouldRestartWhenTimerFires = false;
-            startOneShot(m_delay);
+            // FIXME: This should not be FROM_HERE.
+            startOneShot(m_delay, FROM_HERE);
             return;
         }
 
         (m_object->*m_function)(this);
     }
 
+    // FIXME: oilpan: TimerBase should be moved to the heap and m_object should be traced.
+    // This raw pointer is safe as long as Timer<X> is held by the X itself (That's the case
+    // in the current code base).
     TimerFiredClass* m_object;
     TimerFiredFunction m_function;