OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/jankometer.h" | 5 #include "chrome/browser/jankometer.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 public: | 273 public: |
274 UIJankObserver(const char* thread_name, | 274 UIJankObserver(const char* thread_name, |
275 TimeDelta excessive_duration, | 275 TimeDelta excessive_duration, |
276 bool watchdog_enable) | 276 bool watchdog_enable) |
277 : helper_(thread_name, excessive_duration, watchdog_enable) {} | 277 : helper_(thread_name, excessive_duration, watchdog_enable) {} |
278 | 278 |
279 // Attaches the observer to the current thread's message loop. You can only | 279 // Attaches the observer to the current thread's message loop. You can only |
280 // attach to the current thread, so this function can be invoked on another | 280 // attach to the current thread, so this function can be invoked on another |
281 // thread to attach it. | 281 // thread to attach it. |
282 void AttachToCurrentThread() { | 282 void AttachToCurrentThread() { |
283 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); | 283 DCHECK(base::MessageLoopForUI::IsCurrent()); |
284 base::MessageLoopForUI::current()->AddObserver(this); | 284 base::MessageLoopForUI::current()->AddObserver(this); |
285 base::MessageLoop::current()->AddTaskObserver(this); | 285 base::MessageLoop::current()->AddTaskObserver(this); |
286 } | 286 } |
287 | 287 |
288 // Detaches the observer to the current thread's message loop. | 288 // Detaches the observer to the current thread's message loop. |
289 void DetachFromCurrentThread() { | 289 void DetachFromCurrentThread() { |
290 DCHECK_EQ(base::MessageLoop::current()->type(), base::MessageLoop::TYPE_UI); | 290 DCHECK(base::MessageLoopForUI::IsCurrent()); |
291 base::MessageLoop::current()->RemoveTaskObserver(this); | 291 base::MessageLoop::current()->RemoveTaskObserver(this); |
292 base::MessageLoopForUI::current()->RemoveObserver(this); | 292 base::MessageLoopForUI::current()->RemoveObserver(this); |
293 } | 293 } |
294 | 294 |
295 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { | 295 virtual void WillProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
296 if (!helper_.MessageWillBeMeasured()) | 296 if (!helper_.MessageWillBeMeasured()) |
297 return; | 297 return; |
298 base::TimeTicks now = base::TimeTicks::Now(); | 298 base::TimeTicks now = base::TimeTicks::Now(); |
299 const base::TimeDelta queueing_time = now - pending_task.time_posted; | 299 const base::TimeDelta queueing_time = now - pending_task.time_posted; |
300 helper_.StartProcessingTimers(queueing_time); | 300 helper_.StartProcessingTimers(queueing_time); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 delete ui_observer; | 418 delete ui_observer; |
419 ui_observer = NULL; | 419 ui_observer = NULL; |
420 } | 420 } |
421 if (io_observer) { | 421 if (io_observer) { |
422 // IO thread can't be running when we remove observers. | 422 // IO thread can't be running when we remove observers. |
423 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); | 423 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); |
424 delete io_observer; | 424 delete io_observer; |
425 io_observer = NULL; | 425 io_observer = NULL; |
426 } | 426 } |
427 } | 427 } |
OLD | NEW |