Chromium Code Reviews| Index: chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc |
| diff --git a/chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc b/chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc |
| index 62d5c11edb6d276be915cdf0ed390c7b5add2efa..66a3045122c8846f9c7571893abc5851840d6b63 100644 |
| --- a/chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc |
| +++ b/chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.cc |
| @@ -4,21 +4,66 @@ |
| #include "chrome/browser/resource_coordinator/resource_coordinator_web_contents_observer.h" |
| +#include <utility> |
| + |
| +#include "components/ukm/public/interfaces/ukm_interface.mojom.h" |
| #include "content/public/browser/navigation_handle.h" |
| #include "content/public/browser/render_frame_host.h" |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/common/service_manager_connection.h" |
| +#include "content/public/common/service_names.mojom.h" |
| +#include "content/public/renderer/render_thread.h" |
| #include "services/resource_coordinator/public/cpp/resource_coordinator_features.h" |
| +#include "services/resource_coordinator/public/interfaces/service_callbacks.mojom.h" |
| +#include "services/resource_coordinator/public/interfaces/service_constants.mojom.h" |
| +#include "services/service_manager/public/cpp/connector.h" |
| DEFINE_WEB_CONTENTS_USER_DATA_KEY(ResourceCoordinatorWebContentsObserver); |
| ResourceCoordinatorWebContentsObserver::ResourceCoordinatorWebContentsObserver( |
| content::WebContents* web_contents) |
| : WebContentsObserver(web_contents) { |
| + service_manager::Connector* connector = |
| + content::ServiceManagerConnection::GetForProcess()->GetConnector(); |
| + |
| tab_resource_coordinator_ = |
| base::MakeUnique<resource_coordinator::ResourceCoordinatorInterface>( |
| - content::ServiceManagerConnection::GetForProcess()->GetConnector(), |
| - resource_coordinator::CoordinationUnitType::kWebContents); |
| + connector, resource_coordinator::CoordinationUnitType::kWebContents); |
| + |
| + connector->BindInterface(resource_coordinator::mojom::kServiceName, |
| + mojo::MakeRequest(&service_callbacks_)); |
| + |
| + EnsureUkmRecorderInterface(); |
| +} |
| + |
| +// TODO(matthalp) integrate into ResourceCoordinatorService once the UKM mojo |
| +// interface can be accessed directly within GRC. GRC cannot currently use |
| +// the UKM mojo inteface directly because of software layering issues |
| +// (i.e. the UKM mojo interface is only reachable from the content_browser |
| +// service which cannot be accesses by services in the services/ directory). |
| +// Instead the ResourceCoordinatorWebContentsObserver is used as it lives |
| +// within the content_browser service and can initialize the |
| +// UkmRecorderInterface and pass that interface into GRC through |
| +// resource_coordinator::mojom::ServiceCallbacks. |
| +void ResourceCoordinatorWebContentsObserver::EnsureUkmRecorderInterface() { |
| + service_callbacks_->IsUkmRecorderInterfaceInitialized(base::Bind( |
| + &ResourceCoordinatorWebContentsObserver::MaybeSetUkmRecorderInterface, |
| + base::Unretained(this))); |
| +} |
| + |
| +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.
|
| + bool ukm_recorder_already_initialized) { |
| + if (ukm_recorder_already_initialized) { |
| + return; |
| + } |
| + |
| + ukm::mojom::UkmRecorderInterfacePtr ukm_recorder_interface; |
| + content::ServiceManagerConnection::GetForProcess() |
| + ->GetConnector() |
| + ->BindInterface(content::mojom::kBrowserServiceName, |
| + mojo::MakeRequest(&ukm_recorder_interface)); |
| + service_callbacks_->SetUkmRecorderInterface( |
| + std::move(ukm_recorder_interface)); |
| } |
| ResourceCoordinatorWebContentsObserver:: |