Infobar material design refresh: bg color
[chromium-blink-merge.git] / mojo / shell / content_handler_connection.cc
blobcf733f6a98fc57fb8907ff586d89460aac3bcd77
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/shell/content_handler_connection.h"
7 #include "mojo/shell/application_manager.h"
9 namespace mojo {
10 namespace shell {
12 ContentHandlerConnection::ContentHandlerConnection(
13 ApplicationInstance* originator,
14 ApplicationManager* manager,
15 const GURL& content_handler_url,
16 const GURL& requestor_url,
17 const std::string& qualifier,
18 const CapabilityFilter& filter,
19 uint32_t id)
20 : manager_(manager),
21 content_handler_url_(content_handler_url),
22 content_handler_qualifier_(qualifier),
23 connection_closed_(false),
24 id_(id) {
25 ServiceProviderPtr services;
26 mojo::URLRequestPtr request(mojo::URLRequest::New());
27 request->url = mojo::String::From(content_handler_url.spec());
28 manager->ConnectToApplication(
29 originator, request.Pass(), qualifier, requestor_url, GetProxy(&services),
30 nullptr, filter, base::Closure(), EmptyConnectCallback());
31 MessagePipe pipe;
32 content_handler_.Bind(
33 InterfacePtrInfo<ContentHandler>(pipe.handle0.Pass(), 0u));
34 services->ConnectToService(ContentHandler::Name_, pipe.handle1.Pass());
35 content_handler_.set_connection_error_handler(
36 [this]() { CloseConnection(); });
39 void ContentHandlerConnection::CloseConnection() {
40 if (connection_closed_)
41 return;
42 connection_closed_ = true;
43 manager_->OnContentHandlerConnectionClosed(this);
44 delete this;
47 ContentHandlerConnection::~ContentHandlerConnection() {
48 // If this DCHECK fails then something has tried to delete this object without
49 // calling CloseConnection.
50 DCHECK(connection_closed_);
53 } // namespace shell
54 } // namespace mojo