cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / extensions / browser / extension_error.h
blobc5be1696e71ab1d9ba99bee385b31621cbe7b1da
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 EXTENSIONS_BROWSER_EXTENSION_ERROR_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_ERROR_H_
8 #include <string>
9 #include <vector>
11 #include "base/compiler_specific.h"
12 #include "base/logging.h"
13 #include "base/strings/string16.h"
15 namespace extensions {
17 class ExtensionError {
18 public:
19 enum Type {
20 MANIFEST_ERROR,
21 RUNTIME_ERROR
24 virtual ~ExtensionError();
26 virtual std::string PrintForTest() const;
28 // Return true if this error and |rhs| are considered equal, and should be
29 // grouped together.
30 bool IsEqual(const ExtensionError* rhs) const;
32 Type type() const { return type_; }
33 const std::string& extension_id() const { return extension_id_; }
34 bool from_incognito() const { return from_incognito_; }
35 logging::LogSeverity level() const { return level_; }
36 const base::string16& source() const { return source_; }
37 const base::string16& message() const { return message_; }
38 size_t occurrences() const { return occurrences_; }
39 void set_occurrences(size_t occurrences) { occurrences_ = occurrences; }
41 protected:
42 ExtensionError(Type type,
43 const std::string& extension_id,
44 bool from_incognito,
45 logging::LogSeverity level,
46 const base::string16& source,
47 const base::string16& message);
49 virtual bool IsEqualImpl(const ExtensionError* rhs) const = 0;
51 // Which type of error this is.
52 Type type_;
53 // The ID of the extension which caused the error.
54 std::string extension_id_;
55 // Whether or not the error was caused while incognito.
56 bool from_incognito_;
57 // The severity level of the error.
58 logging::LogSeverity level_;
59 // The source for the error; this can be a script, web page, or manifest file.
60 // This is stored as a string (rather than a url) since it can be a Chrome
61 // script file (e.g., event_bindings.js).
62 base::string16 source_;
63 // The error message itself.
64 base::string16 message_;
65 // The number of times this error has occurred.
66 size_t occurrences_;
68 DISALLOW_COPY_AND_ASSIGN(ExtensionError);
71 class ManifestError : public ExtensionError {
72 public:
73 ManifestError(const std::string& extension_id,
74 const base::string16& message);
75 virtual ~ManifestError();
77 virtual std::string PrintForTest() const OVERRIDE;
78 private:
79 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE;
81 DISALLOW_COPY_AND_ASSIGN(ManifestError);
84 class RuntimeError : public ExtensionError {
85 public:
86 struct StackFrame {
87 size_t line_number;
88 size_t column_number;
89 // This is stored as a string (rather than a url) since it can be a
90 // Chrome script file (e.g., event_bindings.js).
91 base::string16 url;
92 base::string16 function; // optional
94 // STL-Required constructor
95 StackFrame();
97 StackFrame(size_t frame_line,
98 size_t frame_column,
99 const base::string16& frame_url,
100 const base::string16& frame_function /* can be empty */);
102 ~StackFrame();
104 bool operator==(const StackFrame& rhs) const;
106 typedef std::vector<StackFrame> StackTrace;
108 RuntimeError(bool from_incognito,
109 const base::string16& source,
110 const base::string16& message,
111 logging::LogSeverity level,
112 const base::string16& details);
113 virtual ~RuntimeError();
115 virtual std::string PrintForTest() const OVERRIDE;
117 const base::string16& execution_context_url() const {
118 return execution_context_url_;
120 const StackTrace& stack_trace() const { return stack_trace_; }
121 private:
122 virtual bool IsEqualImpl(const ExtensionError* rhs) const OVERRIDE;
124 // Parse the JSON |details| passed to the error. This includes a stack trace
125 // and an execution context url.
126 void ParseDetails(const base::string16& details);
127 // Try to determine the ID of the extension. This may be obtained through the
128 // reported source, or through the execution context url.
129 void DetermineExtensionID();
131 base::string16 execution_context_url_;
132 StackTrace stack_trace_;
134 DISALLOW_COPY_AND_ASSIGN(RuntimeError);
137 } // namespace extensions
139 #endif // EXTENSIONS_BROWSER_EXTENSION_ERROR_H_