Index: services/resource_coordinator/coordination_unit.h |
diff --git a/services/resource_coordinator/coordination_unit.h b/services/resource_coordinator/coordination_unit.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..26e0dd16ca443334aa4dc39e81d418e028b088c4 |
--- /dev/null |
+++ b/services/resource_coordinator/coordination_unit.h |
@@ -0,0 +1,60 @@ |
+// 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_H_ |
+#define SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_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/interfaces/coordination_unit.mojom.h" |
+#include "services/resource_coordinator/public/interfaces/coordination_unit_provider.mojom.h" |
+#include "services/service_manager/public/cpp/connection.h" |
+ |
+namespace resource_coordinator { |
+ |
+class CoordinationUnit : public mojom::CoordinationUnit { |
+ public: |
+ CoordinationUnit(mojom::CoordinationUnitIDPtr options); |
+ ~CoordinationUnit() 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(mojom::CoordinationUnitIDPtr child_id) override; |
+ void SetPolicyCallback(mojom::PolicyCallbackPtr callback) override; |
+ |
+ private: |
+ bool AddChild(CoordinationUnit* child); |
+ void RemoveChild(CoordinationUnit* child); |
+ void AddParent(CoordinationUnit* parent); |
+ void RemoveParent(CoordinationUnit* parent); |
+ void RecalcPolicy(); |
+ void UnregisterPolicyCallback(); |
+ |
+ enum StateFlags : uint8_t { TAB_VISIBLE, AUDIO_PLAYING, NUM_STATE_FLAGS }; |
+ bool SelfOrParentHasFlagSet(StateFlags state); |
+ |
+ mojo::BindingSet<mojom::CoordinationUnit> bindings_; |
+ mojom::IDType type_; |
+ std::string id_; |
+ int64_t id_hash_; |
+ std::set<CoordinationUnit*> children_; |
+ std::set<CoordinationUnit*> parents_; |
+ |
+ mojom::PolicyCallbackPtr policy_callback_; |
+ mojom::PolicyPtr current_policy_; |
+ |
+ base::Optional<bool> state_flags_[NUM_STATE_FLAGS]; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(CoordinationUnit); |
+}; |
+ |
+} // namespace resource_coordinator |
+ |
+#endif // SERVICES_RESOURCE_COORDINATOR_COORDINATION_UNIT_H_ |