Update V8 to version 4.6.62.
[chromium-blink-merge.git] / components / policy / core / browser / policy_error_map.h
blobcb9d2ed7bdd998c1969c1351d458786ed90a5945
1 // Copyright 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.
5 #ifndef COMPONENTS_POLICY_CORE_BROWSER_POLICY_ERROR_MAP_H_
6 #define COMPONENTS_POLICY_CORE_BROWSER_POLICY_ERROR_MAP_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_vector.h"
14 #include "base/strings/string16.h"
15 #include "components/policy/policy_export.h"
17 namespace policy {
19 // Collects error messages and their associated policies.
20 class POLICY_EXPORT PolicyErrorMap {
21 public:
22 typedef std::multimap<std::string, base::string16> PolicyMapType;
23 typedef PolicyMapType::const_iterator const_iterator;
25 class PendingError;
27 PolicyErrorMap();
28 virtual ~PolicyErrorMap();
30 // Returns true when the errors logged are ready to be retrieved. It is always
31 // safe to call AddError, but the other methods are only allowed once
32 // IsReady is true. IsReady will be true once the UI message loop has started.
33 bool IsReady() const;
35 // Adds an entry with key |policy| and the error message corresponding to
36 // |message_id| in grit/generated_resources.h to the map.
37 void AddError(const std::string& policy, int message_id);
39 // Adds an entry with key |policy|, subkey |subkey|, and the error message
40 // corresponding to |message_id| in grit/generated_resources.h to the map.
41 void AddError(const std::string& policy,
42 const std::string& subkey,
43 int message_id);
45 // Adds an entry with key |policy|, list index |index|, and the error message
46 // corresponding to |message_id| in grit/generated_resources.h to the map.
47 void AddError(const std::string& policy,
48 int index,
49 int message_id);
51 // Adds an entry with key |policy| and the error message corresponding to
52 // |message_id| in grit/generated_resources.h to the map and replaces the
53 // placeholder within the error message with |replacement_string|.
54 void AddError(const std::string& policy,
55 int message_id,
56 const std::string& replacement_string);
58 // Adds an entry with key |policy|, subkey |subkey| and the error message
59 // corresponding to |message_id| in grit/generated_resources.h to the map.
60 // Replaces the placeholder in the error message with |replacement_string|.
61 void AddError(const std::string& policy,
62 const std::string& subkey,
63 int message_id,
64 const std::string& replacement_string);
66 // Adds an entry with key |policy|, list index |index| and the error message
67 // corresponding to |message_id| in grit/generated_resources.h to the map.
68 // Replaces the placeholder in the error message with |replacement_string|.
69 void AddError(const std::string& policy,
70 int index,
71 int message_id,
72 const std::string& replacement_string);
74 // Adds an entry with key |policy|, the schema validation error location
75 // |error_path|, and detailed error |message|.
76 void AddError(const std::string& policy,
77 const std::string& error_path,
78 const std::string& message);
80 // Returns all the error messages stored for |policy|, separated by a white
81 // space. Returns an empty string if there are no errors for |policy|.
82 base::string16 GetErrors(const std::string& policy);
84 bool empty();
85 size_t size();
87 const_iterator begin();
88 const_iterator end();
90 void Clear();
92 private:
93 // Maps the error when ready, otherwise adds it to the pending errors list.
94 void AddError(PendingError* error);
96 // Converts a PendingError into a |map_| entry.
97 void Convert(PendingError* error);
99 // Converts all pending errors to |map_| entries.
100 void CheckReadyAndConvert();
102 ScopedVector<PendingError> pending_;
103 PolicyMapType map_;
105 DISALLOW_COPY_AND_ASSIGN(PolicyErrorMap);
108 } // namespace policy
110 #endif // COMPONENTS_POLICY_CORE_BROWSER_POLICY_ERROR_MAP_H_