binders.cc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright 2020 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. #include "components/performance_manager/embedder/binders.h"
  5. #include "components/performance_manager/graph/process_node_impl.h"
  6. #include "components/performance_manager/performance_manager_impl.h"
  7. #include "components/performance_manager/performance_manager_tab_helper.h"
  8. #include "components/performance_manager/render_process_user_data.h"
  9. #include "content/public/browser/render_process_host.h"
  10. #include "content/public/browser/web_contents.h"
  11. namespace performance_manager {
  12. void BindProcessCoordinationUnit(
  13. int render_process_host_id,
  14. mojo::PendingReceiver<performance_manager::mojom::ProcessCoordinationUnit>
  15. receiver) {
  16. content::RenderProcessHost* render_process_host =
  17. content::RenderProcessHost::FromID(render_process_host_id);
  18. if (!render_process_host)
  19. return;
  20. performance_manager::RenderProcessUserData* user_data =
  21. performance_manager::RenderProcessUserData::GetForRenderProcessHost(
  22. render_process_host);
  23. DCHECK(performance_manager::PerformanceManagerImpl::IsAvailable());
  24. performance_manager::PerformanceManagerImpl::CallOnGraphImpl(
  25. FROM_HERE, base::BindOnce(&performance_manager::ProcessNodeImpl::Bind,
  26. base::Unretained(user_data->process_node()),
  27. std::move(receiver)));
  28. }
  29. void BindDocumentCoordinationUnit(
  30. content::RenderFrameHost* host,
  31. mojo::PendingReceiver<performance_manager::mojom::DocumentCoordinationUnit>
  32. receiver) {
  33. auto* content = content::WebContents::FromRenderFrameHost(host);
  34. // |content| can be null if RenderFrameHost's delegate is not a WebContents.
  35. if (!content)
  36. return;
  37. auto* helper =
  38. performance_manager::PerformanceManagerTabHelper::FromWebContents(
  39. content);
  40. // This condition is for testing-only. We should handle a bind request after
  41. // PerformanceManagerTabHelper is attached to WebContents.
  42. if (!helper)
  43. return;
  44. return helper->BindDocumentCoordinationUnit(host, std::move(receiver));
  45. }
  46. } // namespace performance_manager