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/metrics/thread_watcher.h" | 5 #include "chrome/browser/metrics/thread_watcher.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 WaitForSetUp(TimeDelta::FromMinutes(1)); | 272 WaitForSetUp(TimeDelta::FromMinutes(1)); |
273 } | 273 } |
274 | 274 |
275 void SetUpObjects() { | 275 void SetUpObjects() { |
276 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); | 276 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); |
277 | 277 |
278 // Setup the registry for thread watchers. | 278 // Setup the registry for thread watchers. |
279 thread_watcher_list_ = new ThreadWatcherList(); | 279 thread_watcher_list_ = new ThreadWatcherList(); |
280 | 280 |
281 // Create thread watcher object for the IO thread. | 281 // Create thread watcher object for the IO thread. |
282 io_watcher_ = new CustomThreadWatcher(BrowserThread::IO, kIOThreadName, | 282 std::unique_ptr<CustomThreadWatcher> io_watcher( |
283 kSleepTime, kUnresponsiveTime); | 283 new CustomThreadWatcher(BrowserThread::IO, kIOThreadName, |
| 284 kSleepTime, kUnresponsiveTime)); |
| 285 io_watcher_ = io_watcher.get(); |
| 286 ThreadWatcher* registered_io_watcher = |
| 287 ThreadWatcherList::Register(std::move(io_watcher)); |
| 288 EXPECT_EQ(io_watcher_, registered_io_watcher); |
284 EXPECT_EQ(io_watcher_, thread_watcher_list_->Find(BrowserThread::IO)); | 289 EXPECT_EQ(io_watcher_, thread_watcher_list_->Find(BrowserThread::IO)); |
285 | 290 |
286 // Create thread watcher object for the DB thread. | 291 // Create thread watcher object for the DB thread. |
287 db_watcher_ = new CustomThreadWatcher(BrowserThread::DB, kDBThreadName, | 292 std::unique_ptr<CustomThreadWatcher> db_watcher( |
288 kSleepTime, kUnresponsiveTime); | 293 new CustomThreadWatcher(BrowserThread::DB, kDBThreadName, |
| 294 kSleepTime, kUnresponsiveTime)); |
| 295 db_watcher_ = db_watcher.get(); |
| 296 ThreadWatcher* registered_db_watcher = |
| 297 ThreadWatcherList::Register(std::move(db_watcher)); |
| 298 EXPECT_EQ(db_watcher_, registered_db_watcher); |
289 EXPECT_EQ(db_watcher_, thread_watcher_list_->Find(BrowserThread::DB)); | 299 EXPECT_EQ(db_watcher_, thread_watcher_list_->Find(BrowserThread::DB)); |
290 | 300 |
291 { | 301 { |
292 base::AutoLock lock(lock_); | 302 base::AutoLock lock(lock_); |
293 initialized_ = true; | 303 initialized_ = true; |
294 } | 304 } |
295 setup_complete_.Signal(); | 305 setup_complete_.Signal(); |
296 } | 306 } |
297 | 307 |
298 void WaitForSetUp(TimeDelta wait_time) { | 308 void WaitForSetUp(TimeDelta wait_time) { |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 } | 824 } |
815 | 825 |
816 TEST_F(JankTimeBombTest, ArmTest) { | 826 TEST_F(JankTimeBombTest, ArmTest) { |
817 // Test firing of Alarm by passing empty delay. | 827 // Test firing of Alarm by passing empty delay. |
818 TestingJankTimeBomb timebomb((base::TimeDelta())); | 828 TestingJankTimeBomb timebomb((base::TimeDelta())); |
819 if (!timebomb.IsEnabled()) | 829 if (!timebomb.IsEnabled()) |
820 return; | 830 return; |
821 WaitForWatchDogThreadPostTask(); | 831 WaitForWatchDogThreadPostTask(); |
822 EXPECT_TRUE(timebomb.alarm_invoked()); | 832 EXPECT_TRUE(timebomb.alarm_invoked()); |
823 } | 833 } |
OLD | NEW |