| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // TODO(aa) Remove this extra level of inheritance once the browser stops | 86 // TODO(aa) Remove this extra level of inheritance once the browser stops |
| 87 // parsing JSON (and instead uses custom serialization of Value objects). | 87 // parsing JSON (and instead uses custom serialization of Value objects). |
| 88 class AsyncExtensionFunction : public ExtensionFunction { | 88 class AsyncExtensionFunction : public ExtensionFunction { |
| 89 public: | 89 public: |
| 90 AsyncExtensionFunction() : args_(NULL), bad_message_(false) {} | 90 AsyncExtensionFunction() : args_(NULL), bad_message_(false) {} |
| 91 virtual ~AsyncExtensionFunction() {} | 91 virtual ~AsyncExtensionFunction() {} |
| 92 | 92 |
| 93 virtual void SetArgs(const std::string& args); | 93 virtual void SetArgs(const std::string& args); |
| 94 virtual const std::string GetResult(); | 94 virtual const std::string GetResult(); |
| 95 virtual const std::string GetError() { return error_; } | 95 virtual const std::string GetError() { return error_; } |
| 96 virtual void Run() = 0; | 96 virtual void Run() { |
| 97 if (!RunImpl()) |
| 98 SendResponse(false); |
| 99 } |
| 100 |
| 101 // Derived classes should implement this method to do their work and return |
| 102 // success/failure. |
| 103 virtual bool RunImpl() = 0; |
| 97 | 104 |
| 98 protected: | 105 protected: |
| 99 void SendResponse(bool success); | 106 void SendResponse(bool success); |
| 100 | 107 |
| 101 // Note: After Run() returns, dispatcher() can be NULL. Since these getters | 108 // Note: After Run() returns, dispatcher() can be NULL. Since these getters |
| 102 // rely on dispatcher(), make sure it is valid before using them. | 109 // rely on dispatcher(), make sure it is valid before using them. |
| 103 std::string extension_id(); | 110 std::string extension_id(); |
| 104 Profile* profile(); | 111 Profile* profile(); |
| 105 | 112 |
| 106 // The arguments to the API. Only non-null if argument were specified. | 113 // The arguments to the API. Only non-null if argument were specified. |
| 107 Value* args_; | 114 Value* args_; |
| 108 | 115 |
| 109 // The result of the API. This should be populated by the derived class before | 116 // The result of the API. This should be populated by the derived class before |
| 110 // Run() returns. | 117 // SendResponse() is called. |
| 111 scoped_ptr<Value> result_; | 118 scoped_ptr<Value> result_; |
| 112 | 119 |
| 113 // Any detailed error from the API. This should be populated by the derived | 120 // Any detailed error from the API. This should be populated by the derived |
| 114 // class before Run() returns. | 121 // class before Run() returns. |
| 115 std::string error_; | 122 std::string error_; |
| 116 | 123 |
| 117 // Any class that gets a malformed message should set this to true before | 124 // Any class that gets a malformed message should set this to true before |
| 118 // returning. The calling renderer process will be killed. | 125 // returning. The calling renderer process will be killed. |
| 119 bool bad_message_; | 126 bool bad_message_; |
| 120 | 127 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 139 | 146 |
| 140 virtual void Run() { | 147 virtual void Run() { |
| 141 SendResponse(RunImpl()); | 148 SendResponse(RunImpl()); |
| 142 } | 149 } |
| 143 | 150 |
| 144 private: | 151 private: |
| 145 DISALLOW_COPY_AND_ASSIGN(SyncExtensionFunction); | 152 DISALLOW_COPY_AND_ASSIGN(SyncExtensionFunction); |
| 146 }; | 153 }; |
| 147 | 154 |
| 148 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 155 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| OLD | NEW |