| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include <list> | 9 #include <list> |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 error_ = error; \ | 28 error_ = error; \ |
| 29 bad_message_ = true; \ | 29 bad_message_ = true; \ |
| 30 return false; \ | 30 return false; \ |
| 31 } while (0) | 31 } while (0) |
| 32 | 32 |
| 33 #define DECLARE_EXTENSION_FUNCTION_NAME(name) \ | 33 #define DECLARE_EXTENSION_FUNCTION_NAME(name) \ |
| 34 public: static const char* function_name() { return name; } | 34 public: static const char* function_name() { return name; } |
| 35 | 35 |
| 36 // Abstract base class for extension functions the ExtensionFunctionDispatcher | 36 // Abstract base class for extension functions the ExtensionFunctionDispatcher |
| 37 // knows how to dispatch to. | 37 // knows how to dispatch to. |
| 38 // | 38 class ExtensionFunction : public base::RefCountedThreadSafe<ExtensionFunction> { |
| 39 // TODO(aa): This will have to become reference counted when we introduce | |
| 40 // APIs that live beyond a single stack frame. | |
| 41 class ExtensionFunction : public base::RefCounted<ExtensionFunction> { | |
| 42 public: | 39 public: |
| 43 ExtensionFunction() : request_id_(-1), name_(""), has_callback_(false) {} | 40 ExtensionFunction() : request_id_(-1), name_(""), has_callback_(false) {} |
| 44 | 41 |
| 45 // Specifies the name of the function. | 42 // Specifies the name of the function. |
| 46 void set_name(const std::string& name) { name_ = name; } | 43 void set_name(const std::string& name) { name_ = name; } |
| 47 const std::string name() const { return name_; } | 44 const std::string name() const { return name_; } |
| 48 | 45 |
| 49 // Set the profile which contains the extension that has originated this | 46 // Set the profile which contains the extension that has originated this |
| 50 // function call. | 47 // function call. |
| 51 void set_profile(Profile* profile) { profile_ = profile; } | 48 void set_profile(Profile* profile) { profile_ = profile; } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 void set_include_incognito(bool include) { include_incognito_ = include; } | 88 void set_include_incognito(bool include) { include_incognito_ = include; } |
| 92 bool include_incognito() { return include_incognito_; } | 89 bool include_incognito() { return include_incognito_; } |
| 93 | 90 |
| 94 // Execute the API. Clients should call set_raw_args() and | 91 // Execute the API. Clients should call set_raw_args() and |
| 95 // set_request_id() before calling this method. Derived classes should be | 92 // set_request_id() before calling this method. Derived classes should be |
| 96 // ready to return raw_result() and error() before returning from this | 93 // ready to return raw_result() and error() before returning from this |
| 97 // function. | 94 // function. |
| 98 virtual void Run() = 0; | 95 virtual void Run() = 0; |
| 99 | 96 |
| 100 protected: | 97 protected: |
| 101 friend class base::RefCounted<ExtensionFunction>; | 98 friend class base::RefCountedThreadSafe<ExtensionFunction>; |
| 102 | 99 |
| 103 virtual ~ExtensionFunction() {} | 100 virtual ~ExtensionFunction() {} |
| 104 | 101 |
| 105 // Gets the extension that called this function. This can return NULL for | 102 // Gets the extension that called this function. This can return NULL for |
| 106 // async functions, for example if the extension is unloaded while the | 103 // async functions, for example if the extension is unloaded while the |
| 107 // function is running. | 104 // function is running. |
| 108 Extension* GetExtension(); | 105 Extension* GetExtension(); |
| 109 | 106 |
| 110 // Gets the "current" browser, if any. | 107 // Gets the "current" browser, if any. |
| 111 // | 108 // |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 221 } |
| 225 | 222 |
| 226 protected: | 223 protected: |
| 227 virtual ~SyncExtensionFunction() {} | 224 virtual ~SyncExtensionFunction() {} |
| 228 | 225 |
| 229 private: | 226 private: |
| 230 DISALLOW_COPY_AND_ASSIGN(SyncExtensionFunction); | 227 DISALLOW_COPY_AND_ASSIGN(SyncExtensionFunction); |
| 231 }; | 228 }; |
| 232 | 229 |
| 233 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 230 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| OLD | NEW |