| 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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 RendererTask* GetTaskForFrame(RenderFrameHost* render_frame_host) const; | 48 RendererTask* GetTaskForFrame(RenderFrameHost* render_frame_host) const; |
| 49 | 49 |
| 50 // content::WebContentsObserver: | 50 // content::WebContentsObserver: |
| 51 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; | 51 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
| 52 void RenderFrameHostChanged(RenderFrameHost* old_host, | 52 void RenderFrameHostChanged(RenderFrameHost* old_host, |
| 53 RenderFrameHost* new_host) override; | 53 RenderFrameHost* new_host) override; |
| 54 void RenderViewReady() override; | 54 void RenderViewReady() override; |
| 55 void WebContentsDestroyed() override; | 55 void WebContentsDestroyed() override; |
| 56 void RenderProcessGone(base::TerminationStatus status) override; | 56 void RenderProcessGone(base::TerminationStatus status) override; |
| 57 void OnRendererUnresponsive(RenderWidgetHost* render_widget_host) override; | 57 void OnRendererUnresponsive(RenderWidgetHost* render_widget_host) override; |
| 58 void DidNavigateMainFrame( | 58 void DidFinishNavigation( |
| 59 const content::LoadCommittedDetails& details, | 59 content::NavigationHandle* navigation_handle) override; |
| 60 const content::FrameNavigateParams& params) override; | |
| 61 void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override; | 60 void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override; |
| 62 | 61 |
| 63 private: | 62 private: |
| 64 // Defines a callback for WebContents::ForEachFrame() to create a | 63 // Defines a callback for WebContents::ForEachFrame() to create a |
| 65 // corresponding task for the given |render_frame_host| and notifying the | 64 // corresponding task for the given |render_frame_host| and notifying the |
| 66 // provider's observer of the new task. | 65 // provider's observer of the new task. |
| 67 void CreateTaskForFrame(RenderFrameHost* render_frame_host); | 66 void CreateTaskForFrame(RenderFrameHost* render_frame_host); |
| 68 | 67 |
| 69 // Clears the task that corresponds to the given |render_frame_host| and | 68 // Clears the task that corresponds to the given |render_frame_host| and |
| 70 // notifies the provider's observer of the tasks removal. | 69 // notifies the provider's observer of the tasks removal. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 ClearAllTasks(true); | 155 ClearAllTasks(true); |
| 157 provider_->DeleteEntry(web_contents()); | 156 provider_->DeleteEntry(web_contents()); |
| 158 } | 157 } |
| 159 | 158 |
| 160 void WebContentsEntry::RenderProcessGone(base::TerminationStatus status) { | 159 void WebContentsEntry::RenderProcessGone(base::TerminationStatus status) { |
| 161 ClearAllTasks(true); | 160 ClearAllTasks(true); |
| 162 } | 161 } |
| 163 | 162 |
| 164 void WebContentsEntry::OnRendererUnresponsive( | 163 void WebContentsEntry::OnRendererUnresponsive( |
| 165 RenderWidgetHost* render_widget_host) { | 164 RenderWidgetHost* render_widget_host) { |
| 166 auto itr = tasks_by_frames_.find(web_contents()->GetMainFrame()); | 165 RendererTask* task = GetTaskForFrame(web_contents()->GetMainFrame()); |
| 167 if (itr == tasks_by_frames_.end()) | 166 if (!task) |
| 168 return; | 167 return; |
| 169 | 168 |
| 170 DCHECK_EQ(render_widget_host->GetProcess(), | 169 DCHECK_EQ(render_widget_host->GetProcess(), |
| 171 web_contents()->GetMainFrame()->GetProcess()); | 170 web_contents()->GetMainFrame()->GetProcess()); |
| 172 | 171 |
| 173 provider_->NotifyObserverTaskUnresponsive(itr->second); | 172 provider_->NotifyObserverTaskUnresponsive(task); |
| 174 } | 173 } |
| 175 | 174 |
| 176 void WebContentsEntry::DidNavigateMainFrame( | 175 void WebContentsEntry::DidFinishNavigation( |
| 177 const content::LoadCommittedDetails& details, | 176 content::NavigationHandle* navigation_handle) { |
| 178 const content::FrameNavigateParams& params) { | 177 RendererTask* task = GetTaskForFrame(web_contents()->GetMainFrame()); |
| 179 auto itr = tasks_by_frames_.find(web_contents()->GetMainFrame()); | 178 if (!task) |
| 180 if (itr == tasks_by_frames_.end()) { | |
| 181 // TODO(afakhry): Validate whether this actually happens in practice. | |
| 182 NOTREACHED(); | |
| 183 return; | 179 return; |
| 184 } | |
| 185 | 180 |
| 186 // Listening to WebContentsObserver::TitleWasSet() only is not enough in | 181 // Listening to WebContentsObserver::TitleWasSet() only is not enough in |
| 187 // some cases when the the webpage doesn't have a title. That's why we update | 182 // some cases when the the webpage doesn't have a title. That's why we update |
| 188 // the title here as well. | 183 // the title here as well. |
| 189 itr->second->UpdateTitle(); | 184 task->UpdateTitle(); |
| 190 | 185 |
| 191 // Call RendererTask::UpdateFavicon() to set the current favicon to the | 186 // Call RendererTask::UpdateFavicon() to set the current favicon to the |
| 192 // default favicon. If the page has a non-default favicon, | 187 // default favicon. If the page has a non-default favicon, |
| 193 // RendererTask::OnFaviconUpdated() will update the current favicon once | 188 // RendererTask::OnFaviconUpdated() will update the current favicon once |
| 194 // FaviconDriver figures out the correct favicon for the page. | 189 // FaviconDriver figures out the correct favicon for the page. |
| 195 itr->second->UpdateFavicon(); | 190 task->UpdateFavicon(); |
| 196 itr->second->UpdateRapporSampleName(); | 191 task->UpdateRapporSampleName(); |
| 197 } | 192 } |
| 198 | 193 |
| 199 void WebContentsEntry::TitleWasSet(content::NavigationEntry* entry, | 194 void WebContentsEntry::TitleWasSet(content::NavigationEntry* entry, |
| 200 bool explicit_set) { | 195 bool explicit_set) { |
| 201 auto itr = tasks_by_frames_.find(web_contents()->GetMainFrame()); | 196 RendererTask* task = GetTaskForFrame(web_contents()->GetMainFrame()); |
| 202 if (itr == tasks_by_frames_.end()) { | 197 if (!task) |
| 203 // TODO(afakhry): Validate whether this actually happens in practice. | |
| 204 NOTREACHED(); | |
| 205 return; | 198 return; |
| 206 } | |
| 207 | 199 |
| 208 itr->second->UpdateTitle(); | 200 task->UpdateTitle(); |
| 201 task->UpdateFavicon(); |
| 209 } | 202 } |
| 210 | 203 |
| 211 void WebContentsEntry::CreateTaskForFrame(RenderFrameHost* render_frame_host) { | 204 void WebContentsEntry::CreateTaskForFrame(RenderFrameHost* render_frame_host) { |
| 212 DCHECK(!ContainsKey(tasks_by_frames_, render_frame_host)); | 205 DCHECK(!ContainsKey(tasks_by_frames_, render_frame_host)); |
| 213 | 206 |
| 214 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); | 207 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); |
| 215 if (!site_instance->GetProcess()->HasConnection()) | 208 if (!site_instance->GetProcess()->HasConnection()) |
| 216 return; | 209 return; |
| 217 | 210 |
| 218 bool site_instance_exists = | 211 bool site_instance_exists = |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 387 |
| 395 WebContentsEntry* entry = itr->second; | 388 WebContentsEntry* entry = itr->second; |
| 396 entries_map_.erase(itr); | 389 entries_map_.erase(itr); |
| 397 | 390 |
| 398 // The entry we're about to delete is our caller, however its' still fine to | 391 // The entry we're about to delete is our caller, however its' still fine to |
| 399 // delete it. | 392 // delete it. |
| 400 delete entry; | 393 delete entry; |
| 401 } | 394 } |
| 402 | 395 |
| 403 } // namespace task_management | 396 } // namespace task_management |
| OLD | NEW |