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

Unified Diff: chrome/browser/metrics/thread_watcher.cc

Issue 2299453005: Revert of Fix memory leak in ThreadWatcher. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/metrics/thread_watcher.h ('k') | chrome/browser/metrics/thread_watcher_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/metrics/thread_watcher.cc
diff --git a/chrome/browser/metrics/thread_watcher.cc b/chrome/browser/metrics/thread_watcher.cc
index 1b81d61c2e70059677937b5db3c0ada2b25dc29d..84a00ae4e45f32c74fe06ff11da31ca4f7e64500 100644
--- a/chrome/browser/metrics/thread_watcher.cc
+++ b/chrome/browser/metrics/thread_watcher.cc
@@ -79,11 +79,12 @@
DCHECK(WatchDogThread::CurrentlyOnWatchDogThread());
// Create a new thread watcher object for the given thread and activate it.
- std::unique_ptr<ThreadWatcher> watcher(new ThreadWatcher(params));
-
+ ThreadWatcher* watcher = new ThreadWatcher(params);
+
+ DCHECK(watcher);
// If we couldn't register the thread watcher object, we are shutting down,
- // so don't activate thread watching.
- if (!ThreadWatcherList::Register(std::move(watcher)))
+ // then don't activate thread watching.
+ if (!ThreadWatcherList::IsRegistered(params.thread_id))
return;
watcher->ActivateThreadWatching();
}
@@ -223,6 +224,7 @@
void ThreadWatcher::Initialize() {
DCHECK(WatchDogThread::CurrentlyOnWatchDogThread());
+ ThreadWatcherList::Register(this);
const std::string response_time_histogram_name =
"ThreadWatcher.ResponseTime." + thread_name_;
@@ -380,14 +382,18 @@
}
// static
-bool ThreadWatcherList::Register(std::unique_ptr<ThreadWatcher> watcher) {
+void ThreadWatcherList::Register(ThreadWatcher* watcher) {
DCHECK(WatchDogThread::CurrentlyOnWatchDogThread());
if (!g_thread_watcher_list_)
- return false;
- content::BrowserThread::ID thread_id = watcher->thread_id();
- DCHECK(g_thread_watcher_list_->registered_.count(thread_id) == 0);
- g_thread_watcher_list_->registered_[thread_id] = watcher.release();
- return true;
+ return;
+ DCHECK(!g_thread_watcher_list_->Find(watcher->thread_id()));
+ g_thread_watcher_list_->registered_[watcher->thread_id()] = watcher;
+}
+
+// static
+bool ThreadWatcherList::IsRegistered(const BrowserThread::ID thread_id) {
+ DCHECK(WatchDogThread::CurrentlyOnWatchDogThread());
+ return nullptr != ThreadWatcherList::Find(thread_id);
}
// static
« no previous file with comments | « chrome/browser/metrics/thread_watcher.h ('k') | chrome/browser/metrics/thread_watcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698