// Copyright 2018 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_RESOURCE_COORDINATOR_DECISION_DETAILS_H_ #define CHROME_BROWSER_RESOURCE_COORDINATOR_DECISION_DETAILS_H_ #include <string> #include <vector> namespace ukm { namespace builders { class TabManager_LifecycleStateChange; } } // namespace ukm namespace resource_coordinator { // An enumeration of reasons why a particular intervention or lifecycle state // changes can be denied. This is a superset of all failure reasons that can // apply for any particular intervention. New reasons can freely be added to // this enum as necessary, but UKM plumbing and string conversion needs to be // maintained as well. enum class DecisionFailureReason : int32_t { … }; // An enumeration of reasons why a particular intervention or lifecycle state // change can be approved. The fact that no "live state" failures are blocking // the intervention is implicit, and doesn't need to be explicitly encoded. enum class DecisionSuccessReason : int32_t { … }; // Helper function for converting a reason to a string representation. const char* ToString(DecisionFailureReason failure_reason); const char* ToString(DecisionSuccessReason success_reason); // Describes the detailed reasons why a particular intervention decision was // made. This is populated by the various policy bits of policy logic that // decide whether a particular intervention or lifecycle state transition can be // performed. It can populate various related UKM builders and also be converted // to a collection of user readable strings for the purposes of displaying in // in web UI. // // A decision can contain multiple reasons for success or failure, and policy // allows some success reasons to override some failure reasons and vice versa. // The first reason posted to this object determines whether or not the overall // outcome is positive or negative. It is assumed that reasons are posted in // order of decreasing priority. // // For logging and inspection it is useful to know of all possible failure // reasons blocking a success. Similarly, it is interesting to know of all of // the possible success reasons blocking a failure. To this end, policy logic // should continue populating the decision with details until is has "toggled". // That is, a success reason has followed a chain of failures or vice versa. // The "toggling" of the decision chain is indicated by the return value from // AddReason. This allows writing code like the following: // // bool DecideIfCanDoSomething(DecisionDetails* details) { // if (some_condition_is_false) { // if (details->AddReason(kSomeFailureReason)) // return details->IsPositive(); // } // if (some_other_condition) { // if (details->AddReason(kSomeOtherFailureReason)) // return details->IsPositive(); // } // ... // } class DecisionDetails { … }; } // namespace resource_coordinator #endif // CHROME_BROWSER_RESOURCE_COORDINATOR_DECISION_DETAILS_H_