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_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 "base/memory/weak_ptr.h" | |
| 10 #include "base/stl_util.h" | |
| 9 #include "chrome/browser/task_manager/providers/web_contents/subframe_task.h" | 11 #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" | 12 #include "chrome/browser/task_manager/providers/web_contents/web_contents_tags_m anager.h" |
| 11 #include "content/public/browser/navigation_handle.h" | 13 #include "content/public/browser/navigation_handle.h" |
| 12 #include "content/public/browser/render_frame_host.h" | 14 #include "content/public/browser/render_frame_host.h" |
| 13 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 14 #include "content/public/browser/render_widget_host.h" | 16 #include "content/public/browser/render_widget_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/browser/web_contents_observer.h" | 18 #include "content/public/browser/web_contents_observer.h" |
| 17 | 19 |
| 18 using content::RenderFrameHost; | 20 using content::RenderFrameHost; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 44 | 46 |
| 45 // Returns the |RendererTask| that corresponds to the given | 47 // Returns the |RendererTask| that corresponds to the given |
| 46 // |render_frame_host| or |nullptr| if the given frame is not tracked by this | 48 // |render_frame_host| or |nullptr| if the given frame is not tracked by this |
| 47 // entry. | 49 // entry. |
| 48 RendererTask* GetTaskForFrame(RenderFrameHost* render_frame_host) const; | 50 RendererTask* GetTaskForFrame(RenderFrameHost* render_frame_host) const; |
| 49 | 51 |
| 50 // content::WebContentsObserver: | 52 // content::WebContentsObserver: |
| 51 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; | 53 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
| 52 void RenderFrameHostChanged(RenderFrameHost* old_host, | 54 void RenderFrameHostChanged(RenderFrameHost* old_host, |
| 53 RenderFrameHost* new_host) override; | 55 RenderFrameHost* new_host) override; |
| 56 void RenderFrameCreated(RenderFrameHost*) override; | |
| 54 void RenderViewReady() override; | 57 void RenderViewReady() override; |
| 55 void WebContentsDestroyed() override; | 58 void WebContentsDestroyed() override; |
| 56 void RenderProcessGone(base::TerminationStatus status) override; | 59 void RenderProcessGone(base::TerminationStatus status) override; |
| 57 void OnRendererUnresponsive(RenderWidgetHost* render_widget_host) override; | 60 void OnRendererUnresponsive(RenderWidgetHost* render_widget_host) override; |
| 58 void DidFinishNavigation( | 61 void DidFinishNavigation( |
| 59 content::NavigationHandle* navigation_handle) override; | 62 content::NavigationHandle* navigation_handle) override; |
| 60 void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override; | 63 void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override; |
| 61 | 64 |
| 65 void RenderFrameReady(int process_routing_id, int frame_routing_id); | |
| 66 | |
| 62 private: | 67 private: |
| 63 // Defines a callback for WebContents::ForEachFrame() to create a | 68 // Defines a callback for WebContents::ForEachFrame() to create a |
| 64 // corresponding task for the given |render_frame_host| and notifying the | 69 // corresponding task for the given |render_frame_host| and notifying the |
| 65 // provider's observer of the new task. | 70 // provider's observer of the new task. |
| 66 void CreateTaskForFrame(RenderFrameHost* render_frame_host); | 71 void CreateTaskForFrame(RenderFrameHost* render_frame_host); |
| 67 | 72 |
| 68 // Clears the task that corresponds to the given |render_frame_host| and | 73 // Clears the task that corresponds to the given |render_frame_host| and |
| 69 // notifies the provider's observer of the tasks removal. | 74 // notifies the provider's observer of the tasks removal. |
| 70 void ClearTaskForFrame(RenderFrameHost* render_frame_host); | 75 void ClearTaskForFrame(RenderFrameHost* render_frame_host); |
| 71 | 76 |
| 72 // Calls |on_task| for each task managed by this WebContentsEntry. | 77 // Calls |on_task| for each task managed by this WebContentsEntry. |
| 73 void ForEachTask(const base::Callback<void(RendererTask*)>& on_task); | 78 void ForEachTask(const base::Callback<void(RendererTask*)>& on_task); |
| 74 | 79 |
| 75 // The provider that owns this entry. | 80 // The provider that owns this entry. |
| 76 WebContentsTaskProvider* provider_; | 81 WebContentsTaskProvider* provider_; |
| 77 | 82 |
| 78 // The RenderFrameHosts associated with this entry's WebContents that we're | 83 // The RenderFrameHosts associated with this entry's WebContents that we're |
| 79 // tracking mapped by their SiteInstances. | 84 // tracking mapped by their SiteInstances. |
| 80 using FramesList = std::vector<RenderFrameHost*>; | 85 using FramesList = std::vector<RenderFrameHost*>; |
| 81 std::map<SiteInstance*, FramesList> frames_by_site_instance_; | 86 std::map<SiteInstance*, FramesList> frames_by_site_instance_; |
| 82 | 87 |
| 83 // The RendererTasks that we create for the task manager, mapped by their | 88 // The RendererTasks that we create for the task manager, mapped by their |
| 84 // RenderFrameHosts. This owns the RenderTasks. | 89 // RenderFrameHosts. This owns the RenderTasks. |
| 85 std::map<RenderFrameHost*, RendererTask*> tasks_by_frames_; | 90 std::map<RenderFrameHost*, RendererTask*> tasks_by_frames_; |
| 86 | 91 |
| 87 // States whether we did record a main frame for this entry. | 92 // States whether we did record a main frame for this entry. |
| 88 SiteInstance* main_frame_site_instance_; | 93 SiteInstance* main_frame_site_instance_; |
| 89 | 94 |
| 95 base::WeakPtrFactory<WebContentsEntry> weak_factory_; | |
| 96 | |
| 90 DISALLOW_COPY_AND_ASSIGN(WebContentsEntry); | 97 DISALLOW_COPY_AND_ASSIGN(WebContentsEntry); |
| 91 }; | 98 }; |
| 92 | 99 |
| 93 //////////////////////////////////////////////////////////////////////////////// | 100 //////////////////////////////////////////////////////////////////////////////// |
| 94 | 101 |
| 95 WebContentsEntry::WebContentsEntry(content::WebContents* web_contents, | 102 WebContentsEntry::WebContentsEntry(content::WebContents* web_contents, |
| 96 WebContentsTaskProvider* provider) | 103 WebContentsTaskProvider* provider) |
| 97 : WebContentsObserver(web_contents), | 104 : WebContentsObserver(web_contents), |
| 98 provider_(provider), | 105 provider_(provider), |
| 99 main_frame_site_instance_(nullptr) { | 106 main_frame_site_instance_(nullptr), |
| 100 } | 107 weak_factory_(this) {} |
| 101 | 108 |
| 102 WebContentsEntry::~WebContentsEntry() { | 109 WebContentsEntry::~WebContentsEntry() { |
| 103 ClearAllTasks(false); | 110 ClearAllTasks(false); |
| 104 } | 111 } |
| 105 | 112 |
| 106 void WebContentsEntry::CreateAllTasks() { | 113 void WebContentsEntry::CreateAllTasks() { |
| 107 DCHECK(web_contents()->GetMainFrame()); | 114 DCHECK(web_contents()->GetMainFrame()); |
| 108 web_contents()->ForEachFrame(base::Bind(&WebContentsEntry::CreateTaskForFrame, | 115 web_contents()->ForEachFrame(base::Bind(&WebContentsEntry::CreateTaskForFrame, |
| 109 base::Unretained(this))); | 116 base::Unretained(this))); |
| 110 } | 117 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 139 void WebContentsEntry::RenderFrameDeleted(RenderFrameHost* render_frame_host) { | 146 void WebContentsEntry::RenderFrameDeleted(RenderFrameHost* render_frame_host) { |
| 140 ClearTaskForFrame(render_frame_host); | 147 ClearTaskForFrame(render_frame_host); |
| 141 } | 148 } |
| 142 | 149 |
| 143 void WebContentsEntry::RenderFrameHostChanged(RenderFrameHost* old_host, | 150 void WebContentsEntry::RenderFrameHostChanged(RenderFrameHost* old_host, |
| 144 RenderFrameHost* new_host) { | 151 RenderFrameHost* new_host) { |
| 145 ClearTaskForFrame(old_host); | 152 ClearTaskForFrame(old_host); |
| 146 CreateTaskForFrame(new_host); | 153 CreateTaskForFrame(new_host); |
| 147 } | 154 } |
| 148 | 155 |
| 156 void WebContentsEntry::RenderFrameCreated(RenderFrameHost* render_frame_host) { | |
| 157 // Postpone processing |render_frame_host| until its process has a PID. | |
| 158 render_frame_host->GetProcess()->PostTaskWhenProcessIsReady(base::Bind( | |
|
ncarter (slow)
2017/05/12 21:56:02
When we show the task manager, this means we will
Łukasz Anforowicz
2017/05/16 16:37:25
In the most recent patchset, I am returning early
| |
| 159 &WebContentsEntry::RenderFrameReady, weak_factory_.GetWeakPtr(), | |
| 160 render_frame_host->GetProcess()->GetID(), | |
| 161 render_frame_host->GetRoutingID())); | |
| 162 } | |
| 163 | |
| 164 void WebContentsEntry::RenderFrameReady(int render_process_id, | |
| 165 int render_frame_id) { | |
| 166 content::RenderFrameHost* render_frame_host = | |
| 167 content::RenderFrameHost::FromID(render_process_id, render_frame_id); | |
| 168 if (render_frame_host) | |
|
ncarter (slow)
2017/05/12 21:56:02
This would need to be:
render_frame_host && rende
Łukasz Anforowicz
2017/05/16 16:37:25
RE: IsRenderFrameLive
Wouldn't this be redundant
| |
| 169 CreateTaskForFrame(render_frame_host); | |
| 170 } | |
| 171 | |
| 149 void WebContentsEntry::RenderViewReady() { | 172 void WebContentsEntry::RenderViewReady() { |
| 150 ClearAllTasks(true); | 173 ClearAllTasks(true); |
| 151 CreateAllTasks(); | 174 CreateAllTasks(); |
| 152 } | 175 } |
| 153 | 176 |
| 154 void WebContentsEntry::WebContentsDestroyed() { | 177 void WebContentsEntry::WebContentsDestroyed() { |
| 155 ClearAllTasks(true); | 178 ClearAllTasks(true); |
| 156 provider_->DeleteEntry(web_contents()); | 179 provider_->DeleteEntry(web_contents()); |
| 157 } | 180 } |
| 158 | 181 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 } | 228 } |
| 206 | 229 |
| 207 void WebContentsEntry::TitleWasSet(content::NavigationEntry* entry, | 230 void WebContentsEntry::TitleWasSet(content::NavigationEntry* entry, |
| 208 bool explicit_set) { | 231 bool explicit_set) { |
| 209 ForEachTask(base::Bind([](RendererTask* task) { | 232 ForEachTask(base::Bind([](RendererTask* task) { |
| 210 task->UpdateTitle(); | 233 task->UpdateTitle(); |
| 211 task->UpdateFavicon(); | 234 task->UpdateFavicon(); |
| 212 })); | 235 })); |
| 213 } | 236 } |
| 214 | 237 |
| 215 void WebContentsEntry::CreateTaskForFrame(RenderFrameHost* render_frame_host) { | 238 void WebContentsEntry::CreateTaskForFrame(RenderFrameHost* render_frame_host) { |
|
ncarter (slow)
2017/05/12 21:56:02
This function is implemented assuming that |render
Łukasz Anforowicz
2017/05/16 16:37:25
I am not sure if this is still needed?
| |
| 216 DCHECK(!tasks_by_frames_.count(render_frame_host)); | 239 if (base::ContainsKey(tasks_by_frames_, render_frame_host)) |
| 240 ClearTaskForFrame(render_frame_host); | |
|
ncarter (slow)
2017/05/12 21:56:02
When does this happen?
If |render_frame_host| is
Łukasz Anforowicz
2017/05/16 16:37:25
This would happen when CreateTaskForFrame would be
| |
| 217 | 241 |
| 218 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); | 242 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); |
| 219 if (!site_instance->GetProcess()->HasConnection()) | 243 if (!site_instance->GetProcess()->HasConnection()) |
|
ncarter (slow)
2017/05/12 21:56:02
Should probably be IsReady()
Łukasz Anforowicz
2017/05/16 16:37:25
Changing this makes PrintPreviewDialogControllerBr
| |
| 220 return; | 244 return; |
| 221 | 245 |
| 222 bool site_instance_exists = | 246 bool site_instance_exists = |
| 223 frames_by_site_instance_.count(site_instance) != 0; | 247 frames_by_site_instance_.count(site_instance) != 0; |
| 224 bool is_main_frame = (render_frame_host == web_contents()->GetMainFrame()); | 248 bool is_main_frame = (render_frame_host == web_contents()->GetMainFrame()); |
| 225 bool site_instance_is_main = (site_instance == main_frame_site_instance_); | 249 bool site_instance_is_main = (site_instance == main_frame_site_instance_); |
| 226 | 250 |
| 227 RendererTask* new_task = nullptr; | 251 RendererTask* new_task = nullptr; |
| 228 // We don't create a task if there's one for this site_instance AND | 252 // We don't create a task if there's one for this site_instance AND |
| 229 // if this is not the main frame or we did record a main frame for the entry. | 253 // if this is not the main frame or we did record a main frame for the entry. |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 } | 423 } |
| 400 | 424 |
| 401 void WebContentsTaskProvider::DeleteEntry(content::WebContents* web_contents) { | 425 void WebContentsTaskProvider::DeleteEntry(content::WebContents* web_contents) { |
| 402 // This erase() will delete the WebContentsEntry, which is actually our | 426 // This erase() will delete the WebContentsEntry, which is actually our |
| 403 // caller, but it's expecting us to delete it. | 427 // caller, but it's expecting us to delete it. |
| 404 bool success = entries_map_.erase(web_contents) != 0; | 428 bool success = entries_map_.erase(web_contents) != 0; |
| 405 DCHECK(success); | 429 DCHECK(success); |
| 406 } | 430 } |
| 407 | 431 |
| 408 } // namespace task_manager | 432 } // namespace task_manager |
| OLD | NEW |