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

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

Issue 821123005: Move application_manager's ShellImpl to own file (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 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
« no previous file with comments | « mojo/application_manager/application_manager.h ('k') | mojo/application_manager/shell_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/application_manager/application_manager.h" 5 #include "mojo/application_manager/application_manager.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "mojo/application_manager/application_loader.h" 14 #include "mojo/application_manager/application_loader.h"
15 #include "mojo/common/common_type_converters.h"
16 #include "mojo/public/cpp/application/connect.h" 15 #include "mojo/public/cpp/application/connect.h"
17 #include "mojo/public/cpp/bindings/binding.h" 16 #include "mojo/public/cpp/bindings/binding.h"
18 #include "mojo/public/cpp/bindings/error_handler.h" 17 #include "mojo/public/cpp/bindings/error_handler.h"
19 #include "mojo/public/interfaces/application/application.mojom.h"
20 #include "mojo/public/interfaces/application/shell.mojom.h" 18 #include "mojo/public/interfaces/application/shell.mojom.h"
21 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom. h" 19 #include "mojo/services/content_handler/public/interfaces/content_handler.mojom. h"
22 20
23 namespace mojo { 21 namespace mojo {
24 22
25 namespace { 23 namespace {
26 // Used by TestAPI. 24 // Used by TestAPI.
27 bool has_created_instance = false; 25 bool has_created_instance = false;
28 26
29 class StubServiceProvider : public InterfaceImpl<ServiceProvider> { 27 class StubServiceProvider : public InterfaceImpl<ServiceProvider> {
(...skipping 12 matching lines...) Expand all
42 } 40 }
43 41
44 void ApplicationManager::Delegate::OnApplicationError(const GURL& url) { 42 void ApplicationManager::Delegate::OnApplicationError(const GURL& url) {
45 LOG(ERROR) << "Communication error with application: " << url.spec(); 43 LOG(ERROR) << "Communication error with application: " << url.spec();
46 } 44 }
47 45
48 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) { 46 GURL ApplicationManager::Delegate::ResolveURL(const GURL& url) {
49 return url; 47 return url;
50 } 48 }
51 49
52
53 class ApplicationManager::ShellImpl : public Shell, public ErrorHandler {
54 public:
55 ShellImpl(ScopedMessagePipeHandle handle,
56 ApplicationManager* manager,
57 const GURL& requested_url,
58 const GURL& url)
59 : ShellImpl(manager, requested_url, url) {
60 binding_.Bind(handle.Pass());
61 }
62
63 ShellImpl(ShellPtr* ptr,
64 ApplicationManager* manager,
65 const GURL& requested_url,
66 const GURL& url)
67 : ShellImpl(manager, requested_url, url) {
68 binding_.Bind(ptr);
69 }
70
71 ~ShellImpl() override {}
72
73 void ConnectToClient(const GURL& requestor_url,
74 ServiceProviderPtr service_provider) {
75 client()->AcceptConnection(String::From(requestor_url),
76 service_provider.Pass());
77 }
78
79 Application* client() { return binding_.client(); }
80 const GURL& url() const { return url_; }
81 const GURL& requested_url() const { return requested_url_; }
82
83 private:
84 ShellImpl(ApplicationManager* manager,
85 const GURL& requested_url,
86 const GURL& url)
87 : manager_(manager),
88 requested_url_(requested_url),
89 url_(url),
90 binding_(this) {
91 binding_.set_error_handler(this);
92 }
93
94 // Shell implementation:
95 void ConnectToApplication(
96 const String& app_url,
97 InterfaceRequest<ServiceProvider> in_service_provider) override {
98 ServiceProviderPtr out_service_provider;
99 out_service_provider.Bind(in_service_provider.PassMessagePipe());
100 GURL app_gurl(app_url);
101 if (!app_gurl.is_valid()) {
102 LOG(ERROR) << "Error: invalid URL: " << app_url;
103 return;
104 }
105 manager_->ConnectToApplication(app_gurl, url_, out_service_provider.Pass());
106 }
107
108 // ErrorHandler implementation:
109 void OnConnectionError() override { manager_->OnShellImplError(this); }
110
111 ApplicationManager* const manager_;
112 const GURL requested_url_;
113 const GURL url_;
114 Binding<Shell> binding_;
115
116 DISALLOW_COPY_AND_ASSIGN(ShellImpl);
117 };
118
119 class ApplicationManager::ContentHandlerConnection : public ErrorHandler { 50 class ApplicationManager::ContentHandlerConnection : public ErrorHandler {
120 public: 51 public:
121 ContentHandlerConnection(ApplicationManager* manager, 52 ContentHandlerConnection(ApplicationManager* manager,
122 const GURL& content_handler_url) 53 const GURL& content_handler_url)
123 : manager_(manager), content_handler_url_(content_handler_url) { 54 : manager_(manager), content_handler_url_(content_handler_url) {
124 ServiceProviderPtr service_provider; 55 ServiceProviderPtr service_provider;
125 StubServiceProvider* service_provider_impl = 56 StubServiceProvider* service_provider_impl =
126 BindToProxy(new StubServiceProvider, &service_provider); 57 BindToProxy(new StubServiceProvider, &service_provider);
127 manager->ConnectToApplication( 58 manager->ConnectToApplication(
128 content_handler_url, GURL(), service_provider.Pass()); 59 content_handler_url, GURL(), service_provider.Pass());
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 return pipe.handle0.Pass(); 266 return pipe.handle0.Pass();
336 } 267 }
337 268
338 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) { 269 Array<String> ApplicationManager::GetArgsForURL(const GURL& url) {
339 URLToArgsMap::const_iterator args_it = url_to_args_.find(url); 270 URLToArgsMap::const_iterator args_it = url_to_args_.find(url);
340 if (args_it != url_to_args_.end()) 271 if (args_it != url_to_args_.end())
341 return Array<String>::From(args_it->second); 272 return Array<String>::From(args_it->second);
342 return Array<String>(); 273 return Array<String>();
343 } 274 }
344 } // namespace mojo 275 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/application_manager/application_manager.h ('k') | mojo/application_manager/shell_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698