summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrockot@chromium.org <rockot@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-04 21:30:33 +0000
committerrockot@chromium.org <rockot@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-04 21:30:33 +0000
commitf8ef26567f19ec8335076f724030f2b0d4f2f841 (patch)
tree2b01ca2af39e90cf59efb6844412d6d302911278
parent80a6b9c307cf79152f14a5dc301c6d9c164c0254 (diff)
downloadchromium_src-f8ef26567f19ec8335076f724030f2b0d4f2f841.zip
chromium_src-f8ef26567f19ec8335076f724030f2b0d4f2f841.tar.gz
chromium_src-f8ef26567f19ec8335076f724030f2b0d4f2f841.tar.bz2
Remove Chrome dependencies from sockets API implementations.
This is part of an effort to start separating APIs from src/chrome and eventually move them into src/extensions. BUG=347574 TBR=yoz@chromium.org for DEPS Review URL: https://codereview.chromium.org/185303012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254823 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--apps/shell/common/DEPS1
-rw-r--r--apps/shell/common/shell_extensions_client.cc8
-rw-r--r--chrome/browser/extensions/api/socket/socket_api.cc20
-rw-r--r--chrome/browser/extensions/api/socket/socket_api.h12
-rw-r--r--chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.cc32
-rw-r--r--chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h10
-rw-r--r--chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.cc35
-rw-r--r--chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.h10
-rw-r--r--chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.cc33
-rw-r--r--chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.h10
10 files changed, 91 insertions, 80 deletions
diff --git a/apps/shell/common/DEPS b/apps/shell/common/DEPS
index cf709d6..c5e4e60 100644
--- a/apps/shell/common/DEPS
+++ b/apps/shell/common/DEPS
@@ -1,6 +1,7 @@
include_rules = [
# TODO(jamescook): Remove these. http://crbug.com/305404
# Chrome pieces for app_shell bring-up.
+ "+chrome/common/extensions/api/sockets/sockets_manifest_handler.h",
"+chrome/common/extensions/features/base_feature_provider.h",
"+chrome/common/extensions/permissions/chrome_api_permissions.h",
diff --git a/apps/shell/common/shell_extensions_client.cc b/apps/shell/common/shell_extensions_client.cc
index 2b2619e..99a68fb 100644
--- a/apps/shell/common/shell_extensions_client.cc
+++ b/apps/shell/common/shell_extensions_client.cc
@@ -5,6 +5,7 @@
#include "apps/shell/common/shell_extensions_client.h"
#include "base/logging.h"
+#include "chrome/common/extensions/api/sockets/sockets_manifest_handler.h"
#include "chrome/common/extensions/features/base_feature_provider.h"
#include "chrome/common/extensions/permissions/chrome_api_permissions.h"
#include "extensions/common/common_manifest_handlers.h"
@@ -76,8 +77,13 @@ ShellExtensionsClient::~ShellExtensionsClient() {
void ShellExtensionsClient::Initialize() {
extensions::RegisterCommonManifestHandlers();
- extensions::ManifestHandler::FinalizeRegistration();
+ // TODO(rockot): API manifest handlers which move out to src/extensions
+ // should either end up in RegisterCommonManifestHandlers or some new
+ // initialization step specifically for API manifest handlers.
+ (new extensions::SocketsManifestHandler)->Register();
+
+ extensions::ManifestHandler::FinalizeRegistration();
// TODO(jamescook): Do we need to whitelist any extensions?
}
diff --git a/chrome/browser/extensions/api/socket/socket_api.cc b/chrome/browser/extensions/api/socket/socket_api.cc
index 1453cf9..d7555b7 100644
--- a/chrome/browser/extensions/api/socket/socket_api.cc
+++ b/chrome/browser/extensions/api/socket/socket_api.cc
@@ -8,13 +8,13 @@
#include "base/bind.h"
#include "base/containers/hash_tables.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/dns/host_resolver_wrapper.h"
#include "chrome/browser/extensions/api/socket/socket.h"
#include "chrome/browser/extensions/api/socket/tcp_socket.h"
#include "chrome/browser/extensions/api/socket/udp_socket.h"
-#include "chrome/browser/io_thread.h"
#include "chrome/common/extensions/permissions/socket_permission.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/resource_context.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/permissions/permissions_data.h"
@@ -85,19 +85,25 @@ void SocketAsyncApiFunction::RemoveSocket(int api_resource_id) {
}
SocketExtensionWithDnsLookupFunction::SocketExtensionWithDnsLookupFunction()
- : io_thread_(g_browser_process->io_thread()),
+ : resource_context_(NULL),
request_handle_(new net::HostResolver::RequestHandle),
- addresses_(new net::AddressList) {
-}
+ addresses_(new net::AddressList) {}
SocketExtensionWithDnsLookupFunction::~SocketExtensionWithDnsLookupFunction() {
}
+bool SocketExtensionWithDnsLookupFunction::PrePrepare() {
+ if (!SocketAsyncApiFunction::PrePrepare())
+ return false;
+ resource_context_ = browser_context()->GetResourceContext();
+ return resource_context_ != NULL;
+}
+
void SocketExtensionWithDnsLookupFunction::StartDnsLookup(
const std::string& hostname) {
net::HostResolver* host_resolver =
- HostResolverWrapper::GetInstance()->GetHostResolver(
- io_thread_->globals()->host_resolver.get());
+ extensions::HostResolverWrapper::GetInstance()->GetHostResolver(
+ resource_context_->GetHostResolver());
DCHECK(host_resolver);
// Yes, we are passing zero as the port. There are some interesting but not
diff --git a/chrome/browser/extensions/api/socket/socket_api.h b/chrome/browser/extensions/api/socket/socket_api.h
index dc2856e..950eb94 100644
--- a/chrome/browser/extensions/api/socket/socket_api.h
+++ b/chrome/browser/extensions/api/socket/socket_api.h
@@ -17,10 +17,9 @@
#include <string>
-class IOThread;
-
namespace content {
class BrowserContext;
+class ResourceContext;
}
namespace net {
@@ -119,6 +118,9 @@ class SocketExtensionWithDnsLookupFunction : public SocketAsyncApiFunction {
SocketExtensionWithDnsLookupFunction();
virtual ~SocketExtensionWithDnsLookupFunction();
+ // AsyncApiFunction:
+ virtual bool PrePrepare() OVERRIDE;
+
void StartDnsLookup(const std::string& hostname);
virtual void AfterDnsLookup(int lookup_result) = 0;
@@ -127,10 +129,8 @@ class SocketExtensionWithDnsLookupFunction : public SocketAsyncApiFunction {
private:
void OnDnsLookup(int resolve_result);
- // This instance is widely available through BrowserProcess, but we need to
- // acquire it on the UI thread and then use it on the IO thread, so we keep a
- // plain pointer to it here as we move from thread to thread.
- IOThread* io_thread_;
+ // Weak pointer to the resource context.
+ content::ResourceContext* resource_context_;
scoped_ptr<net::HostResolver::RequestHandle> request_handle_;
scoped_ptr<net::AddressList> addresses_;
diff --git a/chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.cc b/chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.cc
index 07a6c19..41361bb 100644
--- a/chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.cc
+++ b/chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.cc
@@ -4,12 +4,10 @@
#include "chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/socket/tcp_socket.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_manager.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_system.h"
+#include "extensions/browser/extensions_browser_client.h"
#include "net/base/net_errors.h"
namespace {
@@ -41,10 +39,9 @@ TCPSocketEventDispatcher* TCPSocketEventDispatcher::Get(
TCPSocketEventDispatcher::TCPSocketEventDispatcher(
content::BrowserContext* context)
- : thread_id_(Socket::kThreadId),
- profile_(Profile::FromBrowserContext(context)) {
+ : thread_id_(Socket::kThreadId), browser_context_(context) {
ApiResourceManager<ResumableTCPSocket>* manager =
- ApiResourceManager<ResumableTCPSocket>::Get(profile_);
+ ApiResourceManager<ResumableTCPSocket>::Get(browser_context_);
DCHECK(manager) << "There is no socket manager. "
"If this assertion is failing during a test, then it is likely that "
"TestExtensionSystem is failing to provide an instance of "
@@ -78,7 +75,7 @@ void TCPSocketEventDispatcher::StartSocketRead(const std::string& extension_id,
ReadParams params;
params.thread_id = thread_id_;
- params.profile_id = profile_;
+ params.browser_context_id = browser_context_;
params.extension_id = extension_id;
params.sockets = sockets_;
params.socket_id = socket_id;
@@ -172,25 +169,26 @@ void TCPSocketEventDispatcher::PostEvent(const ReadParams& params,
scoped_ptr<Event> event) {
DCHECK(BrowserThread::CurrentlyOn(params.thread_id));
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&DispatchEvent,
- params.profile_id,
- params.extension_id,
- base::Passed(event.Pass())));
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&DispatchEvent,
+ params.browser_context_id,
+ params.extension_id,
+ base::Passed(event.Pass())));
}
// static
-void TCPSocketEventDispatcher::DispatchEvent(void* profile_id,
+void TCPSocketEventDispatcher::DispatchEvent(void* browser_context_id,
const std::string& extension_id,
scoped_ptr<Event> event) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- Profile* profile = reinterpret_cast<Profile*>(profile_id);
- if (!g_browser_process->profile_manager()->IsValidProfile(profile))
+ content::BrowserContext* context =
+ reinterpret_cast<content::BrowserContext*>(browser_context_id);
+ if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context))
return;
- EventRouter* router = ExtensionSystem::Get(profile)->event_router();
+ EventRouter* router = ExtensionSystem::Get(context)->event_router();
if (router)
router->DispatchEventToExtension(extension_id, event.Pass());
}
diff --git a/chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h b/chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h
index 742e2cf..12f3fb6 100644
--- a/chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h
+++ b/chrome/browser/extensions/api/sockets_tcp/tcp_socket_event_dispatcher.h
@@ -8,7 +8,9 @@
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.h"
-class Profile;
+namespace content {
+class BrowserContext;
+}
namespace extensions {
struct Event;
@@ -56,7 +58,7 @@ class TCPSocketEventDispatcher
~ReadParams();
content::BrowserThread::ID thread_id;
- void* profile_id;
+ void* browser_context_id;
std::string extension_id;
scoped_refptr<SocketData> sockets;
int socket_id;
@@ -77,13 +79,13 @@ class TCPSocketEventDispatcher
static void PostEvent(const ReadParams& params, scoped_ptr<Event> event);
// Dispatch an extension event on to EventRouter instance on UI thread.
- static void DispatchEvent(void* profile_id,
+ static void DispatchEvent(void* browser_context_id,
const std::string& extension_id,
scoped_ptr<Event> event);
// Usually IO thread (except for unit testing).
content::BrowserThread::ID thread_id_;
- Profile* const profile_;
+ content::BrowserContext* const browser_context_;
scoped_refptr<SocketData> sockets_;
};
diff --git a/chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.cc b/chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.cc
index e2bbcb8..0140403 100644
--- a/chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.cc
+++ b/chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.cc
@@ -4,12 +4,10 @@
#include "chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/socket/tcp_socket.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_manager.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_system.h"
+#include "extensions/browser/extensions_browser_client.h"
#include "net/base/net_errors.h"
namespace extensions {
@@ -38,10 +36,9 @@ TCPServerSocketEventDispatcher* TCPServerSocketEventDispatcher::Get(
TCPServerSocketEventDispatcher::TCPServerSocketEventDispatcher(
content::BrowserContext* context)
- : thread_id_(Socket::kThreadId),
- profile_(Profile::FromBrowserContext(context)) {
+ : thread_id_(Socket::kThreadId), browser_context_(context) {
ApiResourceManager<ResumableTCPServerSocket>* server_manager =
- ApiResourceManager<ResumableTCPServerSocket>::Get(profile_);
+ ApiResourceManager<ResumableTCPServerSocket>::Get(browser_context_);
DCHECK(server_manager) << "There is no server socket manager. "
"If this assertion is failing during a test, then it is likely that "
"TestExtensionSystem is failing to provide an instance of "
@@ -49,7 +46,7 @@ TCPServerSocketEventDispatcher::TCPServerSocketEventDispatcher(
server_sockets_ = server_manager->data_;
ApiResourceManager<ResumableTCPSocket>* client_manager =
- ApiResourceManager<ResumableTCPSocket>::Get(profile_);
+ ApiResourceManager<ResumableTCPSocket>::Get(browser_context_);
DCHECK(client_manager) << "There is no client socket manager. "
"If this assertion is failing during a test, then it is likely that "
"TestExtensionSystem is failing to provide an instance of "
@@ -86,7 +83,7 @@ void TCPServerSocketEventDispatcher::StartSocketAccept(
AcceptParams params;
params.thread_id = thread_id_;
- params.profile_id = profile_;
+ params.browser_context_id = browser_context_;
params.extension_id = extension_id;
params.server_sockets = server_sockets_;
params.client_sockets = client_sockets_;
@@ -171,26 +168,26 @@ void TCPServerSocketEventDispatcher::PostEvent(const AcceptParams& params,
scoped_ptr<Event> event) {
DCHECK(BrowserThread::CurrentlyOn(params.thread_id));
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&DispatchEvent,
- params.profile_id,
- params.extension_id,
- base::Passed(event.Pass())));
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&DispatchEvent,
+ params.browser_context_id,
+ params.extension_id,
+ base::Passed(event.Pass())));
}
// static
void TCPServerSocketEventDispatcher::DispatchEvent(
- void* profile_id,
+ void* browser_context_id,
const std::string& extension_id,
scoped_ptr<Event> event) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- Profile* profile = reinterpret_cast<Profile*>(profile_id);
- if (!g_browser_process->profile_manager()->IsValidProfile(profile))
+ content::BrowserContext* context =
+ reinterpret_cast<content::BrowserContext*>(browser_context_id);
+ if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context))
return;
-
- EventRouter* router = ExtensionSystem::Get(profile)->event_router();
+ EventRouter* router = ExtensionSystem::Get(context)->event_router();
if (router)
router->DispatchEventToExtension(extension_id, event.Pass());
}
diff --git a/chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.h b/chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.h
index 9094bce..ba4d63d 100644
--- a/chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.h
+++ b/chrome/browser/extensions/api/sockets_tcp_server/tcp_server_socket_event_dispatcher.h
@@ -9,7 +9,9 @@
#include "chrome/browser/extensions/api/sockets_tcp/sockets_tcp_api.h"
#include "chrome/browser/extensions/api/sockets_tcp_server/sockets_tcp_server_api.h"
-class Profile;
+namespace content {
+class BrowserContext;
+}
namespace extensions {
struct Event;
@@ -61,7 +63,7 @@ class TCPServerSocketEventDispatcher
~AcceptParams();
content::BrowserThread::ID thread_id;
- void* profile_id;
+ void* browser_context_id;
std::string extension_id;
scoped_refptr<ServerSocketData> server_sockets;
scoped_refptr<ClientSocketData> client_sockets;
@@ -84,13 +86,13 @@ class TCPServerSocketEventDispatcher
scoped_ptr<Event> event);
// Dispatch an extension event on to EventRouter instance on UI thread.
- static void DispatchEvent(void* profile_id,
+ static void DispatchEvent(void* browser_context_id,
const std::string& extension_id,
scoped_ptr<Event> event);
// Usually IO thread (except for unit testing).
content::BrowserThread::ID thread_id_;
- Profile* const profile_;
+ content::BrowserContext* const browser_context_;
scoped_refptr<ServerSocketData> server_sockets_;
scoped_refptr<ClientSocketData> client_sockets_;
};
diff --git a/chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.cc b/chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.cc
index 1f1f5bc..1ff0591 100644
--- a/chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.cc
+++ b/chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.cc
@@ -4,12 +4,10 @@
#include "chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.h"
-#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/socket/udp_socket.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/profiles/profile_manager.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_system.h"
+#include "extensions/browser/extensions_browser_client.h"
#include "net/base/net_errors.h"
namespace extensions {
@@ -37,10 +35,9 @@ UDPSocketEventDispatcher* UDPSocketEventDispatcher::Get(
UDPSocketEventDispatcher::UDPSocketEventDispatcher(
content::BrowserContext* context)
- : thread_id_(Socket::kThreadId),
- profile_(Profile::FromBrowserContext(context)) {
+ : thread_id_(Socket::kThreadId), browser_context_(context) {
ApiResourceManager<ResumableUDPSocket>* manager =
- ApiResourceManager<ResumableUDPSocket>::Get(profile_);
+ ApiResourceManager<ResumableUDPSocket>::Get(browser_context_);
DCHECK(manager) << "There is no socket manager. "
"If this assertion is failing during a test, then it is likely that "
"TestExtensionSystem is failing to provide an instance of "
@@ -65,7 +62,7 @@ void UDPSocketEventDispatcher::OnSocketResume(const std::string& extension_id,
ReceiveParams params;
params.thread_id = thread_id_;
- params.profile_id = profile_;
+ params.browser_context_id = browser_context_;
params.extension_id = extension_id;
params.sockets = sockets_;
params.socket_id = socket_id;
@@ -157,25 +154,25 @@ void UDPSocketEventDispatcher::PostEvent(const ReceiveParams& params,
scoped_ptr<Event> event) {
DCHECK(BrowserThread::CurrentlyOn(params.thread_id));
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&DispatchEvent,
- params.profile_id,
- params.extension_id,
- base::Passed(event.Pass())));
+ BrowserThread::PostTask(BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&DispatchEvent,
+ params.browser_context_id,
+ params.extension_id,
+ base::Passed(event.Pass())));
}
/*static*/
-void UDPSocketEventDispatcher::DispatchEvent(void* profile_id,
+void UDPSocketEventDispatcher::DispatchEvent(void* browser_context_id,
const std::string& extension_id,
scoped_ptr<Event> event) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- Profile* profile = reinterpret_cast<Profile*>(profile_id);
- if (!g_browser_process->profile_manager()->IsValidProfile(profile))
+ content::BrowserContext* context =
+ reinterpret_cast<content::BrowserContext*>(browser_context_id);
+ if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context))
return;
-
- EventRouter* router = ExtensionSystem::Get(profile)->event_router();
+ EventRouter* router = ExtensionSystem::Get(context)->event_router();
if (router)
router->DispatchEventToExtension(extension_id, event.Pass());
}
diff --git a/chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.h b/chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.h
index c16f327..463ecef 100644
--- a/chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.h
+++ b/chrome/browser/extensions/api/sockets_udp/udp_socket_event_dispatcher.h
@@ -8,7 +8,9 @@
#include "chrome/browser/extensions/api/api_resource_manager.h"
#include "chrome/browser/extensions/api/sockets_udp/sockets_udp_api.h"
-class Profile;
+namespace content {
+class BrowserContext;
+}
namespace extensions {
struct Event;
@@ -56,7 +58,7 @@ class UDPSocketEventDispatcher
~ReceiveParams();
content::BrowserThread::ID thread_id;
- void* profile_id;
+ void* browser_context_id;
std::string extension_id;
scoped_refptr<SocketData> sockets;
int socket_id;
@@ -76,13 +78,13 @@ class UDPSocketEventDispatcher
static void PostEvent(const ReceiveParams& params, scoped_ptr<Event> event);
// Dispatch an extension event on to EventRouter instance on UI thread.
- static void DispatchEvent(void* profile_id,
+ static void DispatchEvent(void* browser_context_id,
const std::string& extension_id,
scoped_ptr<Event> event);
// Usually IO thread (except for unit testing).
content::BrowserThread::ID thread_id_;
- Profile* const profile_;
+ content::BrowserContext* const browser_context_;
scoped_refptr<SocketData> sockets_;
};