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

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

Issue 1195003002: Mandoline: Introduce ApplicationConnection::CloseConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed typo 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/application/public/cpp/application_impl.h" 5 #include "mojo/application/public/cpp/application_impl.h"
6 6
7 #include <algorithm>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "mojo/application/public/cpp/application_delegate.h" 11 #include "mojo/application/public/cpp/application_delegate.h"
10 #include "mojo/application/public/cpp/lib/service_registry.h" 12 #include "mojo/application/public/cpp/lib/service_registry.h"
11 #include "mojo/public/cpp/bindings/interface_ptr.h" 13 #include "mojo/public/cpp/bindings/interface_ptr.h"
12 #include "mojo/public/cpp/environment/logging.h" 14 #include "mojo/public/cpp/environment/logging.h"
13 15
14 namespace mojo { 16 namespace mojo {
15 17
16 namespace { 18 namespace {
(...skipping 16 matching lines...) Expand all
33 const base::Closure& termination_closure) 35 const base::Closure& termination_closure)
34 : delegate_(delegate), 36 : delegate_(delegate),
35 binding_(this, request.Pass()), 37 binding_(this, request.Pass()),
36 termination_closure_(termination_closure), 38 termination_closure_(termination_closure),
37 app_lifetime_helper_(this), 39 app_lifetime_helper_(this),
38 quit_requested_(false), 40 quit_requested_(false),
39 weak_factory_(this) { 41 weak_factory_(this) {
40 } 42 }
41 43
42 void ApplicationImpl::ClearConnections() { 44 void ApplicationImpl::ClearConnections() {
43 for (ServiceRegistryList::iterator i(incoming_service_registries_.begin()); 45 // Copy the ServiceRegistryLists because they will be mutated by
44 i != incoming_service_registries_.end(); 46 // ApplicationConnection::CloseConnection.
45 ++i) 47 ServiceRegistryList incoming_service_registries(incoming_service_registries_);
46 delete *i; 48 for (internal::ServiceRegistry* registry : incoming_service_registries)
47 for (ServiceRegistryList::iterator i(outgoing_service_registries_.begin()); 49 registry->CloseConnection();
48 i != outgoing_service_registries_.end(); 50 DCHECK(incoming_service_registries_.empty());
49 ++i) 51
50 delete *i; 52 ServiceRegistryList outgoing_service_registries(outgoing_service_registries_);
51 incoming_service_registries_.clear(); 53 for (internal::ServiceRegistry* registry : outgoing_service_registries)
52 outgoing_service_registries_.clear(); 54 registry->CloseConnection();
55 DCHECK(outgoing_service_registries_.empty());
53 } 56 }
54 57
55 ApplicationImpl::~ApplicationImpl() { 58 ApplicationImpl::~ApplicationImpl() {
56 ClearConnections(); 59 ClearConnections();
57 app_lifetime_helper_.ApplicationTerminated(); 60 app_lifetime_helper_.ApplicationTerminated();
58 } 61 }
59 62
60 ApplicationConnection* ApplicationImpl::ConnectToApplication( 63 ApplicationConnection* ApplicationImpl::ConnectToApplication(
61 mojo::URLRequestPtr request) { 64 mojo::URLRequestPtr request) {
62 MOJO_CHECK(shell_); 65 MOJO_CHECK(shell_);
63 ServiceProviderPtr local_services; 66 ServiceProviderPtr local_services;
64 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services); 67 InterfaceRequest<ServiceProvider> local_request = GetProxy(&local_services);
65 ServiceProviderPtr remote_services; 68 ServiceProviderPtr remote_services;
66 std::string application_url = request->url.To<std::string>(); 69 std::string application_url = request->url.To<std::string>();
67 shell_->ConnectToApplication(request.Pass(), GetProxy(&remote_services), 70 shell_->ConnectToApplication(request.Pass(), GetProxy(&remote_services),
68 local_services.Pass()); 71 local_services.Pass());
69 internal::ServiceRegistry* registry = new internal::ServiceRegistry( 72 internal::ServiceRegistry* registry = new internal::ServiceRegistry(
70 this, application_url, application_url, remote_services.Pass(), 73 this, application_url, application_url, remote_services.Pass(),
71 local_request.Pass()); 74 local_request.Pass());
72 if (!delegate_->ConfigureOutgoingConnection(registry)) { 75 if (!delegate_->ConfigureOutgoingConnection(registry)) {
73 delete registry; 76 registry->CloseConnection();
74 return nullptr; 77 return nullptr;
75 } 78 }
76 outgoing_service_registries_.push_back(registry); 79 outgoing_service_registries_.push_back(registry);
77 return registry; 80 return registry;
78 } 81 }
79 82
83 void ApplicationImpl::CloseConnection(ApplicationConnection* connection) {
84 if (delegate_)
85 delegate_->OnWillCloseConnection(connection);
sky 2015/06/29 21:26:00 Is this problematic for HTMLViewer? HTMLViewer has
Fady Samuel 2015/06/29 21:50:14 This shouldn't be a problem. In ApplicationRunner,
sky 2015/06/29 23:38:38 Could WillDestroySoon be replaced with a boolean m
Fady Samuel 2015/06/30 15:07:22 Yes, that works. Done.
86 auto outgoing_it = std::find(outgoing_service_registries_.begin(),
87 outgoing_service_registries_.end(),
88 connection);
89 if (outgoing_it != outgoing_service_registries_.end()) {
90 outgoing_service_registries_.erase(outgoing_it);
91 return;
92 }
93 auto incoming_it = std::find(incoming_service_registries_.begin(),
94 incoming_service_registries_.end(),
95 connection);
96 if (incoming_it != incoming_service_registries_.end())
97 incoming_service_registries_.erase(incoming_it);
98 }
99
100 void ApplicationImpl::WillDestroySoon() {
101 delegate_ = nullptr;
102 }
103
80 void ApplicationImpl::Initialize(ShellPtr shell, const mojo::String& url) { 104 void ApplicationImpl::Initialize(ShellPtr shell, const mojo::String& url) {
81 shell_ = shell.Pass(); 105 shell_ = shell.Pass();
82 shell_.set_error_handler(this); 106 shell_.set_error_handler(this);
83 url_ = url; 107 url_ = url;
84 delegate_->Initialize(this); 108 delegate_->Initialize(this);
85 } 109 }
86 110
87 void ApplicationImpl::WaitForInitialize() { 111 void ApplicationImpl::WaitForInitialize() {
88 if (!shell_) 112 if (!shell_)
89 binding_.WaitForIncomingMethodCall(); 113 binding_.WaitForIncomingMethodCall();
(...skipping 23 matching lines...) Expand all
113 } 137 }
114 138
115 void ApplicationImpl::AcceptConnection( 139 void ApplicationImpl::AcceptConnection(
116 const String& requestor_url, 140 const String& requestor_url,
117 InterfaceRequest<ServiceProvider> services, 141 InterfaceRequest<ServiceProvider> services,
118 ServiceProviderPtr exposed_services, 142 ServiceProviderPtr exposed_services,
119 const String& url) { 143 const String& url) {
120 internal::ServiceRegistry* registry = new internal::ServiceRegistry( 144 internal::ServiceRegistry* registry = new internal::ServiceRegistry(
121 this, url, requestor_url, exposed_services.Pass(), services.Pass()); 145 this, url, requestor_url, exposed_services.Pass(), services.Pass());
122 if (!delegate_->ConfigureIncomingConnection(registry)) { 146 if (!delegate_->ConfigureIncomingConnection(registry)) {
123 delete registry; 147 registry->CloseConnection();
124 return; 148 return;
125 } 149 }
126 incoming_service_registries_.push_back(registry); 150 incoming_service_registries_.push_back(registry);
127 151
128 // If we were quitting because we thought there were no more services for this 152 // If we were quitting because we thought there were no more services for this
129 // app in use, then that has changed so cancel the quit request. 153 // app in use, then that has changed so cancel the quit request.
130 if (quit_requested_) 154 if (quit_requested_)
131 quit_requested_ = false; 155 quit_requested_ = false;
132 } 156 }
133 157
134 void ApplicationImpl::OnQuitRequested(const Callback<void(bool)>& callback) { 158 void ApplicationImpl::OnQuitRequested(const Callback<void(bool)>& callback) {
135 // If by the time we got the reply from the shell, more requests had come in 159 // If by the time we got the reply from the shell, more requests had come in
136 // then we don't want to quit the app anymore so we return false. Otherwise 160 // then we don't want to quit the app anymore so we return false. Otherwise
137 // |quit_requested_| is true so we tell the shell to proceed with the quit. 161 // |quit_requested_| is true so we tell the shell to proceed with the quit.
138 callback.Run(quit_requested_); 162 callback.Run(quit_requested_);
139 if (quit_requested_) 163 if (quit_requested_)
140 QuitNow(); 164 QuitNow();
141 } 165 }
142 166
143 void ApplicationImpl::OnConnectionError() { 167 void ApplicationImpl::OnConnectionError() {
144 base::WeakPtr<ApplicationImpl> ptr(weak_factory_.GetWeakPtr()); 168 base::WeakPtr<ApplicationImpl> ptr(weak_factory_.GetWeakPtr());
145 QuitNow(); 169 QuitNow();
146 if (!ptr) 170 if (!ptr)
147 return; 171 return;
148 shell_ = nullptr; 172 shell_ = nullptr;
149 } 173 }
150 174
151 } // namespace mojo 175 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698