1 // Copyright (c) 2013 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 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_POLICY_LOAD_STATUS_H_ 6 #define COMPONENTS_POLICY_CORE_COMMON_POLICY_LOAD_STATUS_H_ 7 8 #include <bitset> 9 10 #include "base/macros.h" 11 #include "components/policy/policy_export.h" 12 13 namespace policy { 14 15 // UMA histogram enum for policy load status. Don't change existing constants, 16 // append additional constants to the end if needed. 17 enum PolicyLoadStatus { 18 // Policy load attempt started. This gets logged for each policy load attempt 19 // to get a baseline on the number of requests, and an arbitrary number of 20 // the below status codes may get added in addition. 21 POLICY_LOAD_STATUS_STARTED = 0, 22 // System failed to determine whether there's policy. 23 POLICY_LOAD_STATUS_QUERY_FAILED = 1, 24 // No policy present. 25 POLICY_LOAD_STATUS_NO_POLICY = 2, 26 // Data inaccessible, such as non-local policy file. 27 POLICY_LOAD_STATUS_INACCCESSIBLE = 3, 28 // Data missing, such as policy file not present. 29 POLICY_LOAD_STATUS_MISSING = 4, 30 // Trying with Wow64 redirection disabled. 31 POLICY_LOAD_STATUS_WOW64_REDIRECTION_DISABLED = 5, 32 // Data read error, for example file reading errors. 33 POLICY_LOAD_STATUS_READ_ERROR = 6, 34 // Data too large to process. 35 POLICY_LOAD_STATUS_TOO_BIG = 7, 36 // Parse error. 37 POLICY_LOAD_STATUS_PARSE_ERROR = 8, 38 39 // This must stay last. 40 POLICY_LOAD_STATUS_SIZE 41 }; 42 43 // A helper for collecting statuses for a policy load operation. 44 class POLICY_EXPORT PolicyLoadStatusSampler { 45 public: 46 using StatusSet = std::bitset<POLICY_LOAD_STATUS_SIZE>; 47 48 PolicyLoadStatusSampler(); 49 virtual ~PolicyLoadStatusSampler(); 50 51 // Adds a status code. 52 void Add(PolicyLoadStatus status); 53 54 // Returns a set with all statuses. GetStatusSet()55 const StatusSet& GetStatusSet() const { return status_bits_; } 56 57 private: 58 StatusSet status_bits_; 59 DISALLOW_COPY_AND_ASSIGN(PolicyLoadStatusSampler); 60 }; 61 62 // A helper for generating policy load status UMA statistics. On destruction, 63 // records histogram samples for the collected status codes. 64 class POLICY_EXPORT PolicyLoadStatusUmaReporter 65 : public PolicyLoadStatusSampler { 66 public: 67 PolicyLoadStatusUmaReporter(); 68 ~PolicyLoadStatusUmaReporter() override; 69 70 private: 71 DISALLOW_COPY_AND_ASSIGN(PolicyLoadStatusUmaReporter); 72 }; 73 74 } // namespace policy 75 76 #endif // COMPONENTS_POLICY_CORE_COMMON_POLICY_LOAD_STATUS_H_ 77