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

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

Issue 1228743002: Mandoline: Move ContentHandlerConnection into separate file (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed jam's comments Created 5 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/application_manager.h" 5 #include "mojo/shell/application_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/trace_event/trace_event.h" 13 #include "base/trace_event/trace_event.h"
14 #include "mojo/application/public/interfaces/content_handler.mojom.h" 14 #include "mojo/application/public/interfaces/content_handler.mojom.h"
15 #include "mojo/public/cpp/bindings/binding.h" 15 #include "mojo/public/cpp/bindings/binding.h"
16 #include "mojo/public/cpp/bindings/error_handler.h" 16 #include "mojo/public/cpp/bindings/error_handler.h"
17 #include "mojo/shell/content_handler_connection.h"
17 #include "mojo/shell/fetcher.h" 18 #include "mojo/shell/fetcher.h"
18 #include "mojo/shell/local_fetcher.h" 19 #include "mojo/shell/local_fetcher.h"
19 #include "mojo/shell/network_fetcher.h" 20 #include "mojo/shell/network_fetcher.h"
20 #include "mojo/shell/query_util.h" 21 #include "mojo/shell/query_util.h"
21 #include "mojo/shell/shell_impl.h" 22 #include "mojo/shell/shell_impl.h"
22 #include "mojo/shell/switches.h" 23 #include "mojo/shell/switches.h"
23 #include "mojo/shell/update_fetcher.h" 24 #include "mojo/shell/update_fetcher.h"
24 25
25 namespace mojo { 26 namespace mojo {
26 namespace shell { 27 namespace shell {
27 28
28 namespace { 29 namespace {
29 30
30 // Used by TestAPI. 31 // Used by TestAPI.
31 bool has_created_instance = false; 32 bool has_created_instance = false;
32 33
33 } // namespace 34 } // namespace
34 35
35 class ApplicationManager::ContentHandlerConnection : public ErrorHandler {
36 public:
37 ContentHandlerConnection(ApplicationManager* manager,
38 const GURL& content_handler_url,
39 const GURL& requestor_url,
40 const std::string& qualifier)
41 : manager_(manager),
42 content_handler_url_(content_handler_url),
43 content_handler_qualifier_(qualifier) {
44 ServiceProviderPtr services;
45 mojo::URLRequestPtr request(mojo::URLRequest::New());
46 request->url = mojo::String::From(content_handler_url.spec());
47 manager->ConnectToApplicationInternal(
48 request.Pass(), qualifier, requestor_url, GetProxy(&services),
49 nullptr, base::Closure());
50 MessagePipe pipe;
51 content_handler_.Bind(
52 InterfacePtrInfo<ContentHandler>(pipe.handle0.Pass(), 0u));
53 services->ConnectToService(ContentHandler::Name_, pipe.handle1.Pass());
54 content_handler_.set_error_handler(this);
55 }
56
57 ContentHandler* content_handler() { return content_handler_.get(); }
58
59 GURL content_handler_url() { return content_handler_url_; }
60 std::string content_handler_qualifier() { return content_handler_qualifier_; }
61
62 private:
63 // ErrorHandler implementation:
64 void OnConnectionError() override { manager_->OnContentHandlerError(this); }
65
66 ApplicationManager* manager_;
67 GURL content_handler_url_;
68 std::string content_handler_qualifier_;
69 ContentHandlerPtr content_handler_;
70
71 DISALLOW_COPY_AND_ASSIGN(ContentHandlerConnection);
72 };
73
74 // static 36 // static
75 ApplicationManager::TestAPI::TestAPI(ApplicationManager* manager) 37 ApplicationManager::TestAPI::TestAPI(ApplicationManager* manager)
76 : manager_(manager) { 38 : manager_(manager) {
77 } 39 }
78 40
79 ApplicationManager::TestAPI::~TestAPI() { 41 ApplicationManager::TestAPI::~TestAPI() {
80 } 42 }
81 43
82 bool ApplicationManager::TestAPI::HasCreatedInstance() { 44 bool ApplicationManager::TestAPI::HasCreatedInstance() {
83 return has_created_instance; 45 return has_created_instance;
84 } 46 }
85 47
86 bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const { 48 bool ApplicationManager::TestAPI::HasFactoryForURL(const GURL& url) const {
87 return manager_->identity_to_shell_impl_.find(Identity(url)) != 49 return manager_->identity_to_shell_impl_.find(Identity(url)) !=
88 manager_->identity_to_shell_impl_.end(); 50 manager_->identity_to_shell_impl_.end();
89 } 51 }
90 52
91 ApplicationManager::ApplicationManager(Delegate* delegate) 53 ApplicationManager::ApplicationManager(Delegate* delegate)
92 : delegate_(delegate), weak_ptr_factory_(this) { 54 : delegate_(delegate), weak_ptr_factory_(this) {
93 } 55 }
94 56
95 ApplicationManager::~ApplicationManager() { 57 ApplicationManager::~ApplicationManager() {
96 STLDeleteValues(&url_to_content_handler_); 58 URLToContentHandlerMap url_to_content_handler(url_to_content_handler_);
59 for (auto& pair : url_to_content_handler)
60 pair.second->CloseConnection();
97 TerminateShellConnections(); 61 TerminateShellConnections();
98 STLDeleteValues(&url_to_loader_); 62 STLDeleteValues(&url_to_loader_);
99 STLDeleteValues(&scheme_to_loader_); 63 STLDeleteValues(&scheme_to_loader_);
100 } 64 }
101 65
102 void ApplicationManager::TerminateShellConnections() { 66 void ApplicationManager::TerminateShellConnections() {
103 STLDeleteValues(&identity_to_shell_impl_); 67 STLDeleteValues(&identity_to_shell_impl_);
104 } 68 }
105 69
106 void ApplicationManager::ConnectToApplication( 70 void ApplicationManager::ConnectToApplication(
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 base::Closure on_application_end = shell_impl->on_application_end(); 480 base::Closure on_application_end = shell_impl->on_application_end();
517 // Remove the shell. 481 // Remove the shell.
518 auto it = identity_to_shell_impl_.find(identity); 482 auto it = identity_to_shell_impl_.find(identity);
519 DCHECK(it != identity_to_shell_impl_.end()); 483 DCHECK(it != identity_to_shell_impl_.end());
520 delete it->second; 484 delete it->second;
521 identity_to_shell_impl_.erase(it); 485 identity_to_shell_impl_.erase(it);
522 if (!on_application_end.is_null()) 486 if (!on_application_end.is_null())
523 on_application_end.Run(); 487 on_application_end.Run();
524 } 488 }
525 489
526 void ApplicationManager::OnContentHandlerError( 490 void ApplicationManager::OnContentHandlerConnectionClosed(
527 ContentHandlerConnection* content_handler) { 491 ContentHandlerConnection* content_handler) {
528 // Remove the mapping to the content handler. 492 // Remove the mapping to the content handler.
529 auto it = url_to_content_handler_.find( 493 auto it = url_to_content_handler_.find(
530 std::make_pair(content_handler->content_handler_url(), 494 std::make_pair(content_handler->content_handler_url(),
531 content_handler->content_handler_qualifier())); 495 content_handler->content_handler_qualifier()));
532 DCHECK(it != url_to_content_handler_.end()); 496 DCHECK(it != url_to_content_handler_.end());
533 delete it->second;
534 url_to_content_handler_.erase(it); 497 url_to_content_handler_.erase(it);
535 } 498 }
536 499
537 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName( 500 ScopedMessagePipeHandle ApplicationManager::ConnectToServiceByName(
538 const GURL& application_url, 501 const GURL& application_url,
539 const std::string& interface_name) { 502 const std::string& interface_name) {
540 ServiceProviderPtr services; 503 ServiceProviderPtr services;
541 mojo::URLRequestPtr request(mojo::URLRequest::New()); 504 mojo::URLRequestPtr request(mojo::URLRequest::New());
542 request->url = mojo::String::From(application_url.spec()); 505 request->url = mojo::String::From(application_url.spec());
543 ConnectToApplication(request.Pass(), GURL(), GetProxy(&services), nullptr, 506 ConnectToApplication(request.Pass(), GURL(), GetProxy(&services), nullptr,
544 base::Closure()); 507 base::Closure());
545 MessagePipe pipe; 508 MessagePipe pipe;
546 services->ConnectToService(interface_name, pipe.handle1.Pass()); 509 services->ConnectToService(interface_name, pipe.handle1.Pass());
547 return pipe.handle0.Pass(); 510 return pipe.handle0.Pass();
548 } 511 }
549 512
550 void ApplicationManager::CleanupRunner(NativeRunner* runner) { 513 void ApplicationManager::CleanupRunner(NativeRunner* runner) {
551 native_runners_.erase( 514 native_runners_.erase(
552 std::find(native_runners_.begin(), native_runners_.end(), runner)); 515 std::find(native_runners_.begin(), native_runners_.end(), runner));
553 } 516 }
554 517
555 } // namespace shell 518 } // namespace shell
556 } // namespace mojo 519 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698