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

Side by Side Diff: services/shell/public/cpp/lib/interface_registry.cc

Issue 2111353002: Move content's shell connections to the IO thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "services/shell/public/cpp/interface_registry.h" 5 #include "services/shell/public/cpp/interface_registry.h"
6 6
7 #include "services/shell/public/cpp/connection.h" 7 #include "services/shell/public/cpp/connection.h"
8 8
9 namespace shell { 9 namespace shell {
10 10
(...skipping 21 matching lines...) Expand all
32 name); 32 name);
33 } 33 }
34 34
35 void InterfaceRegistry::RemoveInterface(const std::string& name) { 35 void InterfaceRegistry::RemoveInterface(const std::string& name) {
36 auto it = name_to_binder_.find(name); 36 auto it = name_to_binder_.find(name);
37 if (it != name_to_binder_.end()) 37 if (it != name_to_binder_.end())
38 name_to_binder_.erase(it); 38 name_to_binder_.erase(it);
39 } 39 }
40 40
41 void InterfaceRegistry::PauseBinding() { 41 void InterfaceRegistry::PauseBinding() {
42 DCHECK(!pending_request_.is_pending()); 42 DCHECK(!is_paused_);
43 DCHECK(binding_.is_bound()); 43 is_paused_ = true;
44 pending_request_ = binding_.Unbind();
45 } 44 }
46 45
47 void InterfaceRegistry::ResumeBinding() { 46 void InterfaceRegistry::ResumeBinding() {
48 DCHECK(pending_request_.is_pending()); 47 DCHECK(is_paused_);
49 DCHECK(!binding_.is_bound()); 48 is_paused_ = false;
50 binding_.Bind(std::move(pending_request_)); 49
50 while (!pending_interface_requests_.empty()) {
51 auto& request = pending_interface_requests_.front();
52 GetInterface(request.first, std::move(request.second));
53 pending_interface_requests_.pop();
54 }
51 } 55 }
52 56
53 // mojom::InterfaceProvider: 57 // mojom::InterfaceProvider:
54 void InterfaceRegistry::GetInterface(const mojo::String& interface_name, 58 void InterfaceRegistry::GetInterface(const mojo::String& interface_name,
55 mojo::ScopedMessagePipeHandle handle) { 59 mojo::ScopedMessagePipeHandle handle) {
60 if (is_paused_) {
61 pending_interface_requests_.emplace(interface_name, std::move(handle));
62 return;
63 }
64
56 auto iter = name_to_binder_.find(interface_name); 65 auto iter = name_to_binder_.find(interface_name);
57 if (iter != name_to_binder_.end()) { 66 if (iter != name_to_binder_.end()) {
58 iter->second->BindInterface(connection_, interface_name, std::move(handle)); 67 iter->second->BindInterface(connection_, interface_name, std::move(handle));
59 } else if (connection_ && !connection_->AllowsInterface(interface_name)) { 68 } else if (connection_ && !connection_->AllowsInterface(interface_name)) {
60 LOG(ERROR) << "Connection CapabilityFilter prevented binding to " 69 LOG(ERROR) << "Connection CapabilityFilter prevented binding to "
61 << "interface: " << interface_name << " connection_name:" 70 << "interface: " << interface_name << " connection_name:"
62 << connection_->GetConnectionName() << " remote_name:" 71 << connection_->GetConnectionName() << " remote_name:"
63 << connection_->GetRemoteIdentity().name(); 72 << connection_->GetRemoteIdentity().name();
73 } else if (!default_binder_.is_null()) {
74 default_binder_.Run(interface_name, std::move(handle));
64 } 75 }
65 } 76 }
66 77
67 bool InterfaceRegistry::SetInterfaceBinderForName( 78 bool InterfaceRegistry::SetInterfaceBinderForName(
68 std::unique_ptr<InterfaceBinder> binder, 79 std::unique_ptr<InterfaceBinder> binder,
69 const std::string& interface_name) { 80 const std::string& interface_name) {
70 if (!connection_ || 81 if (!connection_ ||
71 (connection_ && connection_->AllowsInterface(interface_name))) { 82 (connection_ && connection_->AllowsInterface(interface_name))) {
72 RemoveInterface(interface_name); 83 RemoveInterface(interface_name);
73 name_to_binder_[interface_name] = std::move(binder); 84 name_to_binder_[interface_name] = std::move(binder);
74 return true; 85 return true;
75 } 86 }
76 return false; 87 return false;
77 } 88 }
78 89
79 } // namespace shell 90 } // namespace shell
OLDNEW
« no previous file with comments | « services/shell/public/cpp/lib/interface_provider.cc ('k') | services/shell/public/cpp/lib/service_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698