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

Side by Side Diff: mojo/application/public/cpp/lib/application_impl.cc

Issue 1455833005: Convert ConnectToApplication to take a params class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 1 month 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
« no previous file with comments | « mojo/application/public/cpp/application_impl.h ('k') | mojo/mojo_base.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/application/public/cpp/application_impl.h" 5 #include "mojo/application/public/cpp/application_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "mojo/application/public/cpp/application_delegate.h" 11 #include "mojo/application/public/cpp/application_delegate.h"
12 #include "mojo/application/public/cpp/lib/service_registry.h" 12 #include "mojo/application/public/cpp/lib/service_registry.h"
13 #include "mojo/converters/network/network_type_converters.h"
13 #include "mojo/public/cpp/bindings/interface_ptr.h" 14 #include "mojo/public/cpp/bindings/interface_ptr.h"
14 #include "mojo/public/cpp/environment/logging.h" 15 #include "mojo/public/cpp/environment/logging.h"
15 16
16 namespace mojo { 17 namespace mojo {
17 18
18 namespace { 19 namespace {
19 20
20 void DefaultTerminationClosure() { 21 void DefaultTerminationClosure() {
21 if (base::MessageLoop::current() && 22 if (base::MessageLoop::current() &&
22 base::MessageLoop::current()->is_running()) 23 base::MessageLoop::current()->is_running())
23 base::MessageLoop::current()->QuitWhenIdle(); 24 base::MessageLoop::current()->QuitWhenIdle();
24 } 25 }
25 26
26 } // namespace 27 } // namespace
27 28
29 ApplicationImpl::ConnectParams::ConnectParams(const std::string& url)
30 : request_(URLRequest::From(url)) {}
31 ApplicationImpl::ConnectParams::ConnectParams(URLRequestPtr request)
32 : request_(request.Pass()) {}
33 ApplicationImpl::ConnectParams::~ConnectParams() {}
34
28 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, 35 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate,
29 InterfaceRequest<Application> request) 36 InterfaceRequest<Application> request)
30 : ApplicationImpl(delegate, request.Pass(), 37 : ApplicationImpl(delegate, request.Pass(),
31 base::Bind(&DefaultTerminationClosure)) { 38 base::Bind(&DefaultTerminationClosure)) {
32 } 39 }
33 40
34 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate, 41 ApplicationImpl::ApplicationImpl(ApplicationDelegate* delegate,
35 InterfaceRequest<Application> request, 42 InterfaceRequest<Application> request,
36 const Closure& termination_closure) 43 const Closure& termination_closure)
37 : delegate_(delegate), 44 : delegate_(delegate),
38 binding_(this, request.Pass()), 45 binding_(this, request.Pass()),
39 termination_closure_(termination_closure), 46 termination_closure_(termination_closure),
40 app_lifetime_helper_(this), 47 app_lifetime_helper_(this),
41 quit_requested_(false), 48 quit_requested_(false),
42 weak_factory_(this) {} 49 weak_factory_(this) {}
43 50
44 ApplicationImpl::~ApplicationImpl() { 51 ApplicationImpl::~ApplicationImpl() {
45 app_lifetime_helper_.OnQuit(); 52 app_lifetime_helper_.OnQuit();
46 } 53 }
47 54
48 scoped_ptr<ApplicationConnection> ApplicationImpl::ConnectToApplication( 55 scoped_ptr<ApplicationConnection> ApplicationImpl::ConnectToApplication(
49 const std::string& url) { 56 const std::string& url) {
50 mojo::URLRequestPtr request(mojo::URLRequest::New()); 57 ConnectParams params(url);
51 request->url = url; 58 return ConnectToApplication(&params);
52 return ConnectToApplication(request.Pass());
53 }
54
55 scoped_ptr<ApplicationConnection> ApplicationImpl::ConnectToApplication(
56 URLRequestPtr request) {
57 return ConnectToApplicationWithCapabilityFilter(request.Pass(), nullptr);
58 } 59 }
59 60
60 scoped_ptr<ApplicationConnection> 61 scoped_ptr<ApplicationConnection>
61 ApplicationImpl::ConnectToApplicationWithCapabilityFilter( 62 ApplicationImpl::ConnectToApplication(ConnectParams* params) {
62 URLRequestPtr request,
63 CapabilityFilterPtr filter) {
64 if (!shell_) 63 if (!shell_)
65 return nullptr; 64 return nullptr;
65 DCHECK(params);
66 URLRequestPtr request = params->TakeRequest();
66 ServiceProviderPtr local_services; 67 ServiceProviderPtr local_services;
67 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); 68 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services);
68 ServiceProviderPtr remote_services; 69 ServiceProviderPtr remote_services;
69 std::string application_url = request->url.To<std::string>(); 70 std::string application_url = request->url.To<std::string>();
70 // We allow all interfaces on outgoing connections since we are presumably in 71 // We allow all interfaces on outgoing connections since we are presumably in
71 // a position to know who we're talking to. 72 // a position to know who we're talking to.
72 // TODO(beng): is this a valid assumption or do we need to figure some way to 73 // TODO(beng): is this a valid assumption or do we need to figure some way to
73 // filter here too? 74 // filter here too?
74 std::set<std::string> allowed; 75 std::set<std::string> allowed;
75 allowed.insert("*"); 76 allowed.insert("*");
76 InterfaceRequest<ServiceProvider> remote_services_proxy = 77 InterfaceRequest<ServiceProvider> remote_services_proxy =
77 GetProxy(&remote_services); 78 GetProxy(&remote_services);
78 scoped_ptr<internal::ServiceRegistry> registry(new internal::ServiceRegistry( 79 scoped_ptr<internal::ServiceRegistry> registry(new internal::ServiceRegistry(
79 application_url, application_url, remote_services.Pass(), 80 application_url, application_url, remote_services.Pass(),
80 local_request.Pass(), allowed)); 81 local_request.Pass(), allowed));
81 shell_->ConnectToApplication(request.Pass(), remote_services_proxy.Pass(), 82 shell_->ConnectToApplication(request.Pass(), remote_services_proxy.Pass(),
82 local_services.Pass(), filter.Pass(), 83 local_services.Pass(),
84 params->TakeFilter().Pass(),
83 registry->GetConnectToApplicationCallback()); 85 registry->GetConnectToApplicationCallback());
84 if (!delegate_->ConfigureOutgoingConnection(registry.get())) 86 if (!delegate_->ConfigureOutgoingConnection(registry.get()))
85 return nullptr; 87 return nullptr;
86 return registry.Pass(); 88 return registry.Pass();
87 } 89 }
88 90
89 void ApplicationImpl::WaitForInitialize() { 91 void ApplicationImpl::WaitForInitialize() {
90 DCHECK(!shell_.is_bound()); 92 DCHECK(!shell_.is_bound());
91 binding_.WaitForIncomingMethodCall(); 93 binding_.WaitForIncomingMethodCall();
92 } 94 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 161 }
160 162
161 void ApplicationImpl::UnbindConnections( 163 void ApplicationImpl::UnbindConnections(
162 InterfaceRequest<Application>* application_request, 164 InterfaceRequest<Application>* application_request,
163 ShellPtr* shell) { 165 ShellPtr* shell) {
164 *application_request = binding_.Unbind(); 166 *application_request = binding_.Unbind();
165 shell->Bind(shell_.PassInterface()); 167 shell->Bind(shell_.PassInterface());
166 } 168 }
167 169
168 } // namespace mojo 170 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/application/public/cpp/application_impl.h ('k') | mojo/mojo_base.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698