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; |
Charlie Reis
2016/06/24 22:21:17
Hooray! Thanks for moving to the new NavHandle-ba
afakhry
2016/06/27 14:29:18
Yes, Nick told me DidNavigateMainFrame() will be d
| |
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; |
61 void DidAttachInterstitialPage() override; | |
62 void DidDetachInterstitialPage() override; | |
62 | 63 |
63 private: | 64 private: |
64 // Defines a callback for WebContents::ForEachFrame() to create a | 65 // Defines a callback for WebContents::ForEachFrame() to create a |
65 // corresponding task for the given |render_frame_host| and notifying the | 66 // corresponding task for the given |render_frame_host| and notifying the |
66 // provider's observer of the new task. | 67 // provider's observer of the new task. |
67 void CreateTaskForFrame(RenderFrameHost* render_frame_host); | 68 void CreateTaskForFrame(RenderFrameHost* render_frame_host); |
68 | 69 |
69 // Clears the task that corresponds to the given |render_frame_host| and | 70 // Clears the task that corresponds to the given |render_frame_host| and |
70 // notifies the provider's observer of the tasks removal. | 71 // notifies the provider's observer of the tasks removal. |
71 void ClearTaskForFrame(RenderFrameHost* render_frame_host); | 72 void ClearTaskForFrame(RenderFrameHost* render_frame_host); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 ClearAllTasks(true); | 157 ClearAllTasks(true); |
157 provider_->DeleteEntry(web_contents()); | 158 provider_->DeleteEntry(web_contents()); |
158 } | 159 } |
159 | 160 |
160 void WebContentsEntry::RenderProcessGone(base::TerminationStatus status) { | 161 void WebContentsEntry::RenderProcessGone(base::TerminationStatus status) { |
161 ClearAllTasks(true); | 162 ClearAllTasks(true); |
162 } | 163 } |
163 | 164 |
164 void WebContentsEntry::OnRendererUnresponsive( | 165 void WebContentsEntry::OnRendererUnresponsive( |
165 RenderWidgetHost* render_widget_host) { | 166 RenderWidgetHost* render_widget_host) { |
166 auto itr = tasks_by_frames_.find(web_contents()->GetMainFrame()); | 167 RendererTask* task = GetTaskForFrame(web_contents()->GetMainFrame()); |
167 if (itr == tasks_by_frames_.end()) | 168 if (!task) |
168 return; | 169 return; |
169 | 170 |
170 DCHECK_EQ(render_widget_host->GetProcess(), | 171 DCHECK_EQ(render_widget_host->GetProcess(), |
171 web_contents()->GetMainFrame()->GetProcess()); | 172 web_contents()->GetMainFrame()->GetProcess()); |
Charlie Reis
2016/06/24 22:21:17
This line caught my eye, since it looks buggy for
afakhry
2016/06/27 14:29:18
I saw the bug you filed, and I will handle it soon
| |
172 | 173 |
173 provider_->NotifyObserverTaskUnresponsive(itr->second); | 174 provider_->NotifyObserverTaskUnresponsive(task); |
174 } | 175 } |
175 | 176 |
176 void WebContentsEntry::DidNavigateMainFrame( | 177 void WebContentsEntry::DidFinishNavigation( |
177 const content::LoadCommittedDetails& details, | 178 content::NavigationHandle* navigation_handle) { |
178 const content::FrameNavigateParams& params) { | 179 RendererTask* task = GetTaskForFrame(web_contents()->GetMainFrame()); |
179 auto itr = tasks_by_frames_.find(web_contents()->GetMainFrame()); | 180 if (!task) |
180 if (itr == tasks_by_frames_.end()) { | |
181 // TODO(afakhry): Validate whether this actually happens in practice. | |
182 NOTREACHED(); | |
183 return; | 181 return; |
184 } | |
185 | 182 |
186 // Listening to WebContentsObserver::TitleWasSet() only is not enough in | 183 // 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 | 184 // some cases when the the webpage doesn't have a title. That's why we update |
188 // the title here as well. | 185 // the title here as well. |
189 itr->second->UpdateTitle(); | 186 task->UpdateTitle(); |
190 | 187 |
191 // Call RendererTask::UpdateFavicon() to set the current favicon to the | 188 // Call RendererTask::UpdateFavicon() to set the current favicon to the |
192 // default favicon. If the page has a non-default favicon, | 189 // default favicon. If the page has a non-default favicon, |
193 // RendererTask::OnFaviconUpdated() will update the current favicon once | 190 // RendererTask::OnFaviconUpdated() will update the current favicon once |
194 // FaviconDriver figures out the correct favicon for the page. | 191 // FaviconDriver figures out the correct favicon for the page. |
195 itr->second->UpdateFavicon(); | 192 task->UpdateFavicon(); |
196 itr->second->UpdateRapporSampleName(); | 193 task->UpdateRapporSampleName(); |
197 } | 194 } |
198 | 195 |
199 void WebContentsEntry::TitleWasSet(content::NavigationEntry* entry, | 196 void WebContentsEntry::TitleWasSet(content::NavigationEntry* entry, |
200 bool explicit_set) { | 197 bool explicit_set) { |
201 auto itr = tasks_by_frames_.find(web_contents()->GetMainFrame()); | 198 RendererTask* task = GetTaskForFrame(web_contents()->GetMainFrame()); |
202 if (itr == tasks_by_frames_.end()) { | 199 if (!task) |
203 // TODO(afakhry): Validate whether this actually happens in practice. | |
204 NOTREACHED(); | |
205 return; | 200 return; |
206 } | |
207 | 201 |
208 itr->second->UpdateTitle(); | 202 task->UpdateTitle(); |
203 } | |
204 | |
205 void WebContentsEntry::DidAttachInterstitialPage() { | |
Charlie Reis
2016/06/24 22:21:17
Not sure I understand-- why do we need DidAttachIn
afakhry
2016/06/27 14:29:18
Updating titles here alone is not enough. It will
Charlie Reis
2016/06/28 00:47:09
I think I'm ok with that. Just curious, would we
afakhry
2016/06/28 14:34:16
No we won't need listening to the attach/detach ev
| |
206 RendererTask* task = GetTaskForFrame(web_contents()->GetMainFrame()); | |
207 if (!task) | |
208 return; | |
209 | |
210 task->UpdateTitle(); | |
211 task->UpdateFavicon(); | |
212 } | |
213 | |
214 void WebContentsEntry::DidDetachInterstitialPage() { | |
215 RendererTask* task = GetTaskForFrame(web_contents()->GetMainFrame()); | |
216 if (!task) | |
217 return; | |
218 | |
219 task->UpdateTitle(); | |
220 task->UpdateFavicon(); | |
209 } | 221 } |
210 | 222 |
211 void WebContentsEntry::CreateTaskForFrame(RenderFrameHost* render_frame_host) { | 223 void WebContentsEntry::CreateTaskForFrame(RenderFrameHost* render_frame_host) { |
212 DCHECK(!ContainsKey(tasks_by_frames_, render_frame_host)); | 224 DCHECK(!ContainsKey(tasks_by_frames_, render_frame_host)); |
213 | 225 |
214 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); | 226 content::SiteInstance* site_instance = render_frame_host->GetSiteInstance(); |
215 if (!site_instance->GetProcess()->HasConnection()) | 227 if (!site_instance->GetProcess()->HasConnection()) |
216 return; | 228 return; |
217 | 229 |
218 bool site_instance_exists = | 230 bool site_instance_exists = |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 | 406 |
395 WebContentsEntry* entry = itr->second; | 407 WebContentsEntry* entry = itr->second; |
396 entries_map_.erase(itr); | 408 entries_map_.erase(itr); |
397 | 409 |
398 // The entry we're about to delete is our caller, however its' still fine to | 410 // The entry we're about to delete is our caller, however its' still fine to |
399 // delete it. | 411 // delete it. |
400 delete entry; | 412 delete entry; |
401 } | 413 } |
402 | 414 |
403 } // namespace task_management | 415 } // namespace task_management |
OLD | NEW |