| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_ |
| 6 #define EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_ | 6 #define EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 const std::string& extension_id) = 0; | 55 const std::string& extension_id) = 0; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // Implementation of SocketResourceManagerInterface using an | 58 // Implementation of SocketResourceManagerInterface using an |
| 59 // ApiResourceManager<T> instance (where T derives from Socket). | 59 // ApiResourceManager<T> instance (where T derives from Socket). |
| 60 template <typename T> | 60 template <typename T> |
| 61 class SocketResourceManager : public SocketResourceManagerInterface { | 61 class SocketResourceManager : public SocketResourceManagerInterface { |
| 62 public: | 62 public: |
| 63 SocketResourceManager() : manager_(NULL) {} | 63 SocketResourceManager() : manager_(NULL) {} |
| 64 | 64 |
| 65 virtual bool SetBrowserContext(content::BrowserContext* context) override { | 65 bool SetBrowserContext(content::BrowserContext* context) override { |
| 66 manager_ = ApiResourceManager<T>::Get(context); | 66 manager_ = ApiResourceManager<T>::Get(context); |
| 67 DCHECK(manager_) | 67 DCHECK(manager_) |
| 68 << "There is no socket manager. " | 68 << "There is no socket manager. " |
| 69 "If this assertion is failing during a test, then it is likely that " | 69 "If this assertion is failing during a test, then it is likely that " |
| 70 "TestExtensionSystem is failing to provide an instance of " | 70 "TestExtensionSystem is failing to provide an instance of " |
| 71 "ApiResourceManager<Socket>."; | 71 "ApiResourceManager<Socket>."; |
| 72 return manager_ != NULL; | 72 return manager_ != NULL; |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual int Add(Socket* socket) override { | 75 int Add(Socket* socket) override { |
| 76 // Note: Cast needed here, because "T" may be a subclass of "Socket". | 76 // Note: Cast needed here, because "T" may be a subclass of "Socket". |
| 77 return manager_->Add(static_cast<T*>(socket)); | 77 return manager_->Add(static_cast<T*>(socket)); |
| 78 } | 78 } |
| 79 | 79 |
| 80 virtual Socket* Get(const std::string& extension_id, | 80 Socket* Get(const std::string& extension_id, int api_resource_id) override { |
| 81 int api_resource_id) override { | |
| 82 return manager_->Get(extension_id, api_resource_id); | 81 return manager_->Get(extension_id, api_resource_id); |
| 83 } | 82 } |
| 84 | 83 |
| 85 virtual void Replace(const std::string& extension_id, | 84 void Replace(const std::string& extension_id, |
| 86 int api_resource_id, | 85 int api_resource_id, |
| 87 Socket* socket) override { | 86 Socket* socket) override { |
| 88 manager_->Replace(extension_id, api_resource_id, static_cast<T*>(socket)); | 87 manager_->Replace(extension_id, api_resource_id, static_cast<T*>(socket)); |
| 89 } | 88 } |
| 90 | 89 |
| 91 virtual void Remove(const std::string& extension_id, | 90 void Remove(const std::string& extension_id, int api_resource_id) override { |
| 92 int api_resource_id) override { | |
| 93 manager_->Remove(extension_id, api_resource_id); | 91 manager_->Remove(extension_id, api_resource_id); |
| 94 } | 92 } |
| 95 | 93 |
| 96 virtual base::hash_set<int>* GetResourceIds(const std::string& extension_id) | 94 base::hash_set<int>* GetResourceIds( |
| 97 override { | 95 const std::string& extension_id) override { |
| 98 return manager_->GetResourceIds(extension_id); | 96 return manager_->GetResourceIds(extension_id); |
| 99 } | 97 } |
| 100 | 98 |
| 101 private: | 99 private: |
| 102 ApiResourceManager<T>* manager_; | 100 ApiResourceManager<T>* manager_; |
| 103 }; | 101 }; |
| 104 | 102 |
| 105 class SocketAsyncApiFunction : public AsyncApiFunction { | 103 class SocketAsyncApiFunction : public AsyncApiFunction { |
| 106 public: | 104 public: |
| 107 SocketAsyncApiFunction(); | 105 SocketAsyncApiFunction(); |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 | 548 |
| 551 scoped_ptr<core_api::socket::Secure::Params> params_; | 549 scoped_ptr<core_api::socket::Secure::Params> params_; |
| 552 scoped_refptr<net::URLRequestContextGetter> url_request_getter_; | 550 scoped_refptr<net::URLRequestContextGetter> url_request_getter_; |
| 553 | 551 |
| 554 DISALLOW_COPY_AND_ASSIGN(SocketSecureFunction); | 552 DISALLOW_COPY_AND_ASSIGN(SocketSecureFunction); |
| 555 }; | 553 }; |
| 556 | 554 |
| 557 } // namespace extensions | 555 } // namespace extensions |
| 558 | 556 |
| 559 #endif // EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_ | 557 #endif // EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_ |
| OLD | NEW |