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

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: Added test 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 this, application_url, application_url, remote_services.Pass(), 72 this, application_url, application_url, remote_services.Pass(),
71 local_request.Pass()); 73 local_request.Pass());
72 if (!delegate_->ConfigureOutgoingConnection(registry)) { 74 if (!delegate_->ConfigureOutgoingConnection(registry)) {
73 delete registry; 75 delete registry;
74 return nullptr; 76 return nullptr;
75 } 77 }
76 outgoing_service_registries_.push_back(registry); 78 outgoing_service_registries_.push_back(registry);
77 return registry; 79 return registry;
78 } 80 }
79 81
82 void ApplicationImpl::CloseConnection(ApplicationConnection* connection) {
83 scoped_ptr<ApplicationConnection> connection_owner(connection);
84 delegate_->OnWillCloseConnection(connection);
85 auto outgoing_it = std::find(outgoing_service_registries_.begin(),
86 outgoing_service_registries_.end(),
87 connection);
88 if (outgoing_it != outgoing_service_registries_.end()) {
89 outgoing_service_registries_.erase(outgoing_it);
90 return;
91 }
92 auto incoming_it = std::find(incoming_service_registries_.begin(),
93 incoming_service_registries_.end(),
94 connection);
95 if (incoming_it != incoming_service_registries_.end())
96 incoming_service_registries_.erase(incoming_it);
97 }
98
80 void ApplicationImpl::Initialize(ShellPtr shell, const mojo::String& url) { 99 void ApplicationImpl::Initialize(ShellPtr shell, const mojo::String& url) {
81 shell_ = shell.Pass(); 100 shell_ = shell.Pass();
82 shell_.set_error_handler(this); 101 shell_.set_error_handler(this);
83 url_ = url; 102 url_ = url;
84 delegate_->Initialize(this); 103 delegate_->Initialize(this);
85 } 104 }
86 105
87 void ApplicationImpl::WaitForInitialize() { 106 void ApplicationImpl::WaitForInitialize() {
88 if (!shell_) 107 if (!shell_)
89 binding_.WaitForIncomingMethodCall(); 108 binding_.WaitForIncomingMethodCall();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 161
143 void ApplicationImpl::OnConnectionError() { 162 void ApplicationImpl::OnConnectionError() {
144 base::WeakPtr<ApplicationImpl> ptr(weak_factory_.GetWeakPtr()); 163 base::WeakPtr<ApplicationImpl> ptr(weak_factory_.GetWeakPtr());
145 QuitNow(); 164 QuitNow();
146 if (!ptr) 165 if (!ptr)
147 return; 166 return;
148 shell_ = nullptr; 167 shell_ = nullptr;
149 } 168 }
150 169
151 } // namespace mojo 170 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698