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

Side by Side Diff: content/browser/resource_coordinator_web_contents_observer.cc

Issue 2710823003: NOCOMMIT prototype: GRC service plumbing and process priority
Patch Set: Buildfixes Created 3 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/browser/resource_coordinator_web_contents_observer.h"
6
7 #include <memory>
8
9 #include "content/browser/frame_host/render_frame_host_impl.h"
10 #include "content/public/browser/navigation_handle.h"
11 #include "content/public/common/service_manager_connection.h"
12
13 namespace content {
14
15 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ResourceCoordinatorWebContentsObserver);
16
17 ResourceCoordinatorWebContentsObserver::ResourceCoordinatorWebContentsObserver(
18 WebContents* web_contents)
19 : WebContentsObserver(web_contents) {
20 resource_coordinator_ =
21 base::MakeUnique<resource_coordinator::ResourceCoordinatorInterface>(
22 ServiceManagerConnection::GetForProcess()->GetConnector(),
23 resource_coordinator::mojom::IDType::WEBCONTENTS);
24 }
25
26 ResourceCoordinatorWebContentsObserver::
27 ~ResourceCoordinatorWebContentsObserver() = default;
28
29 void ResourceCoordinatorWebContentsObserver::WasShown() {
30 DCHECK(resource_coordinator_);
31 resource_coordinator_->SendEvent(
32 resource_coordinator::mojom::EventType::ON_WEBCONTENTS_SHOWN);
33 }
34
35 void ResourceCoordinatorWebContentsObserver::WasHidden() {
36 DCHECK(resource_coordinator_);
37 resource_coordinator_->SendEvent(
38 resource_coordinator::mojom::EventType::ON_WEBCONTENTS_HIDDEN);
39 }
40
41 void ResourceCoordinatorWebContentsObserver::ReadyToCommitNavigation(
42 NavigationHandle* navigation_handle) {
43 DCHECK(resource_coordinator_);
44 resource_coordinator::ResourceCoordinatorInterface*
45 frame_resource_coordinator = static_cast<RenderFrameHostImpl*>(
46 navigation_handle->GetRenderFrameHost())
47 ->GetFrameResourceCoordinator();
48 DCHECK(frame_resource_coordinator);
49
50 resource_coordinator_->AddChild(*frame_resource_coordinator);
51 frame_resource_coordinator->SendEvent(
52 resource_coordinator::mojom::EventType::ON_COMMIT);
53 }
54
55 void ResourceCoordinatorWebContentsObserver::DidFinishNavigation(
56 NavigationHandle* navigation_handle) {
57 DCHECK(resource_coordinator_);
58 RenderFrameHostImpl* render_frame = static_cast<RenderFrameHostImpl*>(
59 navigation_handle->GetRenderFrameHost());
60 DCHECK(render_frame);
61 resource_coordinator::ResourceCoordinatorInterface*
62 frame_resource_coordinator = render_frame->GetFrameResourceCoordinator();
63 DCHECK(frame_resource_coordinator);
64 DCHECK(render_frame->GetProcess());
65 resource_coordinator::ResourceCoordinatorInterface*
66 process_resource_coordinator =
67 static_cast<RenderProcessHostImpl*>(render_frame->GetProcess())
68 ->GetProcessResourceCoordinator();
69 DCHECK(process_resource_coordinator);
70
71 process_resource_coordinator->AddChild(*frame_resource_coordinator);
72 resource_coordinator_->AddChild(*process_resource_coordinator);
73 }
74
75 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698