Chromium Code Reviews| 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_management/providers/web_contents/web_contents_tas k_provider.h" | 5 #include "chrome/browser/task_management/providers/web_contents/web_contents_tas k_provider.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 "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "chrome/browser/task_management/providers/web_contents/subframe_task.h" | 10 #include "chrome/browser/task_management/providers/web_contents/subframe_task.h" |
| 11 #include "chrome/browser/task_management/providers/web_contents/web_contents_tag s_manager.h" | 11 #include "chrome/browser/task_management/providers/web_contents/web_contents_tag s_manager.h" |
| 12 #include "content/public/browser/render_frame_host.h" | 12 #include "content/public/browser/render_frame_host.h" |
| 13 #include "content/public/browser/render_process_host.h" | 13 #include "content/public/browser/render_process_host.h" |
| 14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 15 #include "content/public/browser/web_contents_observer.h" | 15 #include "content/public/browser/web_contents_observer.h" |
| 16 | 16 |
| 17 using content::RenderFrameHost; | 17 using content::RenderFrameHost; |
| 18 using content::RenderWidgetHost; | |
| 18 using content::SiteInstance; | 19 using content::SiteInstance; |
| 19 using content::WebContents; | 20 using content::WebContents; |
| 20 | 21 |
| 21 namespace task_management { | 22 namespace task_management { |
| 22 | 23 |
| 23 // Defines an entry for each WebContents that will be tracked by the provider. | 24 // Defines an entry for each WebContents that will be tracked by the provider. |
| 24 // The entry is used to observe certain events in its corresponding WebContents | 25 // The entry is used to observe certain events in its corresponding WebContents |
| 25 // and then it notifies the provider or the render task (representing the | 26 // and then it notifies the provider or the render task (representing the |
| 26 // WebContents) of these events. | 27 // WebContents) of these events. |
| 27 // The entry owns the created tasks representing the WebContents, and it is | 28 // The entry owns the created tasks representing the WebContents, and it is |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 45 // entry. | 46 // entry. |
| 46 RendererTask* GetTaskForFrame(RenderFrameHost* render_frame_host) const; | 47 RendererTask* GetTaskForFrame(RenderFrameHost* render_frame_host) const; |
| 47 | 48 |
| 48 // content::WebContentsObserver: | 49 // content::WebContentsObserver: |
| 49 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; | 50 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
| 50 void RenderFrameHostChanged(RenderFrameHost* old_host, | 51 void RenderFrameHostChanged(RenderFrameHost* old_host, |
| 51 RenderFrameHost* new_host) override; | 52 RenderFrameHost* new_host) override; |
| 52 void RenderViewReady() override; | 53 void RenderViewReady() override; |
| 53 void WebContentsDestroyed() override; | 54 void WebContentsDestroyed() override; |
| 54 void RenderProcessGone(base::TerminationStatus status) override; | 55 void RenderProcessGone(base::TerminationStatus status) override; |
| 56 void OnRendererUnresponsive(RenderWidgetHost* render_widget_host) override; | |
| 55 void DidNavigateMainFrame( | 57 void DidNavigateMainFrame( |
| 56 const content::LoadCommittedDetails& details, | 58 const content::LoadCommittedDetails& details, |
| 57 const content::FrameNavigateParams& params) override; | 59 const content::FrameNavigateParams& params) override; |
| 58 void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override; | 60 void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override; |
| 59 | 61 |
| 60 private: | 62 private: |
| 61 // Defines a callback for WebContents::ForEachFrame() to create a | 63 // Defines a callback for WebContents::ForEachFrame() to create a |
| 62 // corresponding task for the given |render_frame_host| and notifying the | 64 // corresponding task for the given |render_frame_host| and notifying the |
| 63 // provider's observer of the new task. | 65 // provider's observer of the new task. |
| 64 void CreateTaskForFrame(RenderFrameHost* render_frame_host); | 66 void CreateTaskForFrame(RenderFrameHost* render_frame_host); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 DCHECK(web_contents()->GetMainFrame()); | 108 DCHECK(web_contents()->GetMainFrame()); |
| 107 web_contents()->ForEachFrame(base::Bind(&WebContentsEntry::CreateTaskForFrame, | 109 web_contents()->ForEachFrame(base::Bind(&WebContentsEntry::CreateTaskForFrame, |
| 108 base::Unretained(this))); | 110 base::Unretained(this))); |
| 109 } | 111 } |
| 110 | 112 |
| 111 void WebContentsEntry::ClearAllTasks(bool notify_observer) { | 113 void WebContentsEntry::ClearAllTasks(bool notify_observer) { |
| 112 for (auto& pair : frames_by_site_instance_) { | 114 for (auto& pair : frames_by_site_instance_) { |
| 113 FramesList& frames_list = pair.second; | 115 FramesList& frames_list = pair.second; |
| 114 DCHECK(!frames_list.empty()); | 116 DCHECK(!frames_list.empty()); |
| 115 RendererTask* task = tasks_by_frames_[frames_list[0]]; | 117 RendererTask* task = tasks_by_frames_[frames_list[0]]; |
| 118 | |
| 119 task->set_termination_status(web_contents()->GetCrashedStatus()); | |
| 120 task->set_termination_error_code(web_contents()->GetCrashedErrorCode()); | |
| 121 | |
| 116 if (notify_observer) | 122 if (notify_observer) |
| 117 provider_->NotifyObserverTaskRemoved(task); | 123 provider_->NotifyObserverTaskRemoved(task); |
| 118 delete task; | 124 delete task; |
| 119 } | 125 } |
| 120 | 126 |
| 121 frames_by_site_instance_.clear(); | 127 frames_by_site_instance_.clear(); |
| 122 tasks_by_frames_.clear(); | 128 tasks_by_frames_.clear(); |
| 123 main_frame_site_instance_ = nullptr; | 129 main_frame_site_instance_ = nullptr; |
| 124 } | 130 } |
| 125 | 131 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 149 | 155 |
| 150 void WebContentsEntry::WebContentsDestroyed() { | 156 void WebContentsEntry::WebContentsDestroyed() { |
| 151 ClearAllTasks(true); | 157 ClearAllTasks(true); |
| 152 provider_->DeleteEntry(web_contents()); | 158 provider_->DeleteEntry(web_contents()); |
| 153 } | 159 } |
| 154 | 160 |
| 155 void WebContentsEntry::RenderProcessGone(base::TerminationStatus status) { | 161 void WebContentsEntry::RenderProcessGone(base::TerminationStatus status) { |
| 156 ClearAllTasks(true); | 162 ClearAllTasks(true); |
| 157 } | 163 } |
| 158 | 164 |
| 165 void WebContentsEntry::OnRendererUnresponsive( | |
| 166 RenderWidgetHost* render_widget_host) { | |
| 167 auto itr = tasks_by_frames_.find(web_contents()->GetMainFrame()); | |
| 168 if (itr == tasks_by_frames_.end()) | |
| 169 return; | |
| 170 | |
|
ncarter (slow)
2016/02/11 22:16:49
This function should use the |render_widget_host|
afakhry
2016/02/17 02:27:14
Done.
| |
| 171 provider_->NotifyObserverTaskUnresponsive(itr->second); | |
| 172 } | |
| 173 | |
| 159 void WebContentsEntry::DidNavigateMainFrame( | 174 void WebContentsEntry::DidNavigateMainFrame( |
| 160 const content::LoadCommittedDetails& details, | 175 const content::LoadCommittedDetails& details, |
| 161 const content::FrameNavigateParams& params) { | 176 const content::FrameNavigateParams& params) { |
| 162 auto itr = tasks_by_frames_.find(web_contents()->GetMainFrame()); | 177 auto itr = tasks_by_frames_.find(web_contents()->GetMainFrame()); |
| 163 if (itr == tasks_by_frames_.end()) { | 178 if (itr == tasks_by_frames_.end()) { |
| 164 // TODO(afakhry): Validate whether this actually happens in practice. | 179 // TODO(afakhry): Validate whether this actually happens in practice. |
| 165 NOTREACHED(); | 180 NOTREACHED(); |
| 166 return; | 181 return; |
| 167 } | 182 } |
| 168 | 183 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 | 392 |
| 378 WebContentsEntry* entry = itr->second; | 393 WebContentsEntry* entry = itr->second; |
| 379 entries_map_.erase(itr); | 394 entries_map_.erase(itr); |
| 380 | 395 |
| 381 // The entry we're about to delete is our caller, however its' still fine to | 396 // The entry we're about to delete is our caller, however its' still fine to |
| 382 // delete it. | 397 // delete it. |
| 383 delete entry; | 398 delete entry; |
| 384 } | 399 } |
| 385 | 400 |
| 386 } // namespace task_management | 401 } // namespace task_management |
| OLD | NEW |