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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 return; | 291 return; |
292 base::TimeTicks now = base::TimeTicks::Now(); | 292 base::TimeTicks now = base::TimeTicks::Now(); |
293 const base::TimeDelta queueing_time = now - pending_task.time_posted; | 293 const base::TimeDelta queueing_time = now - pending_task.time_posted; |
294 helper_.StartProcessingTimers(queueing_time); | 294 helper_.StartProcessingTimers(queueing_time); |
295 } | 295 } |
296 | 296 |
297 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { | 297 virtual void DidProcessTask(const base::PendingTask& pending_task) OVERRIDE { |
298 helper_.EndProcessingTimers(); | 298 helper_.EndProcessingTimers(); |
299 } | 299 } |
300 | 300 |
301 virtual base::EventStatus WillProcessEvent( | 301 virtual void WillProcessEvent(const base::NativeEvent& event) OVERRIDE { |
302 const base::NativeEvent& event) OVERRIDE { | |
303 if (!helper_.MessageWillBeMeasured()) | 302 if (!helper_.MessageWillBeMeasured()) |
304 return base::EVENT_CONTINUE; | 303 return; |
305 // GetMessageTime returns a LONG (signed 32-bit) and GetTickCount returns | 304 // GetMessageTime returns a LONG (signed 32-bit) and GetTickCount returns |
306 // a DWORD (unsigned 32-bit). They both wrap around when the time is longer | 305 // a DWORD (unsigned 32-bit). They both wrap around when the time is longer |
307 // than they can hold. I'm not sure if GetMessageTime wraps around to 0, | 306 // than they can hold. I'm not sure if GetMessageTime wraps around to 0, |
308 // or if the original time comes from GetTickCount, it might wrap around | 307 // or if the original time comes from GetTickCount, it might wrap around |
309 // to -1. | 308 // to -1. |
310 // | 309 // |
311 // Therefore, I cast to DWORD so if it wraps to -1 we will correct it. If | 310 // Therefore, I cast to DWORD so if it wraps to -1 we will correct it. If |
312 // it doesn't, then our time delta will be negative if a message happens | 311 // it doesn't, then our time delta will be negative if a message happens |
313 // to straddle the wraparound point, it will still be OK. | 312 // to straddle the wraparound point, it will still be OK. |
314 DWORD cur_message_issue_time = static_cast<DWORD>(event.time); | 313 DWORD cur_message_issue_time = static_cast<DWORD>(event.time); |
315 DWORD cur_time = GetTickCount(); | 314 DWORD cur_time = GetTickCount(); |
316 base::TimeDelta queueing_time = | 315 base::TimeDelta queueing_time = |
317 base::TimeDelta::FromMilliseconds(cur_time - cur_message_issue_time); | 316 base::TimeDelta::FromMilliseconds(cur_time - cur_message_issue_time); |
318 | 317 |
319 helper_.StartProcessingTimers(queueing_time); | 318 helper_.StartProcessingTimers(queueing_time); |
320 return base::EVENT_CONTINUE; | |
321 } | 319 } |
322 | 320 |
323 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE { | 321 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE { |
324 helper_.EndProcessingTimers(); | 322 helper_.EndProcessingTimers(); |
325 } | 323 } |
326 | 324 |
327 private: | 325 private: |
328 friend class base::RefCountedThreadSafe<UIJankObserver>; | 326 friend class base::RefCountedThreadSafe<UIJankObserver>; |
329 | 327 |
330 virtual ~UIJankObserver() {} | 328 virtual ~UIJankObserver() {} |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 delete ui_observer; | 385 delete ui_observer; |
388 ui_observer = NULL; | 386 ui_observer = NULL; |
389 } | 387 } |
390 if (io_observer) { | 388 if (io_observer) { |
391 // IO thread can't be running when we remove observers. | 389 // IO thread can't be running when we remove observers. |
392 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); | 390 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); |
393 delete io_observer; | 391 delete io_observer; |
394 io_observer = NULL; | 392 io_observer = NULL; |
395 } | 393 } |
396 } | 394 } |
OLD | NEW |