Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Side by Side Diff: mojo/services/network/network_service_impl.cc

Issue 1229903003: Mandoline: Implement basic "process per site" support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include "mojo/services/network/network_service_impl.h" 5 #include "mojo/services/network/network_service_impl.h"
6 6
7 #include "mojo/application/public/cpp/application_connection.h" 7 #include "mojo/application/public/cpp/application_connection.h"
8 #include "mojo/services/network/cookie_store_impl.h" 8 #include "mojo/services/network/cookie_store_impl.h"
9 #include "mojo/services/network/http_server_impl.h" 9 #include "mojo/services/network/http_server_impl.h"
10 #include "mojo/services/network/net_adapters.h" 10 #include "mojo/services/network/net_adapters.h"
11 #include "mojo/services/network/tcp_bound_socket_impl.h" 11 #include "mojo/services/network/tcp_bound_socket_impl.h"
12 #include "mojo/services/network/udp_socket_impl.h" 12 #include "mojo/services/network/udp_socket_impl.h"
13 #include "mojo/services/network/url_loader_impl.h" 13 #include "mojo/services/network/url_loader_impl.h"
14 #include "mojo/services/network/web_socket_impl.h" 14 #include "mojo/services/network/web_socket_impl.h"
15 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
15 16
16 namespace mojo { 17 namespace mojo {
17 18
18 NetworkServiceImpl::NetworkServiceImpl( 19 NetworkServiceImpl::NetworkServiceImpl(
19 ApplicationConnection* connection, 20 ApplicationConnection* connection,
20 NetworkContext* context, 21 NetworkContext* context,
21 scoped_ptr<mojo::AppRefCount> app_refcount, 22 scoped_ptr<mojo::AppRefCount> app_refcount,
22 InterfaceRequest<NetworkService> request) 23 InterfaceRequest<NetworkService> request)
23 : context_(context), 24 : context_(context),
24 app_refcount_(app_refcount.Pass()), 25 app_refcount_(app_refcount.Pass()),
25 origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()), 26 origin_(GURL(connection->GetRemoteApplicationURL()).GetOrigin()),
26 binding_(this, request.Pass()) { 27 binding_(this, request.Pass()) {
27 } 28 }
28 29
29 NetworkServiceImpl::~NetworkServiceImpl() { 30 NetworkServiceImpl::~NetworkServiceImpl() {
30 } 31 }
31 32
32 void NetworkServiceImpl::GetCookieStore(InterfaceRequest<CookieStore> store) { 33 void NetworkServiceImpl::GetCookieStore(InterfaceRequest<CookieStore> store) {
33 new CookieStoreImpl(context_, origin_, app_refcount_->Clone(), store.Pass()); 34 new CookieStoreImpl(context_, origin_, app_refcount_->Clone(), store.Pass());
34 } 35 }
35 36
37 void NetworkServiceImpl::GetSiteForURL(const String& url,
38 const GetSiteForURLCallback& callback) {
39 GURL gurl(url);
40 // If the url has a host, then determine the site.
41 if (gurl.has_host()) {
42 // Only keep the scheme and registered domain as given by GetOrigin. This
43 // may also include a port, which we need to drop.
44 GURL site = gurl.GetOrigin();
45
46 // Remove port, if any.
47 if (site.has_port()) {
48 GURL::Replacements rep;
49 rep.ClearPort();
50 site = site.ReplaceComponents(rep);
51 }
52
53 // If this URL has a registered domain, we only want to remember that part.
54 std::string domain =
55 net::registry_controlled_domains::GetDomainAndRegistry(
56 url,
57 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
58 if (!domain.empty()) {
59 GURL::Replacements rep;
60 rep.SetHostStr(domain);
61 site = site.ReplaceComponents(rep);
62 }
63 callback.Run(String::From(site.spec()));
64 return;
65 }
66
67 // If there is no host but there is a scheme, return the scheme.
68 // This is useful for cases like file URLs.
69 if (gurl.has_scheme()) {
70 callback.Run(String::From(GURL(gurl.scheme() + ":").spec()));
71 return;
72 }
73
74 // Otherwise the URL should be invalid; return an empty site.
75 DCHECK(!gurl.is_valid());
76 callback.Run(String());
77 }
78
36 void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) { 79 void NetworkServiceImpl::CreateWebSocket(InterfaceRequest<WebSocket> socket) {
37 new WebSocketImpl(context_, app_refcount_->Clone(), socket.Pass()); 80 new WebSocketImpl(context_, app_refcount_->Clone(), socket.Pass());
38 } 81 }
39 82
40 void NetworkServiceImpl::CreateTCPBoundSocket( 83 void NetworkServiceImpl::CreateTCPBoundSocket(
41 NetAddressPtr local_address, 84 NetAddressPtr local_address,
42 InterfaceRequest<TCPBoundSocket> bound_socket, 85 InterfaceRequest<TCPBoundSocket> bound_socket,
43 const CreateTCPBoundSocketCallback& callback) { 86 const CreateTCPBoundSocketCallback& callback) {
44 scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl( 87 scoped_ptr<TCPBoundSocketImpl> bound(new TCPBoundSocketImpl(
45 app_refcount_->Clone(), bound_socket.Pass())); 88 app_refcount_->Clone(), bound_socket.Pass()));
(...skipping 26 matching lines...) Expand all
72 115
73 void NetworkServiceImpl::CreateHttpServer( 116 void NetworkServiceImpl::CreateHttpServer(
74 NetAddressPtr local_address, 117 NetAddressPtr local_address,
75 HttpServerDelegatePtr delegate, 118 HttpServerDelegatePtr delegate,
76 const CreateHttpServerCallback& callback) { 119 const CreateHttpServerCallback& callback) {
77 HttpServerImpl::Create(local_address.Pass(), delegate.Pass(), 120 HttpServerImpl::Create(local_address.Pass(), delegate.Pass(),
78 app_refcount_->Clone(), callback); 121 app_refcount_->Clone(), callback);
79 } 122 }
80 123
81 } // namespace mojo 124 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698