render_process_host_id.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. #ifndef COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_RENDER_PROCESS_HOST_ID_H_
  5. #define COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_RENDER_PROCESS_HOST_ID_H_
  6. #include "base/types/id_type.h"
  7. #include "content/public/common/child_process_host.h"
  8. namespace performance_manager {
  9. using RenderProcessHostIdBase =
  10. base::IdType<class RenderProcessHostIdTag,
  11. int32_t,
  12. content::ChildProcessHost::kInvalidUniqueID,
  13. 1>;
  14. // A strongly typed wrapper for the id returned by RenderProcessHost::GetID().
  15. //
  16. // This uses ChildProcessHost::kInvalidUniqueId (-1) as the default invalid id,
  17. // but also recognizes 0 as an invalid id because there is existing code that
  18. // uses 0 as an invalid value. It starts generating id's at 1.
  19. class RenderProcessHostId : public RenderProcessHostIdBase {
  20. public:
  21. using RenderProcessHostIdBase::RenderProcessHostIdBase;
  22. // 0 is also an invalid value.
  23. constexpr bool is_null() const {
  24. return RenderProcessHostIdBase::is_null() || this->value() == 0;
  25. }
  26. // Override operator bool() to call the overridden is_null().
  27. constexpr explicit operator bool() const { return !is_null(); }
  28. };
  29. } // namespace performance_manager
  30. #endif // COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_RENDER_PROCESS_HOST_ID_H_