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/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "chrome/browser/task_management/providers/web_contents/subframe_task.h" | 9 #include "chrome/browser/task_management/providers/web_contents/subframe_task.h" |
10 #include "chrome/browser/task_management/providers/web_contents/web_contents_tag s_manager.h" | 10 #include "chrome/browser/task_management/providers/web_contents/web_contents_tag s_manager.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 class WebContentsEntry : public content::WebContentsObserver { | 28 class WebContentsEntry : public content::WebContentsObserver { |
29 public: | 29 public: |
30 WebContentsEntry(content::WebContents* web_contents, | 30 WebContentsEntry(content::WebContents* web_contents, |
31 WebContentsTaskProvider* provider); | 31 WebContentsTaskProvider* provider); |
32 ~WebContentsEntry() override; | 32 ~WebContentsEntry() override; |
33 | 33 |
34 // Creates all the tasks associated with each |RenderFrameHost| in this | 34 // Creates all the tasks associated with each |RenderFrameHost| in this |
35 // entry's WebContents. | 35 // entry's WebContents. |
36 void CreateAllTasks(); | 36 void CreateAllTasks(); |
37 | 37 |
38 // Clears all the tasks in this entry. The provider's observer will be | |
39 // notified if |notify_observer| is true. | |
40 void ClearAllTasks(bool notify_observer); | |
gavinp
2015/06/22 18:38:04
Nit: I think the method definition should move to
afakhry
2015/06/22 21:56:18
Thanks for catching that! I forgot to do it.
Done!
| |
41 | |
38 // Returns the |RendererTask| that corresponds to the given | 42 // Returns the |RendererTask| that corresponds to the given |
39 // |render_frame_host| or |nullptr| if the given frame is not tracked by this | 43 // |render_frame_host| or |nullptr| if the given frame is not tracked by this |
40 // entry. | 44 // entry. |
41 RendererTask* GetTaskForFrame(RenderFrameHost* render_frame_host) const; | 45 RendererTask* GetTaskForFrame(RenderFrameHost* render_frame_host) const; |
42 | 46 |
43 // content::WebContentsObserver: | 47 // content::WebContentsObserver: |
44 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; | 48 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; |
45 void RenderFrameHostChanged(RenderFrameHost* old_host, | 49 void RenderFrameHostChanged(RenderFrameHost* old_host, |
46 RenderFrameHost* new_host) override; | 50 RenderFrameHost* new_host) override; |
47 void RenderViewReady() override; | 51 void RenderViewReady() override; |
48 void WebContentsDestroyed() override; | 52 void WebContentsDestroyed() override; |
49 void RenderProcessGone(base::TerminationStatus status) override; | 53 void RenderProcessGone(base::TerminationStatus status) override; |
50 void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override; | 54 void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override; |
51 void DidUpdateFaviconURL( | 55 void DidUpdateFaviconURL( |
52 const std::vector<content::FaviconURL>& candidates) override; | 56 const std::vector<content::FaviconURL>& candidates) override; |
53 | 57 |
54 private: | 58 private: |
55 // Defines a callback for WebContents::ForEachFrame() to create a | 59 // Defines a callback for WebContents::ForEachFrame() to create a |
56 // corresponding task for the given |render_frame_host| and notifying the | 60 // corresponding task for the given |render_frame_host| and notifying the |
57 // provider's observer of the new task. | 61 // provider's observer of the new task. |
58 void CreateTaskForFrame(RenderFrameHost* render_frame_host); | 62 void CreateTaskForFrame(RenderFrameHost* render_frame_host); |
59 | 63 |
60 // Clears the task that corresponds to the given |render_frame_host| and | 64 // Clears the task that corresponds to the given |render_frame_host| and |
61 // notifies the provider's observer of the tasks removal. | 65 // notifies the provider's observer of the tasks removal. |
62 void ClearTaskForFrame(RenderFrameHost* render_frame_host); | 66 void ClearTaskForFrame(RenderFrameHost* render_frame_host); |
63 | 67 |
64 // Clears all the tasks in this entry. The provider's observer will be | |
65 // notified if |notify_observer| is true. | |
66 void ClearAllTasks(bool notify_observer); | |
67 | |
68 // The provider that owns this entry. | 68 // The provider that owns this entry. |
69 WebContentsTaskProvider* provider_; | 69 WebContentsTaskProvider* provider_; |
70 | 70 |
71 // The RenderFrameHosts associated with this entry's WebContents that we're | 71 // The RenderFrameHosts associated with this entry's WebContents that we're |
72 // tracking mapped by their SiteInstances. | 72 // tracking mapped by their SiteInstances. |
73 typedef std::vector<RenderFrameHost*> FramesList; | 73 typedef std::vector<RenderFrameHost*> FramesList; |
74 typedef std::map<SiteInstance*, FramesList> SiteInstanceToFramesMap; | 74 typedef std::map<SiteInstance*, FramesList> SiteInstanceToFramesMap; |
75 SiteInstanceToFramesMap frames_by_site_instance_; | 75 SiteInstanceToFramesMap frames_by_site_instance_; |
76 | 76 |
77 // The RendererTasks that we create for the task manager, mapped by their | 77 // The RendererTasks that we create for the task manager, mapped by their |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
255 | 255 |
256 //////////////////////////////////////////////////////////////////////////////// | 256 //////////////////////////////////////////////////////////////////////////////// |
257 | 257 |
258 WebContentsTaskProvider::WebContentsTaskProvider() : entries_map_() { | 258 WebContentsTaskProvider::WebContentsTaskProvider() : entries_map_() { |
259 } | 259 } |
260 | 260 |
261 WebContentsTaskProvider::~WebContentsTaskProvider() { | 261 WebContentsTaskProvider::~WebContentsTaskProvider() { |
262 STLDeleteValues(&entries_map_); | 262 STLDeleteValues(&entries_map_); |
263 } | 263 } |
264 | 264 |
265 void WebContentsTaskProvider::OnWebContentsTagCreated(WebContentsTag* tag) { | 265 void WebContentsTaskProvider::OnWebContentsTagCreated( |
266 const WebContentsTag* tag) { | |
266 DCHECK(tag); | 267 DCHECK(tag); |
267 content::WebContents* web_contents = tag->web_contents(); | 268 content::WebContents* web_contents = tag->web_contents(); |
268 DCHECK(web_contents); | 269 DCHECK(web_contents); |
269 | 270 |
270 // TODO(afakhry): Check if we need this check. It seems that we no longer | 271 // TODO(afakhry): Check if we need this check. It seems that we no longer |
271 // need it in the new implementation. | 272 // need it in the new implementation. |
272 if (entries_map_.count(web_contents)) { | 273 if (entries_map_.count(web_contents)) { |
273 // This case may happen if we added a WebContents while collecting all the | 274 // This case may happen if we added a WebContents while collecting all the |
274 // pre-existing ones at the time |StartUpdating()| was called, but the | 275 // pre-existing ones at the time |StartUpdating()| was called, but the |
275 // notification of its connection hasn't been fired yet. In this case we | 276 // notification of its connection hasn't been fired yet. In this case we |
276 // ignore it since we're already tracking it. | 277 // ignore it since we're already tracking it. |
277 return; | 278 return; |
278 } | 279 } |
279 | 280 |
280 WebContentsEntry* entry = new WebContentsEntry(web_contents, this); | 281 WebContentsEntry* entry = new WebContentsEntry(web_contents, this); |
281 entries_map_[web_contents] = entry; | 282 entries_map_[web_contents] = entry; |
282 entry->CreateAllTasks(); | 283 entry->CreateAllTasks(); |
283 } | 284 } |
284 | 285 |
286 void WebContentsTaskProvider::OnWebContentsTagRemoved( | |
287 const WebContentsTag* tag) { | |
288 DCHECK(tag); | |
289 content::WebContents* web_contents = tag->web_contents(); | |
290 DCHECK(web_contents); | |
291 | |
292 auto itr = entries_map_.find(web_contents); | |
293 DCHECK(itr != entries_map_.end()); | |
294 WebContentsEntry* entry = itr->second; | |
295 | |
296 // Must manually clear the tasks and notify the observer. | |
297 entry->ClearAllTasks(true); | |
298 entries_map_.erase(itr); | |
299 delete entry; | |
300 } | |
301 | |
285 Task* WebContentsTaskProvider::GetTaskOfUrlRequest(int origin_pid, | 302 Task* WebContentsTaskProvider::GetTaskOfUrlRequest(int origin_pid, |
286 int child_id, | 303 int child_id, |
287 int route_id) { | 304 int route_id) { |
288 // If an origin PID was specified then the URL request originated in a plugin | 305 // If an origin PID was specified then the URL request originated in a plugin |
289 // working on the WebContents' behalf, so ignore it. | 306 // working on the WebContents' behalf, so ignore it. |
290 if (origin_pid) | 307 if (origin_pid) |
291 return nullptr; | 308 return nullptr; |
292 | 309 |
293 content::RenderFrameHost* rfh = | 310 content::RenderFrameHost* rfh = |
294 content::RenderFrameHost::FromID(child_id, route_id); | 311 content::RenderFrameHost::FromID(child_id, route_id); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 | 354 |
338 WebContentsEntry* entry = itr->second; | 355 WebContentsEntry* entry = itr->second; |
339 entries_map_.erase(itr); | 356 entries_map_.erase(itr); |
340 | 357 |
341 // The entry we're about to delete is our caller, however its' still fine to | 358 // The entry we're about to delete is our caller, however its' still fine to |
342 // delete it. | 359 // delete it. |
343 delete entry; | 360 delete entry; |
344 } | 361 } |
345 | 362 |
346 } // namespace task_management | 363 } // namespace task_management |
OLD | NEW |