| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_API_API_FUNCTION_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_ASYNC_API_FUCTION_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_ | 6 #define EXTENSIONS_BROWSER_API_ASYNC_API_FUCTION_H_ |
| 7 | 7 |
| 8 #include "chrome/browser/extensions/chrome_extension_function.h" | |
| 9 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "extensions/browser/extension_function.h" |
| 10 | 10 |
| 11 namespace extensions { | 11 namespace extensions { |
| 12 | 12 |
| 13 // Base class for API functions. TODO(miket): there isn't much here anymore | |
| 14 // since the removal of ApiResourceEventRouter. Should we promote all its | |
| 15 // subclasses to UIThreadExtensionFunctions? | |
| 16 class ApiFunction : public ChromeAsyncExtensionFunction { | |
| 17 protected: | |
| 18 ApiFunction(); | |
| 19 virtual ~ApiFunction(); | |
| 20 }; | |
| 21 | |
| 22 // AsyncApiFunction provides convenient thread management for APIs that need to | 13 // AsyncApiFunction provides convenient thread management for APIs that need to |
| 23 // do essentially all their work on a thread other than the UI thread. | 14 // do essentially all their work on a thread other than the UI thread. |
| 24 class AsyncApiFunction : public ApiFunction { | 15 class AsyncApiFunction : public UIThreadExtensionFunction { |
| 25 protected: | 16 protected: |
| 26 AsyncApiFunction(); | 17 AsyncApiFunction(); |
| 27 virtual ~AsyncApiFunction(); | 18 virtual ~AsyncApiFunction(); |
| 28 | 19 |
| 29 // Like Prepare(). A useful place to put common work in an ApiFunction | 20 // Like Prepare(). A useful place to put common work in an ApiFunction |
| 30 // superclass that multiple API functions want to share. | 21 // superclass that multiple API functions want to share. |
| 31 virtual bool PrePrepare(); | 22 virtual bool PrePrepare(); |
| 32 | 23 |
| 33 // Set up for work (e.g., validate arguments). Guaranteed to happen on UI | 24 // Set up for work (e.g., validate arguments). Guaranteed to happen on UI |
| 34 // thread. | 25 // thread. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 59 void WorkOnWorkThread(); | 50 void WorkOnWorkThread(); |
| 60 void RespondOnUIThread(); | 51 void RespondOnUIThread(); |
| 61 | 52 |
| 62 // If you don't want your Work() method to happen on the IO thread, then set | 53 // If you don't want your Work() method to happen on the IO thread, then set |
| 63 // this to the thread that you do want, preferably in Prepare(). | 54 // this to the thread that you do want, preferably in Prepare(). |
| 64 content::BrowserThread::ID work_thread_id_; | 55 content::BrowserThread::ID work_thread_id_; |
| 65 }; | 56 }; |
| 66 | 57 |
| 67 } // namespace extensions | 58 } // namespace extensions |
| 68 | 59 |
| 69 #endif // CHROME_BROWSER_EXTENSIONS_API_API_FUNCTION_H_ | 60 #endif // EXTENSIONS_BROWSER_API_ASYNC_API_FUCTION_H_ |
| OLD | NEW |