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

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

Issue 2938443002: [GRC] UKM Support (Closed)
Patch Set: Refactor 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 <utility>
8
9 #include "components/ukm/public/interfaces/ukm_interface.mojom.h"
7 #include "content/public/browser/navigation_handle.h" 10 #include "content/public/browser/navigation_handle.h"
8 #include "content/public/browser/render_frame_host.h" 11 #include "content/public/browser/render_frame_host.h"
9 #include "content/public/browser/render_process_host.h" 12 #include "content/public/browser/render_process_host.h"
10 #include "content/public/common/service_manager_connection.h" 13 #include "content/public/common/service_manager_connection.h"
14 #include "content/public/common/service_names.mojom.h"
15 #include "content/public/renderer/render_thread.h"
11 #include "services/resource_coordinator/public/cpp/resource_coordinator_features .h" 16 #include "services/resource_coordinator/public/cpp/resource_coordinator_features .h"
17 #include "services/resource_coordinator/public/interfaces/service_callbacks.mojo m.h"
18 #include "services/resource_coordinator/public/interfaces/service_constants.mojo m.h"
19 #include "services/service_manager/public/cpp/connector.h"
12 20
13 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ResourceCoordinatorWebContentsObserver); 21 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ResourceCoordinatorWebContentsObserver);
14 22
15 ResourceCoordinatorWebContentsObserver::ResourceCoordinatorWebContentsObserver( 23 ResourceCoordinatorWebContentsObserver::ResourceCoordinatorWebContentsObserver(
16 content::WebContents* web_contents) 24 content::WebContents* web_contents)
17 : WebContentsObserver(web_contents) { 25 : WebContentsObserver(web_contents) {
26 service_manager::Connector* connector =
27 content::ServiceManagerConnection::GetForProcess()->GetConnector();
28
18 tab_resource_coordinator_ = 29 tab_resource_coordinator_ =
19 base::MakeUnique<resource_coordinator::ResourceCoordinatorInterface>( 30 base::MakeUnique<resource_coordinator::ResourceCoordinatorInterface>(
20 content::ServiceManagerConnection::GetForProcess()->GetConnector(), 31 connector, resource_coordinator::CoordinationUnitType::kWebContents);
21 resource_coordinator::CoordinationUnitType::kWebContents); 32
33 connector->BindInterface(resource_coordinator::mojom::kServiceName,
34 mojo::MakeRequest(&service_callbacks_));
35
36 EnsureUkmRecorderInterface();
37 }
38
39 // TODO(matthalp) integrate into ResourceCoordinatorService once the UKM mojo
40 // interface can be accessed directly within GRC. GRC cannot currently use
41 // the UKM mojo inteface directly because of software layering issues
42 // (i.e. the UKM mojo interface is only reachable from the content_browser
43 // service which cannot be accesses by services in the services/ directory).
44 // Instead the ResourceCoordinatorWebContentsObserver is used as it lives
45 // within the content_browser service and can initialize the
46 // UkmRecorderInterface and pass that interface into GRC through
47 // resource_coordinator::mojom::ServiceCallbacks.
48 void ResourceCoordinatorWebContentsObserver::EnsureUkmRecorderInterface() {
49 service_callbacks_->IsUkmRecorderInterfaceInitialized(base::Bind(
50 &ResourceCoordinatorWebContentsObserver::MaybeSetUkmRecorderInterface,
51 base::Unretained(this)));
52 }
53
54 void ResourceCoordinatorWebContentsObserver::MaybeSetUkmRecorderInterface(
oystein (OOO til 10th of July) 2017/06/22 20:27:02 As an additional optimization, maybe set a static
matthalp 2017/06/22 22:59:30 Good suggestion -- done.
55 bool ukm_recorder_already_initialized) {
56 if (ukm_recorder_already_initialized) {
57 return;
58 }
59
60 ukm::mojom::UkmRecorderInterfacePtr ukm_recorder_interface;
61 content::ServiceManagerConnection::GetForProcess()
62 ->GetConnector()
63 ->BindInterface(content::mojom::kBrowserServiceName,
64 mojo::MakeRequest(&ukm_recorder_interface));
65 service_callbacks_->SetUkmRecorderInterface(
66 std::move(ukm_recorder_interface));
22 } 67 }
23 68
24 ResourceCoordinatorWebContentsObserver:: 69 ResourceCoordinatorWebContentsObserver::
25 ~ResourceCoordinatorWebContentsObserver() = default; 70 ~ResourceCoordinatorWebContentsObserver() = default;
26 71
27 // static 72 // static
28 bool ResourceCoordinatorWebContentsObserver::IsEnabled() { 73 bool ResourceCoordinatorWebContentsObserver::IsEnabled() {
29 return base::FeatureList::IsEnabled(features::kGlobalResourceCoordinator); 74 return base::FeatureList::IsEnabled(features::kGlobalResourceCoordinator);
30 } 75 }
31 76
(...skipping 18 matching lines...) Expand all
50 navigation_handle->GetRenderFrameHost(); 95 navigation_handle->GetRenderFrameHost();
51 96
52 auto* frame_resource_coordinator = 97 auto* frame_resource_coordinator =
53 render_frame_host->GetFrameResourceCoordinator(); 98 render_frame_host->GetFrameResourceCoordinator();
54 tab_resource_coordinator_->AddChild(*frame_resource_coordinator); 99 tab_resource_coordinator_->AddChild(*frame_resource_coordinator);
55 100
56 auto* process_resource_coordinator = 101 auto* process_resource_coordinator =
57 render_frame_host->GetProcess()->GetProcessResourceCoordinator(); 102 render_frame_host->GetProcess()->GetProcessResourceCoordinator();
58 process_resource_coordinator->AddChild(*frame_resource_coordinator); 103 process_resource_coordinator->AddChild(*frame_resource_coordinator);
59 } 104 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698