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

Side by Side Diff: headless/public/util/error_reporter.h

Issue 2466923002: headless: Only report protocol parsing errors when DCHECK is enabled (Closed)
Patch Set: Add comment Created 4 years, 1 month 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 | « no previous file | headless/public/util/error_reporter.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 HEADLESS_PUBLIC_UTIL_ERROR_REPORTER_H_ 5 #ifndef HEADLESS_PUBLIC_UTIL_ERROR_REPORTER_H_
6 #define HEADLESS_PUBLIC_UTIL_ERROR_REPORTER_H_ 6 #define HEADLESS_PUBLIC_UTIL_ERROR_REPORTER_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 #include "headless/public/headless_export.h" 12 #include "headless/public/headless_export.h"
13 13
14 namespace headless { 14 namespace headless {
15 15
16 // Tracks errors which are encountered while parsing client API types. 16 // Tracks errors which are encountered while parsing client API types. Note that
17 // errors are only reported in debug builds (i.e., when DCHECK is enabled).
17 class HEADLESS_EXPORT ErrorReporter { 18 class HEADLESS_EXPORT ErrorReporter {
18 public: 19 public:
19 ErrorReporter(); 20 ErrorReporter();
20 ~ErrorReporter(); 21 ~ErrorReporter();
21 22
23 #if DCHECK_IS_ON()
22 // Enter a new nested parsing context. It will initially have a null name. 24 // Enter a new nested parsing context. It will initially have a null name.
23 void Push(); 25 void Push();
24 26
25 // Leave the current parsing context, returning to the previous one. 27 // Leave the current parsing context, returning to the previous one.
26 void Pop(); 28 void Pop();
27 29
28 // Set the name of the current parsing context. |name| must be a string with 30 // Set the name of the current parsing context. |name| must be a string with
29 // application lifetime. 31 // application lifetime.
30 void SetName(const char* name); 32 void SetName(const char* name);
31 33
32 // Report an error in the current parsing context. 34 // Report an error in the current parsing context.
33 void AddError(base::StringPiece description); 35 void AddError(base::StringPiece description);
34 36
35 // Returns true if any errors have been reported so far. 37 // Returns true if any errors have been reported so far.
36 bool HasErrors() const; 38 bool HasErrors() const;
37 39
38 // Returns a list of reported errors. 40 // Returns a list of reported errors.
39 const std::vector<std::string>& errors() const { return errors_; } 41 const std::vector<std::string>& errors() const { return errors_; }
42 #else // DCHECK_IS_ON()
43 inline void Push() {}
44 inline void Pop() {}
45 inline void SetName(const char* name) {}
46 inline void AddError(base::StringPiece description) {}
47 inline bool HasErrors() const { return false; }
48 #endif // DCHECK_IS_ON()
40 49
41 private: 50 private:
42 std::vector<const char*> path_; 51 std::vector<const char*> path_;
43 std::vector<std::string> errors_; 52 std::vector<std::string> errors_;
44 }; 53 };
45 54
46 } // namespace headless 55 } // namespace headless
47 56
48 #endif // HEADLESS_PUBLIC_UTIL_ERROR_REPORTER_H_ 57 #endif // HEADLESS_PUBLIC_UTIL_ERROR_REPORTER_H_
OLDNEW
« no previous file with comments | « no previous file | headless/public/util/error_reporter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698