| 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 class ExtensionFunction : public base::RefCountedThreadSafe<ExtensionFunction> { | 38 // |
| 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> { |
| 39 public: | 42 public: |
| 40 ExtensionFunction() : request_id_(-1), name_(""), has_callback_(false) {} | 43 ExtensionFunction() : request_id_(-1), name_(""), has_callback_(false) {} |
| 41 | 44 |
| 42 // Specifies the name of the function. | 45 // Specifies the name of the function. |
| 43 void set_name(const std::string& name) { name_ = name; } | 46 void set_name(const std::string& name) { name_ = name; } |
| 44 const std::string name() const { return name_; } | 47 const std::string name() const { return name_; } |
| 45 | 48 |
| 46 // Set the profile which contains the extension that has originated this | 49 // Set the profile which contains the extension that has originated this |
| 47 // function call. | 50 // function call. |
| 48 void set_profile(Profile* profile) { profile_ = profile; } | 51 void set_profile(Profile* profile) { profile_ = profile; } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 void set_include_incognito(bool include) { include_incognito_ = include; } | 91 void set_include_incognito(bool include) { include_incognito_ = include; } |
| 89 bool include_incognito() { return include_incognito_; } | 92 bool include_incognito() { return include_incognito_; } |
| 90 | 93 |
| 91 // Execute the API. Clients should call set_raw_args() and | 94 // Execute the API. Clients should call set_raw_args() and |
| 92 // set_request_id() before calling this method. Derived classes should be | 95 // set_request_id() before calling this method. Derived classes should be |
| 93 // ready to return raw_result() and error() before returning from this | 96 // ready to return raw_result() and error() before returning from this |
| 94 // function. | 97 // function. |
| 95 virtual void Run() = 0; | 98 virtual void Run() = 0; |
| 96 | 99 |
| 97 protected: | 100 protected: |
| 98 friend class base::RefCountedThreadSafe<ExtensionFunction>; | 101 friend class base::RefCounted<ExtensionFunction>; |
| 99 | 102 |
| 100 virtual ~ExtensionFunction() {} | 103 virtual ~ExtensionFunction() {} |
| 101 | 104 |
| 102 // Gets the extension that called this function. This can return NULL for | 105 // Gets the extension that called this function. This can return NULL for |
| 103 // async functions, for example if the extension is unloaded while the | 106 // async functions, for example if the extension is unloaded while the |
| 104 // function is running. | 107 // function is running. |
| 105 Extension* GetExtension(); | 108 Extension* GetExtension(); |
| 106 | 109 |
| 107 // Gets the "current" browser, if any. | 110 // Gets the "current" browser, if any. |
| 108 // | 111 // |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 } | 224 } |
| 222 | 225 |
| 223 protected: | 226 protected: |
| 224 virtual ~SyncExtensionFunction() {} | 227 virtual ~SyncExtensionFunction() {} |
| 225 | 228 |
| 226 private: | 229 private: |
| 227 DISALLOW_COPY_AND_ASSIGN(SyncExtensionFunction); | 230 DISALLOW_COPY_AND_ASSIGN(SyncExtensionFunction); |
| 228 }; | 231 }; |
| 229 | 232 |
| 230 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 233 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ |
| OLD | NEW |