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

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

Issue 1311353005: Adds a way to determine id of content handler that created app (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: separate out declaration/definition Created 5 years, 3 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 2015 The Chromium Authors. All rights reserved. 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 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/shell/content_handler_connection.h" 5 #include "mojo/shell/content_handler_connection.h"
6 6
7 #include "base/bind.h"
7 #include "mojo/shell/application_manager.h" 8 #include "mojo/shell/application_manager.h"
8 9
9 namespace mojo { 10 namespace mojo {
10 namespace shell { 11 namespace shell {
11 12
12 ContentHandlerConnection::ContentHandlerConnection( 13 ContentHandlerConnection::ContentHandlerConnection(
13 ApplicationInstance* originator, 14 ApplicationInstance* originator,
14 ApplicationManager* manager, 15 ApplicationManager* manager,
15 const GURL& content_handler_url, 16 const GURL& content_handler_url,
16 const GURL& requestor_url, 17 const GURL& requestor_url,
17 const std::string& qualifier, 18 const std::string& qualifier,
18 const CapabilityFilter& filter) 19 const CapabilityFilter& filter,
20 uint32_t id)
19 : manager_(manager), 21 : manager_(manager),
20 content_handler_url_(content_handler_url), 22 content_handler_url_(content_handler_url),
21 content_handler_qualifier_(qualifier), 23 content_handler_qualifier_(qualifier),
22 connection_closed_(false) { 24 connection_closed_(false),
25 id_(id),
26 got_nested_content_handler_id_(false),
27 nested_content_handler_id_(0u),
28 weak_ptr_factory_(this) {
23 ServiceProviderPtr services; 29 ServiceProviderPtr services;
24 mojo::URLRequestPtr request(mojo::URLRequest::New()); 30 mojo::URLRequestPtr request(mojo::URLRequest::New());
25 request->url = mojo::String::From(content_handler_url.spec()); 31 request->url = mojo::String::From(content_handler_url.spec());
26 manager->ConnectToApplication( 32 manager->ConnectToApplication(
27 originator, request.Pass(), qualifier, requestor_url, GetProxy(&services), 33 originator, request.Pass(), qualifier, requestor_url, id,
28 nullptr, filter, base::Closure()); 34 GetProxy(&services), nullptr, filter, base::Closure(),
35 base::Bind(&ContentHandlerConnection::OnGotNestedContentHandlerID,
36 weak_ptr_factory_.GetWeakPtr()));
29 MessagePipe pipe; 37 MessagePipe pipe;
30 content_handler_.Bind( 38 content_handler_.Bind(
31 InterfacePtrInfo<ContentHandler>(pipe.handle0.Pass(), 0u)); 39 InterfacePtrInfo<ContentHandler>(pipe.handle0.Pass(), 0u));
32 services->ConnectToService(ContentHandler::Name_, pipe.handle1.Pass()); 40 services->ConnectToService(ContentHandler::Name_, pipe.handle1.Pass());
33 content_handler_.set_connection_error_handler( 41 content_handler_.set_connection_error_handler(
34 [this]() { CloseConnection(); }); 42 [this]() { CloseConnection(); });
35 } 43 }
36 44
37 void ContentHandlerConnection::CloseConnection() { 45 void ContentHandlerConnection::CloseConnection() {
38 if (connection_closed_) 46 if (connection_closed_)
39 return; 47 return;
40 connection_closed_ = true; 48 connection_closed_ = true;
41 manager_->OnContentHandlerConnectionClosed(this); 49 manager_->OnContentHandlerConnectionClosed(this);
42 delete this; 50 delete this;
43 } 51 }
44 52
53 void ContentHandlerConnection::ScheduleTargetIdCallback(
54 const Shell::ConnectToApplicationCallback& connect_callback) {
55 if (got_nested_content_handler_id_)
56 connect_callback.Run(content_handler_id_for_callback());
57 else
58 pending_content_handler_id_callbacks_.push_back(connect_callback);
59 }
60
45 ContentHandlerConnection::~ContentHandlerConnection() { 61 ContentHandlerConnection::~ContentHandlerConnection() {
46 // If this DCHECK fails then something has tried to delete this object without 62 // If this DCHECK fails then something has tried to delete this object without
47 // calling CloseConnection. 63 // calling CloseConnection.
48 DCHECK(connection_closed_); 64 DCHECK(connection_closed_);
49 } 65 }
50 66
67 void ContentHandlerConnection::OnGotNestedContentHandlerID(
68 uint32_t content_handler_id) {
69 DCHECK(!got_nested_content_handler_id_);
70 got_nested_content_handler_id_ = true;
71 nested_content_handler_id_ = content_handler_id;
72 for (auto callback : pending_content_handler_id_callbacks_)
73 callback.Run(content_handler_id_for_callback());
74 pending_content_handler_id_callbacks_.clear();
75 }
76
77 uint32_t ContentHandlerConnection::content_handler_id_for_callback() const {
78 return nested_content_handler_id_ ==
79 ApplicationManager::kInvalidContentHandlerID
80 ? id_
81 : nested_content_handler_id_;
82 }
83
51 } // namespace shell 84 } // namespace shell
52 } // namespace mojo 85 } // namespace mojo
OLDNEW
« mojo/shell/content_handler_connection.h ('K') | « mojo/shell/content_handler_connection.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698