| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <limits> | 5 #include <limits> |
| 6 | 6 |
| 7 #include "chrome/browser/jankometer.h" | 7 #include "chrome/browser/jankometer.h" |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 //------------------------------------------------------------------------------ | 214 //------------------------------------------------------------------------------ |
| 215 class IOJankObserver : public base::RefCountedThreadSafe<IOJankObserver>, | 215 class IOJankObserver : public base::RefCountedThreadSafe<IOJankObserver>, |
| 216 public MessageLoopForIO::IOObserver, | 216 public MessageLoopForIO::IOObserver, |
| 217 public MessageLoop::TaskObserver { | 217 public MessageLoop::TaskObserver { |
| 218 public: | 218 public: |
| 219 IOJankObserver(const char* thread_name, | 219 IOJankObserver(const char* thread_name, |
| 220 TimeDelta excessive_duration, | 220 TimeDelta excessive_duration, |
| 221 bool watchdog_enable) | 221 bool watchdog_enable) |
| 222 : helper_(thread_name, excessive_duration, watchdog_enable) {} | 222 : helper_(thread_name, excessive_duration, watchdog_enable) {} |
| 223 | 223 |
| 224 ~IOJankObserver() {} | |
| 225 | |
| 226 // Attaches the observer to the current thread's message loop. You can only | 224 // Attaches the observer to the current thread's message loop. You can only |
| 227 // attach to the current thread, so this function can be invoked on another | 225 // attach to the current thread, so this function can be invoked on another |
| 228 // thread to attach it. | 226 // thread to attach it. |
| 229 void AttachToCurrentThread() { | 227 void AttachToCurrentThread() { |
| 230 MessageLoop::current()->AddTaskObserver(this); | 228 MessageLoop::current()->AddTaskObserver(this); |
| 231 MessageLoopForIO::current()->AddIOObserver(this); | 229 MessageLoopForIO::current()->AddIOObserver(this); |
| 232 } | 230 } |
| 233 | 231 |
| 234 // Detaches the observer to the current thread's message loop. | 232 // Detaches the observer to the current thread's message loop. |
| 235 void DetachFromCurrentThread() { | 233 void DetachFromCurrentThread() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 255 helper_.StartProcessingTimers(queueing_time); | 253 helper_.StartProcessingTimers(queueing_time); |
| 256 } | 254 } |
| 257 | 255 |
| 258 virtual void DidProcessTask(base::TimeTicks time_posted) OVERRIDE { | 256 virtual void DidProcessTask(base::TimeTicks time_posted) OVERRIDE { |
| 259 helper_.EndProcessingTimers(); | 257 helper_.EndProcessingTimers(); |
| 260 } | 258 } |
| 261 | 259 |
| 262 private: | 260 private: |
| 263 friend class base::RefCountedThreadSafe<IOJankObserver>; | 261 friend class base::RefCountedThreadSafe<IOJankObserver>; |
| 264 | 262 |
| 263 ~IOJankObserver() {} |
| 264 |
| 265 JankObserverHelper helper_; | 265 JankObserverHelper helper_; |
| 266 | 266 |
| 267 DISALLOW_COPY_AND_ASSIGN(IOJankObserver); | 267 DISALLOW_COPY_AND_ASSIGN(IOJankObserver); |
| 268 }; | 268 }; |
| 269 | 269 |
| 270 //------------------------------------------------------------------------------ | 270 //------------------------------------------------------------------------------ |
| 271 class UIJankObserver : public base::RefCountedThreadSafe<UIJankObserver>, | 271 class UIJankObserver : public base::RefCountedThreadSafe<UIJankObserver>, |
| 272 public MessageLoop::TaskObserver, | 272 public MessageLoop::TaskObserver, |
| 273 public MessageLoopForUI::Observer { | 273 public MessageLoopForUI::Observer { |
| 274 public: | 274 public: |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 delete ui_observer; | 419 delete ui_observer; |
| 420 ui_observer = NULL; | 420 ui_observer = NULL; |
| 421 } | 421 } |
| 422 if (io_observer) { | 422 if (io_observer) { |
| 423 // IO thread can't be running when we remove observers. | 423 // IO thread can't be running when we remove observers. |
| 424 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); | 424 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); |
| 425 delete io_observer; | 425 delete io_observer; |
| 426 io_observer = NULL; | 426 io_observer = NULL; |
| 427 } | 427 } |
| 428 } | 428 } |
| OLD | NEW |