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

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

Issue 2300133002: Fix memory leak in ThreadWatcher. (Closed)
Patch Set: Implement isherman's feedback (from comment #6) 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
« no previous file with comments | « chrome/browser/metrics/thread_watcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 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
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 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/thread_watcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698