Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/task_management/providers/web_contents/web_contents_task_provider.cc

Issue 1584473004: Migrate ProcessesEventRouter to the new task manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nit. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/render_widget_host.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_observer.h" 16 #include "content/public/browser/web_contents_observer.h"
16 17
17 using content::RenderFrameHost; 18 using content::RenderFrameHost;
19 using content::RenderWidgetHost;
18 using content::SiteInstance; 20 using content::SiteInstance;
19 using content::WebContents; 21 using content::WebContents;
20 22
21 namespace task_management { 23 namespace task_management {
22 24
23 // Defines an entry for each WebContents that will be tracked by the provider. 25 // 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 26 // 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 27 // and then it notifies the provider or the render task (representing the
26 // WebContents) of these events. 28 // WebContents) of these events.
27 // The entry owns the created tasks representing the WebContents, and it is 29 // The entry owns the created tasks representing the WebContents, and it is
(...skipping 17 matching lines...) Expand all
45 // entry. 47 // entry.
46 RendererTask* GetTaskForFrame(RenderFrameHost* render_frame_host) const; 48 RendererTask* GetTaskForFrame(RenderFrameHost* render_frame_host) const;
47 49
48 // content::WebContentsObserver: 50 // content::WebContentsObserver:
49 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override; 51 void RenderFrameDeleted(RenderFrameHost* render_frame_host) override;
50 void RenderFrameHostChanged(RenderFrameHost* old_host, 52 void RenderFrameHostChanged(RenderFrameHost* old_host,
51 RenderFrameHost* new_host) override; 53 RenderFrameHost* new_host) override;
52 void RenderViewReady() override; 54 void RenderViewReady() override;
53 void WebContentsDestroyed() override; 55 void WebContentsDestroyed() override;
54 void RenderProcessGone(base::TerminationStatus status) override; 56 void RenderProcessGone(base::TerminationStatus status) override;
57 void OnRendererUnresponsive(RenderWidgetHost* render_widget_host) override;
55 void DidNavigateMainFrame( 58 void DidNavigateMainFrame(
56 const content::LoadCommittedDetails& details, 59 const content::LoadCommittedDetails& details,
57 const content::FrameNavigateParams& params) override; 60 const content::FrameNavigateParams& params) override;
58 void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override; 61 void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override;
59 62
60 private: 63 private:
61 // Defines a callback for WebContents::ForEachFrame() to create a 64 // Defines a callback for WebContents::ForEachFrame() to create a
62 // corresponding task for the given |render_frame_host| and notifying the 65 // corresponding task for the given |render_frame_host| and notifying the
63 // provider's observer of the new task. 66 // provider's observer of the new task.
64 void CreateTaskForFrame(RenderFrameHost* render_frame_host); 67 void CreateTaskForFrame(RenderFrameHost* render_frame_host);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 DCHECK(web_contents()->GetMainFrame()); 109 DCHECK(web_contents()->GetMainFrame());
107 web_contents()->ForEachFrame(base::Bind(&WebContentsEntry::CreateTaskForFrame, 110 web_contents()->ForEachFrame(base::Bind(&WebContentsEntry::CreateTaskForFrame,
108 base::Unretained(this))); 111 base::Unretained(this)));
109 } 112 }
110 113
111 void WebContentsEntry::ClearAllTasks(bool notify_observer) { 114 void WebContentsEntry::ClearAllTasks(bool notify_observer) {
112 for (auto& pair : frames_by_site_instance_) { 115 for (auto& pair : frames_by_site_instance_) {
113 FramesList& frames_list = pair.second; 116 FramesList& frames_list = pair.second;
114 DCHECK(!frames_list.empty()); 117 DCHECK(!frames_list.empty());
115 RendererTask* task = tasks_by_frames_[frames_list[0]]; 118 RendererTask* task = tasks_by_frames_[frames_list[0]];
119
120 task->set_termination_status(web_contents()->GetCrashedStatus());
121 task->set_termination_error_code(web_contents()->GetCrashedErrorCode());
122
116 if (notify_observer) 123 if (notify_observer)
117 provider_->NotifyObserverTaskRemoved(task); 124 provider_->NotifyObserverTaskRemoved(task);
118 delete task; 125 delete task;
119 } 126 }
120 127
121 frames_by_site_instance_.clear(); 128 frames_by_site_instance_.clear();
122 tasks_by_frames_.clear(); 129 tasks_by_frames_.clear();
123 main_frame_site_instance_ = nullptr; 130 main_frame_site_instance_ = nullptr;
124 } 131 }
125 132
(...skipping 23 matching lines...) Expand all
149 156
150 void WebContentsEntry::WebContentsDestroyed() { 157 void WebContentsEntry::WebContentsDestroyed() {
151 ClearAllTasks(true); 158 ClearAllTasks(true);
152 provider_->DeleteEntry(web_contents()); 159 provider_->DeleteEntry(web_contents());
153 } 160 }
154 161
155 void WebContentsEntry::RenderProcessGone(base::TerminationStatus status) { 162 void WebContentsEntry::RenderProcessGone(base::TerminationStatus status) {
156 ClearAllTasks(true); 163 ClearAllTasks(true);
157 } 164 }
158 165
166 void WebContentsEntry::OnRendererUnresponsive(
167 RenderWidgetHost* render_widget_host) {
168 auto itr = tasks_by_frames_.find(web_contents()->GetMainFrame());
169 if (itr == tasks_by_frames_.end())
170 return;
171
172 DCHECK_EQ(render_widget_host->GetProcess(),
173 web_contents()->GetMainFrame()->GetProcess());
174
175 provider_->NotifyObserverTaskUnresponsive(itr->second);
176 }
177
159 void WebContentsEntry::DidNavigateMainFrame( 178 void WebContentsEntry::DidNavigateMainFrame(
160 const content::LoadCommittedDetails& details, 179 const content::LoadCommittedDetails& details,
161 const content::FrameNavigateParams& params) { 180 const content::FrameNavigateParams& params) {
162 auto itr = tasks_by_frames_.find(web_contents()->GetMainFrame()); 181 auto itr = tasks_by_frames_.find(web_contents()->GetMainFrame());
163 if (itr == tasks_by_frames_.end()) { 182 if (itr == tasks_by_frames_.end()) {
164 // TODO(afakhry): Validate whether this actually happens in practice. 183 // TODO(afakhry): Validate whether this actually happens in practice.
165 NOTREACHED(); 184 NOTREACHED();
166 return; 185 return;
167 } 186 }
168 187
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 396
378 WebContentsEntry* entry = itr->second; 397 WebContentsEntry* entry = itr->second;
379 entries_map_.erase(itr); 398 entries_map_.erase(itr);
380 399
381 // The entry we're about to delete is our caller, however its' still fine to 400 // The entry we're about to delete is our caller, however its' still fine to
382 // delete it. 401 // delete it.
383 delete entry; 402 delete entry;
384 } 403 }
385 404
386 } // namespace task_management 405 } // namespace task_management
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698