Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: components/policy/core/browser/policy_error_map.h

Issue 144363008: Add support for schema validate error to PolicyErrorMap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@expand-policy-schema-3.5
Patch Set: fix indention Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/ios/grit_whitelist.txt ('k') | components/policy/core/browser/policy_error_map.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_POLICY_CORE_BROWSER_POLICY_ERROR_MAP_H_ 5 #ifndef COMPONENTS_POLICY_CORE_BROWSER_POLICY_ERROR_MAP_H_
6 #define COMPONENTS_POLICY_CORE_BROWSER_POLICY_ERROR_MAP_H_ 6 #define COMPONENTS_POLICY_CORE_BROWSER_POLICY_ERROR_MAP_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/memory/scoped_vector.h"
13 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
14 #include "components/policy/policy_export.h" 15 #include "components/policy/policy_export.h"
15 16
16 namespace policy { 17 namespace policy {
17 18
18 // Collects error messages and their associated policies. 19 // Collects error messages and their associated policies.
19 class POLICY_EXPORT PolicyErrorMap { 20 class POLICY_EXPORT PolicyErrorMap {
20 public: 21 public:
21 typedef std::multimap<std::string, base::string16> PolicyMapType; 22 typedef std::multimap<std::string, base::string16> PolicyMapType;
22 typedef PolicyMapType::const_iterator const_iterator; 23 typedef PolicyMapType::const_iterator const_iterator;
23 24
25 class PendingError;
26
24 PolicyErrorMap(); 27 PolicyErrorMap();
25 virtual ~PolicyErrorMap(); 28 virtual ~PolicyErrorMap();
26 29
27 // Returns true when the errors logged are ready to be retrieved. It is always 30 // Returns true when the errors logged are ready to be retrieved. It is always
28 // safe to call AddError, but the other methods are only allowed once 31 // safe to call AddError, but the other methods are only allowed once
29 // IsReady is true. IsReady will be true once the UI message loop has started. 32 // IsReady is true. IsReady will be true once the UI message loop has started.
30 bool IsReady() const; 33 bool IsReady() const;
31 34
32 // Adds an entry with key |policy| and the error message corresponding to 35 // Adds an entry with key |policy| and the error message corresponding to
33 // |message_id| in grit/generated_resources.h to the map. 36 // |message_id| in grit/generated_resources.h to the map.
(...skipping 27 matching lines...) Expand all
61 const std::string& replacement_string); 64 const std::string& replacement_string);
62 65
63 // Adds an entry with key |policy|, list index |index| and the error message 66 // Adds an entry with key |policy|, list index |index| and the error message
64 // corresponding to |message_id| in grit/generated_resources.h to the map. 67 // corresponding to |message_id| in grit/generated_resources.h to the map.
65 // Replaces the placeholder in the error message with |replacement_string|. 68 // Replaces the placeholder in the error message with |replacement_string|.
66 void AddError(const std::string& policy, 69 void AddError(const std::string& policy,
67 int index, 70 int index,
68 int message_id, 71 int message_id,
69 const std::string& replacement_string); 72 const std::string& replacement_string);
70 73
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);
79
71 // Returns all the error messages stored for |policy|, separated by a white 80 // Returns all the error messages stored for |policy|, separated by a white
72 // space. Returns an empty string if there are no errors for |policy|. 81 // space. Returns an empty string if there are no errors for |policy|.
73 base::string16 GetErrors(const std::string& policy); 82 base::string16 GetErrors(const std::string& policy);
74 83
75 bool empty(); 84 bool empty();
76 size_t size(); 85 size_t size();
77 86
78 const_iterator begin(); 87 const_iterator begin();
79 const_iterator end(); 88 const_iterator end();
80 89
81 void Clear(); 90 void Clear();
82 91
83 private: 92 private:
84 struct PendingError;
85
86 // Maps the error when ready, otherwise adds it to the pending errors list. 93 // Maps the error when ready, otherwise adds it to the pending errors list.
87 void AddError(const PendingError& error); 94 void AddError(PendingError* error);
88 95
89 // Converts a PendingError into a |map_| entry. 96 // Converts a PendingError into a |map_| entry.
90 void Convert(const PendingError& error); 97 void Convert(PendingError* error);
91 98
92 // Converts all pending errors to |map_| entries. 99 // Converts all pending errors to |map_| entries.
93 void CheckReadyAndConvert(); 100 void CheckReadyAndConvert();
94 101
95 std::vector<PendingError> pending_; 102 ScopedVector<PendingError> pending_;
96 PolicyMapType map_; 103 PolicyMapType map_;
97 104
98 DISALLOW_COPY_AND_ASSIGN(PolicyErrorMap); 105 DISALLOW_COPY_AND_ASSIGN(PolicyErrorMap);
99 }; 106 };
100 107
101 } // namespace policy 108 } // namespace policy
102 109
103 #endif // COMPONENTS_POLICY_CORE_BROWSER_POLICY_ERROR_MAP_H_ 110 #endif // COMPONENTS_POLICY_CORE_BROWSER_POLICY_ERROR_MAP_H_
OLDNEW
« no previous file with comments | « build/ios/grit_whitelist.txt ('k') | components/policy/core/browser/policy_error_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698