| 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 18 matching lines...) Expand all  Loading... | 
| 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), name_(""), 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   void set_name(const std::string& name) { name_ = name; } | 36   void set_name(const std::string& name) { name_ = name; } | 
| 37   const std::string name() { return name_; } | 37   const std::string name() { return name_; } | 
| 38 | 38 | 
| 39   // Specifies the raw arguments to the function, as a JSON-encoded string. | 39   // Specifies the raw arguments to the function, as a JSON value. | 
| 40   virtual void SetArgs(const std::string& args) = 0; | 40   virtual void SetArgs(const Value* args) = 0; | 
| 41 | 41 | 
| 42   // 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 | 
| 43   // be empty). | 43   // be empty). | 
| 44   virtual const std::string GetResult() = 0; | 44   virtual const std::string GetResult() = 0; | 
| 45 | 45 | 
| 46   // Retrieves any error string from the function. | 46   // Retrieves any error string from the function. | 
| 47   virtual const std::string GetError() = 0; | 47   virtual const std::string GetError() = 0; | 
| 48 | 48 | 
| 49   void set_dispatcher_peer(ExtensionFunctionDispatcher::Peer* peer) { | 49   void set_dispatcher_peer(ExtensionFunctionDispatcher::Peer* peer) { | 
| 50     peer_ = peer; | 50     peer_ = peer; | 
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 96 // the browser's UI thread*. | 96 // the browser's UI thread*. | 
| 97 // Note that once Run() returns, dispatcher() can be NULL, so be sure to | 97 // Note that once Run() returns, dispatcher() can be NULL, so be sure to | 
| 98 // NULL-check. | 98 // NULL-check. | 
| 99 // TODO(aa) Remove this extra level of inheritance once the browser stops | 99 // TODO(aa) Remove this extra level of inheritance once the browser stops | 
| 100 // parsing JSON (and instead uses custom serialization of Value objects). | 100 // parsing JSON (and instead uses custom serialization of Value objects). | 
| 101 class AsyncExtensionFunction : public ExtensionFunction { | 101 class AsyncExtensionFunction : public ExtensionFunction { | 
| 102  public: | 102  public: | 
| 103   AsyncExtensionFunction() : args_(NULL), bad_message_(false) {} | 103   AsyncExtensionFunction() : args_(NULL), bad_message_(false) {} | 
| 104   virtual ~AsyncExtensionFunction() {} | 104   virtual ~AsyncExtensionFunction() {} | 
| 105 | 105 | 
| 106   virtual void SetArgs(const std::string& args); | 106   virtual void SetArgs(const Value* args); | 
| 107   virtual const std::string GetResult(); | 107   virtual const std::string GetResult(); | 
| 108   virtual const std::string GetError() { return error_; } | 108   virtual const std::string GetError() { return error_; } | 
| 109   virtual void Run() { | 109   virtual void Run() { | 
| 110     if (!RunImpl()) | 110     if (!RunImpl()) | 
| 111       SendResponse(false); | 111       SendResponse(false); | 
| 112   } | 112   } | 
| 113 | 113 | 
| 114   // Derived classes should implement this method to do their work and return | 114   // Derived classes should implement this method to do their work and return | 
| 115   // success/failure. | 115   // success/failure. | 
| 116   virtual bool RunImpl() = 0; | 116   virtual bool RunImpl() = 0; | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 159 | 159 | 
| 160   virtual void Run() { | 160   virtual void Run() { | 
| 161     SendResponse(RunImpl()); | 161     SendResponse(RunImpl()); | 
| 162   } | 162   } | 
| 163 | 163 | 
| 164  private: | 164  private: | 
| 165   DISALLOW_COPY_AND_ASSIGN(SyncExtensionFunction); | 165   DISALLOW_COPY_AND_ASSIGN(SyncExtensionFunction); | 
| 166 }; | 166 }; | 
| 167 | 167 | 
| 168 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 168 #endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_FUNCTION_H_ | 
| OLD | NEW | 
|---|