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

Unified Diff: content/common/service_manager/service_manager_connection_impl.cc

Issue 2795413002: Makes ServiceManagerConnectionImpl queue requests (Closed)
Patch Set: merge Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/service_manager/service_manager_connection_impl.cc
diff --git a/content/common/service_manager/service_manager_connection_impl.cc b/content/common/service_manager/service_manager_connection_impl.cc
index 9e81238aa0a4a53a53cbf5928388dcc0a9d1c9ec..ea9b4f4cc3584edf7c6eefa71c939726d8367c15 100644
--- a/content/common/service_manager/service_manager_connection_impl.cc
+++ b/content/common/service_manager/service_manager_connection_impl.cc
@@ -139,6 +139,11 @@ class ServiceManagerConnectionImpl::IOThreadContext
private:
friend class base::RefCountedThreadSafe<IOThreadContext>;
+ struct PendingRequest {
+ std::string service_name;
+ service_manager::mojom::ServiceRequest request;
+ };
+
class MessageLoopObserver : public base::MessageLoop::DestructionObserver {
public:
explicit MessageLoopObserver(base::WeakPtr<IOThreadContext> context)
@@ -256,6 +261,16 @@ class ServiceManagerConnectionImpl::IOThreadContext
DCHECK(io_thread_checker_.CalledOnValidThread());
auto result = request_handlers_.insert(std::make_pair(name, handler));
DCHECK(result.second);
+ auto iter = pending_requests_.begin();
+ while (iter != pending_requests_.end()) {
+ if ((*iter)->service_name == name) {
+ std::unique_ptr<PendingRequest> pending_request = std::move(*iter);
+ iter = pending_requests_.erase(iter);
+ handler.Run(std::move(pending_request->request));
+ } else {
+ ++iter;
+ }
+ }
}
/////////////////////////////////////////////////////////////////////////////
@@ -329,8 +344,14 @@ class ServiceManagerConnectionImpl::IOThreadContext
const std::string& name) override {
DCHECK(io_thread_checker_.CalledOnValidThread());
auto it = request_handlers_.find(name);
- DCHECK(it != request_handlers_.end())
- << "Can't create service " << name << ". No handler found.";
+ if (it == request_handlers_.end()) {
+ std::unique_ptr<PendingRequest> pending_request =
+ base::MakeUnique<PendingRequest>();
+ pending_request->service_name = name;
+ pending_request->request = std::move(request);
+ pending_requests_.push_back(std::move(pending_request));
+ return;
+ }
it->second.Run(std::move(request));
}
@@ -392,6 +413,10 @@ class ServiceManagerConnectionImpl::IOThreadContext
embedded_services_;
std::unordered_map<std::string, ServiceRequestHandler> request_handlers_;
+ // Requests before the service have been registered are added here. Typically
+ // there are very few elements, so we use a vector.
+ std::vector<std::unique_ptr<PendingRequest>> pending_requests_;
+
mojo::Binding<mojom::Child> child_binding_;
base::WeakPtrFactory<IOThreadContext> weak_factory_;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698