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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/resource_coordinator_web_contents_observer.cc
diff --git a/content/browser/resource_coordinator_web_contents_observer.cc b/content/browser/resource_coordinator_web_contents_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..95b096b706a83378a027e5ca3cec1ec031e8157f
--- /dev/null
+++ b/content/browser/resource_coordinator_web_contents_observer.cc
@@ -0,0 +1,75 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/resource_coordinator_web_contents_observer.h"
+
+#include <memory>
+
+#include "content/browser/frame_host/render_frame_host_impl.h"
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/common/service_manager_connection.h"
+
+namespace content {
+
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(ResourceCoordinatorWebContentsObserver);
+
+ResourceCoordinatorWebContentsObserver::ResourceCoordinatorWebContentsObserver(
+ WebContents* web_contents)
+ : WebContentsObserver(web_contents) {
+ resource_coordinator_ =
+ base::MakeUnique<resource_coordinator::ResourceCoordinatorInterface>(
+ ServiceManagerConnection::GetForProcess()->GetConnector(),
+ resource_coordinator::mojom::IDType::WEBCONTENTS);
+}
+
+ResourceCoordinatorWebContentsObserver::
+ ~ResourceCoordinatorWebContentsObserver() = default;
+
+void ResourceCoordinatorWebContentsObserver::WasShown() {
+ DCHECK(resource_coordinator_);
+ resource_coordinator_->SendEvent(
+ resource_coordinator::mojom::EventType::ON_WEBCONTENTS_SHOWN);
+}
+
+void ResourceCoordinatorWebContentsObserver::WasHidden() {
+ DCHECK(resource_coordinator_);
+ resource_coordinator_->SendEvent(
+ resource_coordinator::mojom::EventType::ON_WEBCONTENTS_HIDDEN);
+}
+
+void ResourceCoordinatorWebContentsObserver::ReadyToCommitNavigation(
+ NavigationHandle* navigation_handle) {
+ DCHECK(resource_coordinator_);
+ resource_coordinator::ResourceCoordinatorInterface*
+ frame_resource_coordinator = static_cast<RenderFrameHostImpl*>(
+ navigation_handle->GetRenderFrameHost())
+ ->GetFrameResourceCoordinator();
+ DCHECK(frame_resource_coordinator);
+
+ resource_coordinator_->AddChild(*frame_resource_coordinator);
+ frame_resource_coordinator->SendEvent(
+ resource_coordinator::mojom::EventType::ON_COMMIT);
+}
+
+void ResourceCoordinatorWebContentsObserver::DidFinishNavigation(
+ NavigationHandle* navigation_handle) {
+ DCHECK(resource_coordinator_);
+ RenderFrameHostImpl* render_frame = static_cast<RenderFrameHostImpl*>(
+ navigation_handle->GetRenderFrameHost());
+ DCHECK(render_frame);
+ resource_coordinator::ResourceCoordinatorInterface*
+ frame_resource_coordinator = render_frame->GetFrameResourceCoordinator();
+ DCHECK(frame_resource_coordinator);
+ DCHECK(render_frame->GetProcess());
+ resource_coordinator::ResourceCoordinatorInterface*
+ process_resource_coordinator =
+ static_cast<RenderProcessHostImpl*>(render_frame->GetProcess())
+ ->GetProcessResourceCoordinator();
+ DCHECK(process_resource_coordinator);
+
+ process_resource_coordinator->AddChild(*frame_resource_coordinator);
+ resource_coordinator_->AddChild(*process_resource_coordinator);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698