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

Side by Side Diff: mojo/package_manager/content_handler_connection.cc

Issue 1566253002: Move package_manager into mojo/shell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 11 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
(Empty)
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.
4
5 #include "mojo/package_manager/content_handler_connection.h"
6
7 #include <stdint.h>
8
9 #include <utility>
10
11 #include "base/bind.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "mojo/shell/application_manager.h"
14 #include "mojo/shell/connect_to_application_params.h"
15 #include "mojo/shell/identity.h"
16
17 namespace mojo {
18 namespace package_manager {
19
20 ContentHandlerConnection::ContentHandlerConnection(
21 shell::ApplicationManager* manager,
22 const shell::Identity& source,
23 const shell::Identity& content_handler,
24 uint32_t id,
25 const ClosedCallback& connection_closed_callback)
26 : connection_closed_callback_(connection_closed_callback),
27 identity_(content_handler),
28 connection_closed_(false),
29 id_(id),
30 ref_count_(0) {
31 ServiceProviderPtr services;
32
33 scoped_ptr<shell::ConnectToApplicationParams> params(
34 new shell::ConnectToApplicationParams);
35 params->set_source(source);
36 params->SetTarget(identity_);
37 params->set_services(GetProxy(&services));
38 manager->ConnectToApplication(std::move(params));
39
40 MessagePipe pipe;
41 content_handler_.Bind(
42 InterfacePtrInfo<ContentHandler>(std::move(pipe.handle0), 0u));
43 services->ConnectToService(ContentHandler::Name_, std::move(pipe.handle1));
44 content_handler_.set_connection_error_handler(
45 [this]() { CloseConnection(); });
46 }
47
48 void ContentHandlerConnection::StartApplication(
49 InterfaceRequest<Application> request,
50 URLResponsePtr response) {
51 content_handler_->StartApplication(
52 std::move(request), std::move(response),
53 base::Bind(&ContentHandlerConnection::ApplicationDestructed,
54 base::Unretained(this)));
55 ref_count_++;
56 }
57
58 void ContentHandlerConnection::CloseConnection() {
59 if (connection_closed_)
60 return;
61 connection_closed_ = true;
62 connection_closed_callback_.Run(this);
63 delete this;
64 }
65
66 ContentHandlerConnection::~ContentHandlerConnection() {
67 // If this DCHECK fails then something has tried to delete this object without
68 // calling CloseConnection.
69 DCHECK(connection_closed_);
70 }
71
72 void ContentHandlerConnection::ApplicationDestructed() {
73 if (!--ref_count_)
74 CloseConnection();
75 }
76
77 } // namespace package_manager
78 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/package_manager/content_handler_connection.h ('k') | mojo/package_manager/content_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698