OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/task_manager/providers/web_contents/web_contents_task_p
rovider.h" | 5 #include "chrome/browser/task_manager/providers/web_contents/web_contents_task_p
rovider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "chrome/browser/task_manager/providers/web_contents/subframe_task.h" | 9 #include "chrome/browser/task_manager/providers/web_contents/subframe_task.h" |
10 #include "chrome/browser/task_manager/providers/web_contents/web_contents_tags_m
anager.h" | 10 #include "chrome/browser/task_manager/providers/web_contents/web_contents_tags_m
anager.h" |
| 11 #include "content/public/browser/navigation_handle.h" |
11 #include "content/public/browser/render_frame_host.h" | 12 #include "content/public/browser/render_frame_host.h" |
12 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
13 #include "content/public/browser/render_widget_host.h" | 14 #include "content/public/browser/render_widget_host.h" |
14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
15 #include "content/public/browser/web_contents_observer.h" | 16 #include "content/public/browser/web_contents_observer.h" |
16 | 17 |
17 using content::RenderFrameHost; | 18 using content::RenderFrameHost; |
18 using content::RenderWidgetHost; | 19 using content::RenderWidgetHost; |
19 using content::SiteInstance; | 20 using content::SiteInstance; |
20 using content::WebContents; | 21 using content::WebContents; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 ClearAllTasks(true); | 155 ClearAllTasks(true); |
155 provider_->DeleteEntry(web_contents()); | 156 provider_->DeleteEntry(web_contents()); |
156 } | 157 } |
157 | 158 |
158 void WebContentsEntry::RenderProcessGone(base::TerminationStatus status) { | 159 void WebContentsEntry::RenderProcessGone(base::TerminationStatus status) { |
159 ClearAllTasks(true); | 160 ClearAllTasks(true); |
160 } | 161 } |
161 | 162 |
162 void WebContentsEntry::OnRendererUnresponsive( | 163 void WebContentsEntry::OnRendererUnresponsive( |
163 RenderWidgetHost* render_widget_host) { | 164 RenderWidgetHost* render_widget_host) { |
164 RendererTask* task = GetTaskForFrame(web_contents()->GetMainFrame()); | 165 // Find the first RenderFrameHost matching the RenderWidgetHost. |
| 166 RendererTask* task = nullptr; |
| 167 for (const auto& pair : tasks_by_frames_) { |
| 168 if (pair.first->GetView() == render_widget_host->GetView()) { |
| 169 DCHECK_EQ(pair.first->GetProcess(), render_widget_host->GetProcess()); |
| 170 task = pair.second; |
| 171 break; |
| 172 } |
| 173 } |
165 if (!task) | 174 if (!task) |
166 return; | 175 return; |
167 | 176 |
168 DCHECK_EQ(render_widget_host->GetProcess(), | |
169 web_contents()->GetMainFrame()->GetProcess()); | |
170 | |
171 provider_->NotifyObserverTaskUnresponsive(task); | 177 provider_->NotifyObserverTaskUnresponsive(task); |
172 } | 178 } |
173 | 179 |
174 void WebContentsEntry::DidFinishNavigation( | 180 void WebContentsEntry::DidFinishNavigation( |
175 content::NavigationHandle* navigation_handle) { | 181 content::NavigationHandle* navigation_handle) { |
| 182 // We only need to update tasks for main frame navigations. |
| 183 if (!navigation_handle->IsInMainFrame()) |
| 184 return; |
| 185 |
176 RendererTask* main_frame_task = | 186 RendererTask* main_frame_task = |
177 GetTaskForFrame(web_contents()->GetMainFrame()); | 187 GetTaskForFrame(web_contents()->GetMainFrame()); |
178 if (!main_frame_task) | 188 if (!main_frame_task) |
179 return; | 189 return; |
180 | 190 |
181 main_frame_task->UpdateRapporSampleName(); | 191 main_frame_task->UpdateRapporSampleName(); |
182 | 192 |
183 ForEachTask(base::Bind([](RendererTask* task) { | 193 ForEachTask(base::Bind([](RendererTask* task) { |
184 // Listening to WebContentsObserver::TitleWasSet() only is not enough in | 194 // Listening to WebContentsObserver::TitleWasSet() only is not enough in |
185 // some cases when the the web page doesn't have a title. That's why we | 195 // some cases when the the web page doesn't have a title. That's why we |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 } | 399 } |
390 | 400 |
391 void WebContentsTaskProvider::DeleteEntry(content::WebContents* web_contents) { | 401 void WebContentsTaskProvider::DeleteEntry(content::WebContents* web_contents) { |
392 // This erase() will delete the WebContentsEntry, which is actually our | 402 // This erase() will delete the WebContentsEntry, which is actually our |
393 // caller, but it's expecting us to delete it. | 403 // caller, but it's expecting us to delete it. |
394 bool success = entries_map_.erase(web_contents) != 0; | 404 bool success = entries_map_.erase(web_contents) != 0; |
395 DCHECK(success); | 405 DCHECK(success); |
396 } | 406 } |
397 | 407 |
398 } // namespace task_manager | 408 } // namespace task_manager |
OLD | NEW |