Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: chrome/browser/metrics/thread_watcher_unittest.cc

Issue 2295983002: Fix memory leak in ThreadWatcher. (Closed)
Patch Set: Cleanup ThreadWatcher initialization logic. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 EXPECT_TRUE(ThreadWatcherList::Register(std::move(io_watcher)));
Ilya Sherman 2016/08/31 03:54:42 nit: This should be an ASSERT_TRUE, as the followi
Joshua LeVasseur 2016/08/31 19:06:50 Done.
284 EXPECT_EQ(io_watcher_, thread_watcher_list_->Find(BrowserThread::IO)); 287 EXPECT_EQ(io_watcher_, thread_watcher_list_->Find(BrowserThread::IO));
285 288
286 // Create thread watcher object for the DB thread. 289 // Create thread watcher object for the DB thread.
287 db_watcher_ = new CustomThreadWatcher(BrowserThread::DB, kDBThreadName, 290 std::unique_ptr<CustomThreadWatcher> db_watcher(
288 kSleepTime, kUnresponsiveTime); 291 new CustomThreadWatcher(BrowserThread::DB, kDBThreadName,
292 kSleepTime, kUnresponsiveTime));
293 db_watcher_ = db_watcher.get();
294 EXPECT_TRUE(ThreadWatcherList::Register(std::move(db_watcher)));
Ilya Sherman 2016/08/31 03:54:42 Ditto.
Joshua LeVasseur 2016/08/31 19:06:50 Done.
289 EXPECT_EQ(db_watcher_, thread_watcher_list_->Find(BrowserThread::DB)); 295 EXPECT_EQ(db_watcher_, thread_watcher_list_->Find(BrowserThread::DB));
290 296
291 { 297 {
292 base::AutoLock lock(lock_); 298 base::AutoLock lock(lock_);
293 initialized_ = true; 299 initialized_ = true;
294 } 300 }
295 setup_complete_.Signal(); 301 setup_complete_.Signal();
296 } 302 }
297 303
298 void WaitForSetUp(TimeDelta wait_time) { 304 void WaitForSetUp(TimeDelta wait_time) {
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 } 820 }
815 821
816 TEST_F(JankTimeBombTest, ArmTest) { 822 TEST_F(JankTimeBombTest, ArmTest) {
817 // Test firing of Alarm by passing empty delay. 823 // Test firing of Alarm by passing empty delay.
818 TestingJankTimeBomb timebomb((base::TimeDelta())); 824 TestingJankTimeBomb timebomb((base::TimeDelta()));
819 if (!timebomb.IsEnabled()) 825 if (!timebomb.IsEnabled())
820 return; 826 return;
821 WaitForWatchDogThreadPostTask(); 827 WaitForWatchDogThreadPostTask();
822 EXPECT_TRUE(timebomb.alarm_invoked()); 828 EXPECT_TRUE(timebomb.alarm_invoked());
823 } 829 }
OLDNEW
« chrome/browser/metrics/thread_watcher.cc ('K') | « chrome/browser/metrics/thread_watcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698