OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 CHROME_BROWSER_POLICY_POLICY_ERROR_MAP_H_ |
| 6 #define CHROME_BROWSER_POLICY_POLICY_ERROR_MAP_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <map> |
| 10 #include <string> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/string16.h" |
| 14 #include "base/values.h" |
| 15 #include "policy/configuration_policy_type.h" |
| 16 |
| 17 namespace policy { |
| 18 |
| 19 // Collects error messages and their associated policies. |
| 20 class PolicyErrorMap { |
| 21 public: |
| 22 typedef std::multimap<ConfigurationPolicyType, string16> PolicyMapType; |
| 23 typedef PolicyMapType::const_iterator const_iterator; |
| 24 |
| 25 PolicyErrorMap(); |
| 26 virtual ~PolicyErrorMap(); |
| 27 |
| 28 // Returns true when the errors logged are ready to be retrieved. It is always |
| 29 // safe to call AddError, but the other methods are only allowed once |
| 30 // IsReady is true. IsReady will be true once the UI message loop has started. |
| 31 bool IsReady() const; |
| 32 |
| 33 // Adds an entry with key |policy| and the error message corresponding to |
| 34 // |message_id| in grit/generated_resources.h to the map. |
| 35 void AddError(ConfigurationPolicyType policy, int message_id); |
| 36 |
| 37 // Adds an entry with key |policy| and the error message corresponding to |
| 38 // |message_id| in grit/generated_resources.h to the map and replaces the |
| 39 // placeholder within the error message with |replacement_string|. |
| 40 void AddError(ConfigurationPolicyType policy, |
| 41 int message_id, |
| 42 const std::string& replacement_string); |
| 43 |
| 44 // Returns a list of all the error messages stored for |policy|. Returns NULL |
| 45 // if there are no error messages for |policy. The caller acquires ownership |
| 46 // of the returned ListValue pointer. |
| 47 ListValue* GetErrors(ConfigurationPolicyType policy); |
| 48 |
| 49 bool empty(); |
| 50 size_t size(); |
| 51 |
| 52 const_iterator begin(); |
| 53 const_iterator end(); |
| 54 |
| 55 void Clear(); |
| 56 |
| 57 private: |
| 58 struct PendingError; |
| 59 |
| 60 // Maps the error when ready, otherwise adds it to the pending errors list. |
| 61 void AddError(const PendingError& error); |
| 62 |
| 63 // Converts a PendingError into a |map_| entry. |
| 64 void Convert(const PendingError& error); |
| 65 |
| 66 // Converts all pending errors to |map_| entries. |
| 67 void CheckReadyAndConvert(); |
| 68 |
| 69 std::vector<PendingError> pending_; |
| 70 PolicyMapType map_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(PolicyErrorMap); |
| 73 }; |
| 74 |
| 75 } // namespace policy |
| 76 |
| 77 #endif // CHROME_BROWSER_POLICY_POLICY_ERROR_MAP_H_ |
OLD | NEW |