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_
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"
19 // Collects error messages and their associated policies.
20 class POLICY_EXPORT PolicyErrorMap
{
22 typedef std::multimap
<std::string
, base::string16
> PolicyMapType
;
23 typedef PolicyMapType::const_iterator const_iterator
;
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.
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
,
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
,
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
,
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
,
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
,
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
);
87 const_iterator
begin();
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_
;
105 DISALLOW_COPY_AND_ASSIGN(PolicyErrorMap
);
108 } // namespace policy
110 #endif // COMPONENTS_POLICY_CORE_BROWSER_POLICY_ERROR_MAP_H_