Index: services/resource_coordinator/coordination_unit/coordination_unit_impl.h |
diff --git a/services/resource_coordinator/coordination_unit/coordination_unit_impl.h b/services/resource_coordinator/coordination_unit/coordination_unit_impl.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..00570e336943a6b1262fa97ad087e3e9096ac192 |
--- /dev/null |
+++ b/services/resource_coordinator/coordination_unit/coordination_unit_impl.h |
@@ -0,0 +1,71 @@ |
+// 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. |
+ |
+#ifndef SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_IMPL_H_ |
+#define SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_IMPL_H_ |
+ |
+#include <list> |
+ |
+#include "base/optional.h" |
+#include "mojo/public/cpp/bindings/binding_set.h" |
+#include "mojo/public/cpp/bindings/interface_request.h" |
+#include "mojo/public/cpp/bindings/strong_binding.h" |
+#include "services/resource_coordinator/public/cpp/coordination_unit_id.h" |
+#include "services/resource_coordinator/public/interfaces/coordination_unit.mojom.h" |
+#include "services/resource_coordinator/public/interfaces/coordination_unit_provider.mojom.h" |
+#include "services/service_manager/public/cpp/service_context_ref.h" |
+ |
+namespace resource_coordinator { |
+ |
+class CoordinationUnitImpl : public mojom::CoordinationUnit { |
+ public: |
+ CoordinationUnitImpl( |
+ const CoordinationUnitID& id, |
+ std::unique_ptr<service_manager::ServiceContextRef> service_ref); |
+ ~CoordinationUnitImpl() override; |
+ |
+ // Overridden from mojom::CoordinationUnit: |
+ void SendEvent(mojom::EventPtr event) override; |
+ void GetID(const GetIDCallback& callback) override; |
+ void Duplicate(mojom::CoordinationUnitRequest request) override; |
+ void AddChild(const CoordinationUnitID& child_id) override; |
+ void SetPolicyCallback(mojom::PolicyCallbackPtr callback) override; |
+ |
+ private: |
+ bool AddChild(CoordinationUnitImpl* child); |
+ void RemoveChild(CoordinationUnitImpl* child); |
+ void AddParent(CoordinationUnitImpl* parent); |
+ void RemoveParent(CoordinationUnitImpl* parent); |
+ bool HasParent(CoordinationUnitImpl* unit); |
+ bool HasChild(CoordinationUnitImpl* unit); |
+ |
+ void RecalcPolicy(); |
+ void UnregisterPolicyCallback(); |
+ |
+ enum StateFlags : uint8_t { |
+ TEST_STATE, |
+ TAB_VISIBLE, |
+ AUDIO_PLAYING, |
+ NUM_STATE_FLAGS |
+ }; |
+ bool SelfOrParentHasFlagSet(StateFlags state); |
+ |
+ std::unique_ptr<service_manager::ServiceContextRef> service_ref_; |
+ mojo::BindingSet<mojom::CoordinationUnit> bindings_; |
+ CoordinationUnitID id_; |
+ |
+ std::set<CoordinationUnitImpl*> children_; |
+ std::set<CoordinationUnitImpl*> parents_; |
+ |
+ mojom::PolicyCallbackPtr policy_callback_; |
+ mojom::PolicyPtr current_policy_; |
+ |
+ base::Optional<bool> state_flags_[NUM_STATE_FLAGS]; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CoordinationUnitImpl); |
+}; |
+ |
+} // namespace resource_coordinator |
+ |
+#endif // SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_COORDINATION_UNIT_IMPL_H_ |