OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/histogram.h" | 11 #include "base/histogram.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/ref_counted.h" | 13 #include "base/ref_counted.h" |
14 #include "base/stats_counters.h" | 14 #include "base/stats_counters.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "base/thread.h" | 16 #include "base/thread.h" |
17 #include "base/time.h" | 17 #include "base/time.h" |
18 #include "base/watchdog.h" | 18 #include "base/watchdog.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/chrome_thread.h" |
21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
22 | 23 |
23 #if defined(OS_LINUX) | 24 #if defined(OS_LINUX) |
24 #include "chrome/common/gtk_util.h" | 25 #include "chrome/common/gtk_util.h" |
25 #endif | 26 #endif |
26 | 27 |
27 using base::TimeDelta; | 28 using base::TimeDelta; |
28 using base::TimeTicks; | 29 using base::TimeTicks; |
29 | 30 |
30 namespace { | 31 namespace { |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 ui_observer->AttachToCurrentThread(); | 243 ui_observer->AttachToCurrentThread(); |
243 | 244 |
244 // Now install on the I/O thread. Hiccups on that thread will block | 245 // Now install on the I/O thread. Hiccups on that thread will block |
245 // interaction with web pages. We must proxy to that thread before we can | 246 // interaction with web pages. We must proxy to that thread before we can |
246 // add our observer. | 247 // add our observer. |
247 io_observer = new JankObserver( | 248 io_observer = new JankObserver( |
248 "IO", | 249 "IO", |
249 TimeDelta::FromMilliseconds(kMaxIOMessageDelayMs), | 250 TimeDelta::FromMilliseconds(kMaxIOMessageDelayMs), |
250 io_watchdog_enabled); | 251 io_watchdog_enabled); |
251 io_observer->AddRef(); | 252 io_observer->AddRef(); |
252 base::Thread* io_thread = g_browser_process->io_thread(); | 253 ChromeThread::PostTask( |
253 if (io_thread) { | 254 ChromeThread::IO, FROM_HERE, |
254 io_thread->message_loop()->PostTask(FROM_HERE, | 255 NewRunnableMethod(io_observer, &JankObserver::AttachToCurrentThread)); |
255 NewRunnableMethod(io_observer, | |
256 &JankObserver::AttachToCurrentThread)); | |
257 } | |
258 } | 256 } |
259 | 257 |
260 void UninstallJankometer() { | 258 void UninstallJankometer() { |
261 if (ui_observer) { | 259 if (ui_observer) { |
262 ui_observer->DetachFromCurrentThread(); | 260 ui_observer->DetachFromCurrentThread(); |
263 ui_observer->Release(); | 261 ui_observer->Release(); |
264 ui_observer = NULL; | 262 ui_observer = NULL; |
265 } | 263 } |
266 if (io_observer) { | 264 if (io_observer) { |
267 // IO thread can't be running when we remove observers. | 265 // IO thread can't be running when we remove observers. |
268 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); | 266 DCHECK((!g_browser_process) || !(g_browser_process->io_thread())); |
269 io_observer->Release(); | 267 io_observer->Release(); |
270 io_observer = NULL; | 268 io_observer = NULL; |
271 } | 269 } |
272 } | 270 } |
OLD | NEW |