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

Side by Side Diff: mojo/services/launcher/launcher.cc

Issue 380413003: Mojo: Use InterfaceFactory<Interface> for service registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix network_service_loader Created 6 years, 4 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 | Annotate | Revision Log
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/string_tokenizer.h" 8 #include "base/strings/string_tokenizer.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "mojo/public/cpp/application/application_connection.h" 10 #include "mojo/public/cpp/application/application_connection.h"
11 #include "mojo/public/cpp/application/application_delegate.h" 11 #include "mojo/public/cpp/application/application_delegate.h"
12 #include "mojo/public/cpp/application/application_impl.h" 12 #include "mojo/public/cpp/application/application_impl.h"
13 #include "mojo/public/cpp/application/interface_factory_with_context.h"
13 #include "mojo/services/public/cpp/view_manager/types.h" 14 #include "mojo/services/public/cpp/view_manager/types.h"
14 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h" 15 #include "mojo/services/public/interfaces/launcher/launcher.mojom.h"
15 #include "mojo/services/public/interfaces/network/network_service.mojom.h" 16 #include "mojo/services/public/interfaces/network/network_service.mojom.h"
16 #include "mojo/services/public/interfaces/network/url_loader.mojom.h" 17 #include "mojo/services/public/interfaces/network/url_loader.mojom.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 namespace mojo { 20 namespace mojo {
20 namespace launcher { 21 namespace launcher {
21 22
22 namespace { 23 namespace {
23 24
24 typedef mojo::Callback<void(String handler_url, String view_url, 25 typedef mojo::Callback<void(String handler_url, String view_url,
25 navigation::ResponseDetailsPtr response)> LaunchCallback; 26 navigation::ResponseDetailsPtr response)> LaunchCallback;
26 27
27 } 28 }
28 29
29 class LauncherApp; 30 class LauncherApp;
30 31
31 class LauncherConnection : public InterfaceImpl<Launcher> { 32 class LauncherConnection : public InterfaceImpl<Launcher> {
32 public: 33 public:
33 LauncherConnection(ApplicationConnection* connection, LauncherApp* app) 34 explicit LauncherConnection(LauncherApp* app) : app_(app) {}
34 : app_(app) {}
35 virtual ~LauncherConnection() {} 35 virtual ~LauncherConnection() {}
36 36
37 private: 37 private:
38 // Overridden from Launcher: 38 // Overridden from Launcher:
39 virtual void Launch(const String& url, 39 virtual void Launch(const String& url,
40 const LaunchCallback& callback) OVERRIDE; 40 const LaunchCallback& callback) OVERRIDE;
41 41
42 LauncherApp* app_; 42 LauncherApp* app_;
43 43
44 DISALLOW_COPY_AND_ASSIGN(LauncherConnection); 44 DISALLOW_COPY_AND_ASSIGN(LauncherConnection);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 LauncherApp* app_; 80 LauncherApp* app_;
81 bool destroy_scheduled_; 81 bool destroy_scheduled_;
82 const LaunchCallback callback_; 82 const LaunchCallback callback_;
83 URLLoaderPtr url_loader_; 83 URLLoaderPtr url_loader_;
84 ScopedDataPipeConsumerHandle response_body_stream_; 84 ScopedDataPipeConsumerHandle response_body_stream_;
85 85
86 DISALLOW_COPY_AND_ASSIGN(LaunchInstance); 86 DISALLOW_COPY_AND_ASSIGN(LaunchInstance);
87 }; 87 };
88 88
89 class LauncherApp : public ApplicationDelegate { 89 class LauncherApp
90 : public ApplicationDelegate,
91 public InterfaceFactoryWithContext<LauncherConnection, LauncherApp> {
90 public: 92 public:
91 LauncherApp() { 93 LauncherApp() : InterfaceFactoryWithContext(this) {
92 handler_map_["text/html"] = "mojo:mojo_html_viewer"; 94 handler_map_["text/html"] = "mojo:mojo_html_viewer";
93 handler_map_["image/png"] = "mojo:mojo_media_viewer"; 95 handler_map_["image/png"] = "mojo:mojo_media_viewer";
94 } 96 }
95 virtual ~LauncherApp() {} 97 virtual ~LauncherApp() {}
96 98
97 URLLoaderPtr CreateURLLoader() { 99 URLLoaderPtr CreateURLLoader() {
98 URLLoaderPtr loader; 100 URLLoaderPtr loader;
99 network_service_->CreateURLLoader(Get(&loader)); 101 network_service_->CreateURLLoader(Get(&loader));
100 return loader.Pass(); 102 return loader.Pass();
101 } 103 }
102 104
103 std::string GetHandlerForContentType(const std::string& content_type) { 105 std::string GetHandlerForContentType(const std::string& content_type) {
104 HandlerMap::const_iterator it = handler_map_.find(content_type); 106 HandlerMap::const_iterator it = handler_map_.find(content_type);
105 return it != handler_map_.end() ? it->second : ""; 107 return it != handler_map_.end() ? it->second : "";
106 } 108 }
107 109
108 private: 110 private:
109 typedef std::map<std::string, std::string> HandlerMap; 111 typedef std::map<std::string, std::string> HandlerMap;
110 112
111 // Overridden from ApplicationDelegate: 113 // Overridden from ApplicationDelegate:
112 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE { 114 virtual void Initialize(ApplicationImpl* app) MOJO_OVERRIDE {
113 app->ConnectToService("mojo:mojo_network_service", &network_service_); 115 app->ConnectToService("mojo:mojo_network_service", &network_service_);
114 } 116 }
115 117
116 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection) 118 virtual bool ConfigureIncomingConnection(ApplicationConnection* connection)
117 MOJO_OVERRIDE { 119 MOJO_OVERRIDE {
118 connection->AddService<LauncherConnection>(this); 120 connection->AddService(this);
119 return true; 121 return true;
120 } 122 }
121 123
122 HandlerMap handler_map_; 124 HandlerMap handler_map_;
123 125
124 NetworkServicePtr network_service_; 126 NetworkServicePtr network_service_;
125 127
126 DISALLOW_COPY_AND_ASSIGN(LauncherApp); 128 DISALLOW_COPY_AND_ASSIGN(LauncherApp);
127 }; 129 };
128 130
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 178 }
177 179
178 } // namespace launcher 180 } // namespace launcher
179 181
180 // static 182 // static
181 ApplicationDelegate* ApplicationDelegate::Create() { 183 ApplicationDelegate* ApplicationDelegate::Create() {
182 return new launcher::LauncherApp; 184 return new launcher::LauncherApp;
183 } 185 }
184 186
185 } // namespace mojo 187 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/html_viewer/html_viewer.cc ('k') | mojo/services/native_viewport/native_viewport_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698