| 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 11 matching lines...) Expand all Loading... |
| 22 } \ | 22 } \ |
| 23 } while (0) | 23 } while (0) |
| 24 | 24 |
| 25 // Abstract base class for extension functions the ExtensionFunctionDispatcher | 25 // Abstract base class for extension functions the ExtensionFunctionDispatcher |
| 26 // knows how to dispatch to. | 26 // knows how to dispatch to. |
| 27 // | 27 // |
| 28 // TODO(aa): This will have to become reference counted when we introduce | 28 // TODO(aa): This will have to become reference counted when we introduce |
| 29 // APIs that live beyond a single stack frame. | 29 // APIs that live beyond a single stack frame. |
| 30 class ExtensionFunction : public base::RefCounted<ExtensionFunction> { | 30 class ExtensionFunction : public base::RefCounted<ExtensionFunction> { |
| 31 public: | 31 public: |
| 32 ExtensionFunction() : request_id_(-1), has_callback_(false) {} | 32 ExtensionFunction() : request_id_(-1), name_(""), has_callback_(false) {} |
| 33 virtual ~ExtensionFunction() {} | 33 virtual ~ExtensionFunction() {} |
| 34 | 34 |
| 35 // Specifies the name of the function. | 35 // Specifies the name of the function. |
| 36 virtual void SetName(const std::string& name) { } | 36 void set_name(const std::string& name) { name_ = name; } |
| 37 const std::string name() { return name_; } |
| 37 | 38 |
| 38 // Specifies the raw arguments to the function, as a JSON-encoded string. | 39 // Specifies the raw arguments to the function, as a JSON-encoded string. |
| 39 virtual void SetArgs(const std::string& args) = 0; | 40 virtual void SetArgs(const std::string& args) = 0; |
| 40 | 41 |
| 41 // Retrieves the results of the function as a JSON-encoded string (may | 42 // Retrieves the results of the function as a JSON-encoded string (may |
| 42 // be empty). | 43 // be empty). |
| 43 virtual const std::string GetResult() = 0; | 44 virtual const std::string GetResult() = 0; |
| 44 | 45 |
| 45 // Retrieves any error string from the function. | 46 // Retrieves any error string from the function. |
| 46 virtual const std::string GetError() = 0; | 47 virtual const std::string GetError() = 0; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 64 // function. | 65 // function. |
| 65 virtual void Run() = 0; | 66 virtual void Run() = 0; |
| 66 | 67 |
| 67 protected: | 68 protected: |
| 68 // The peer to the dispatcher that will service this extension function call. | 69 // The peer to the dispatcher that will service this extension function call. |
| 69 scoped_refptr<ExtensionFunctionDispatcher::Peer> peer_; | 70 scoped_refptr<ExtensionFunctionDispatcher::Peer> peer_; |
| 70 | 71 |
| 71 // Id of this request, used to map the response back to the caller. | 72 // Id of this request, used to map the response back to the caller. |
| 72 int request_id_; | 73 int request_id_; |
| 73 | 74 |
| 75 // The name of this function. |
| 76 std::string name_; |
| 77 |
| 74 // True if the js caller provides a callback function to receive the response | 78 // True if the js caller provides a callback function to receive the response |
| 75 // of this call. | 79 // of this call. |
| 76 bool has_callback_; | 80 bool has_callback_; |
| 77 | 81 |
| 78 private: | 82 private: |
| 79 DISALLOW_COPY_AND_ASSIGN(ExtensionFunction); | 83 DISALLOW_COPY_AND_ASSIGN(ExtensionFunction); |
| 80 }; | 84 }; |
| 81 | 85 |
| 82 // Base class for an extension function that runs asynchronously *relative to | 86 // Base class for an extension function that runs asynchronously *relative to |
| 83 // the browser's UI thread*. | 87 // the browser's UI thread*. |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 150 |
| 147 virtual void Run() { | 151 virtual void Run() { |
| 148 SendResponse(RunImpl()); | 152 SendResponse(RunImpl()); |
| 149 } | 153 } |
| 150 | 154 |
| 151 private: | 155 private: |
| 152 DISALLOW_COPY_AND_ASSIGN(SyncExtensionFunction); | 156 DISALLOW_COPY_AND_ASSIGN(SyncExtensionFunction); |
| 153 }; | 157 }; |
| 154 | 158 |
| 155 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 159 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| OLD | NEW |