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

Side by Side Diff: chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc

Issue 2925123002: NOCOMMIT PROTOTYPE [GRC] Tab CPU Usage Observer (Closed)
Patch Set: Rebase Created 3 years, 6 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/resource_coordinator/resource_coordinator_web_contents_ observer.h" 5 #include "chrome/browser/resource_coordinator/resource_coordinator_web_contents_ observer.h"
6 6
7 #include "content/public/browser/navigation_handle.h" 7 #include "content/public/browser/navigation_handle.h"
8 #include "content/public/browser/render_frame_host.h" 8 #include "content/public/browser/render_frame_host.h"
9 #include "content/public/browser/render_process_host.h" 9 #include "content/public/browser/render_process_host.h"
10 #include "content/public/common/service_manager_connection.h" 10 #include "content/public/common/service_manager_connection.h"
11 #include "services/resource_coordinator/public/cpp/resource_coordinator_features .h" 11 #include "services/resource_coordinator/public/cpp/resource_coordinator_features .h"
12 #include "services/resource_coordinator/public/interfaces/coordination_unit.mojo m.h"
12 13
13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ResourceCoordinatorWebContentsObserver); 14 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ResourceCoordinatorWebContentsObserver);
14 15
15 ResourceCoordinatorWebContentsObserver::ResourceCoordinatorWebContentsObserver( 16 ResourceCoordinatorWebContentsObserver::ResourceCoordinatorWebContentsObserver(
16 content::WebContents* web_contents) 17 content::WebContents* web_contents)
17 : WebContentsObserver(web_contents) { 18 : WebContentsObserver(web_contents) {
18 tab_resource_coordinator_ = 19 tab_resource_coordinator_ =
19 base::MakeUnique<resource_coordinator::ResourceCoordinatorInterface>( 20 base::MakeUnique<resource_coordinator::ResourceCoordinatorInterface>(
20 content::ServiceManagerConnection::GetForProcess()->GetConnector(), 21 content::ServiceManagerConnection::GetForProcess()->GetConnector(),
21 resource_coordinator::CoordinationUnitType::kWebContents); 22 resource_coordinator::CoordinationUnitType::kWebContents);
(...skipping 22 matching lines...) Expand all
44 if (!navigation_handle->HasCommitted() || navigation_handle->IsErrorPage() || 45 if (!navigation_handle->HasCommitted() || navigation_handle->IsErrorPage() ||
45 navigation_handle->IsSameDocument()) { 46 navigation_handle->IsSameDocument()) {
46 return; 47 return;
47 } 48 }
48 49
49 content::RenderFrameHost* render_frame_host = 50 content::RenderFrameHost* render_frame_host =
50 navigation_handle->GetRenderFrameHost(); 51 navigation_handle->GetRenderFrameHost();
51 52
52 auto* frame_resource_coordinator = 53 auto* frame_resource_coordinator =
53 render_frame_host->GetFrameResourceCoordinator(); 54 render_frame_host->GetFrameResourceCoordinator();
55
54 tab_resource_coordinator_->AddChild(*frame_resource_coordinator); 56 tab_resource_coordinator_->AddChild(*frame_resource_coordinator);
55 57
58 content::RenderFrameHost* parent_frame_host = render_frame_host->GetParent();
59 if (parent_frame_host) {
60 auto* parent_frame_resource_coordinator =
61 parent_frame_host->GetFrameResourceCoordinator();
62 parent_frame_resource_coordinator->AddChild(*frame_resource_coordinator);
63 }
64
56 auto* process_resource_coordinator = 65 auto* process_resource_coordinator =
57 render_frame_host->GetProcess()->GetProcessResourceCoordinator(); 66 render_frame_host->GetProcess()->GetProcessResourceCoordinator();
58 process_resource_coordinator->AddChild(*frame_resource_coordinator); 67 process_resource_coordinator->AddChild(*frame_resource_coordinator);
68
69 if (navigation_handle->IsInMainFrame()) {
70 base::Value url_value = base::Value(navigation_handle->GetURL().spec());
71 tab_resource_coordinator_->SetProperty(
72 resource_coordinator::mojom::PropertyType::kTabURL, url_value);
73 }
59 } 74 }
75
76 void ResourceCoordinatorWebContentsObserver::RemoveFrameFromParents(
77 content::RenderFrameHost* render_frame_host) {
78 auto* frame_resource_coordinator =
79 render_frame_host->GetFrameResourceCoordinator();
80
81 tab_resource_coordinator_->RemoveChild(*frame_resource_coordinator);
82
83 content::RenderFrameHost* parent_frame_host = render_frame_host->GetParent();
84 if (parent_frame_host) {
85 auto* parent_frame_resource_coordinator =
86 parent_frame_host->GetFrameResourceCoordinator();
87 parent_frame_resource_coordinator->RemoveChild(*frame_resource_coordinator);
88 }
89
90 auto* process_resource_coordinator =
91 render_frame_host->GetProcess()->GetProcessResourceCoordinator();
92 process_resource_coordinator->RemoveChild(*frame_resource_coordinator);
93 }
94
95 void ResourceCoordinatorWebContentsObserver::RenderFrameDeleted(
96 content::RenderFrameHost* render_frame_host) {
97 RemoveFrameFromParents(render_frame_host);
98 }
99
100 void ResourceCoordinatorWebContentsObserver::RenderFrameHostChanged(
101 content::RenderFrameHost* old_host,
102 content::RenderFrameHost* new_host) {
103 if (old_host) {
104 RemoveFrameFromParents(old_host);
105 }
106 }
107
108 void ResourceCoordinatorWebContentsObserver::FrameDeleted(
109 content::RenderFrameHost* render_frame_host) {
110 RemoveFrameFromParents(render_frame_host);
111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698