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

Side by Side Diff: services/python/content_handler/content_handler_main.cc

Issue 1993053002: Simplify ContentHandlerFactory a bit. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 7 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 | « services/nacl/sfi/content_handler_main.cc ('k') | shell/android/android_handler.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 <dlfcn.h> 5 #include <dlfcn.h>
6 #include <python2.7/Python.h> 6 #include <python2.7/Python.h>
7 7
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/i18n/icu_util.h" 10 #include "base/i18n/icu_util.h"
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 197 }
198 198
199 bool debug_; 199 bool debug_;
200 200
201 DISALLOW_COPY_AND_ASSIGN(PythonContentHandler); 201 DISALLOW_COPY_AND_ASSIGN(PythonContentHandler);
202 }; 202 };
203 203
204 class PythonContentHandlerApp : public ApplicationDelegate { 204 class PythonContentHandlerApp : public ApplicationDelegate {
205 public: 205 public:
206 PythonContentHandlerApp() 206 PythonContentHandlerApp()
207 : content_handler_(false), 207 : content_handler_(false), debug_content_handler_(true) {}
208 debug_content_handler_(true),
209 content_handler_factory_(&content_handler_),
210 debug_content_handler_factory_(&debug_content_handler_) {}
211 208
212 private: 209 private:
213 // Overridden from ApplicationDelegate: 210 // Overridden from ApplicationDelegate:
214 bool ConfigureIncomingConnection( 211 bool ConfigureIncomingConnection(
215 mojo::ServiceProviderImpl* service_provider_impl) override { 212 mojo::ServiceProviderImpl* service_provider_impl) override {
216 if (IsDebug(service_provider_impl->connection_context().connection_url)) { 213 if (IsDebug(service_provider_impl->connection_context().connection_url)) {
217 service_provider_impl->AddService<mojo::ContentHandler>( 214 service_provider_impl->AddService<mojo::ContentHandler>(
218 debug_content_handler_factory_.GetInterfaceRequestHandler()); 215 ContentHandlerFactory::GetInterfaceRequestHandler(
216 &debug_content_handler_));
219 } else { 217 } else {
220 service_provider_impl->AddService<mojo::ContentHandler>( 218 service_provider_impl->AddService<mojo::ContentHandler>(
221 content_handler_factory_.GetInterfaceRequestHandler()); 219 ContentHandlerFactory::GetInterfaceRequestHandler(&content_handler_));
222 } 220 }
223 return true; 221 return true;
224 } 222 }
225 223
226 bool IsDebug(const std::string& requestedUrl) { 224 bool IsDebug(const std::string& requestedUrl) {
227 GURL url(requestedUrl); 225 GURL url(requestedUrl);
228 if (url.has_query()) { 226 if (url.has_query()) {
229 std::vector<std::string> query_parameters = base::SplitString( 227 std::vector<std::string> query_parameters = base::SplitString(
230 url.query(), "&", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); 228 url.query(), "&", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
231 return std::find(query_parameters.begin(), query_parameters.end(), 229 return std::find(query_parameters.begin(), query_parameters.end(),
232 "debug=true") != query_parameters.end(); 230 "debug=true") != query_parameters.end();
233 } 231 }
234 return false; 232 return false;
235 } 233 }
236 234
237 PythonContentHandler content_handler_; 235 PythonContentHandler content_handler_;
238 PythonContentHandler debug_content_handler_; 236 PythonContentHandler debug_content_handler_;
239 ContentHandlerFactory content_handler_factory_;
240 ContentHandlerFactory debug_content_handler_factory_;
241 237
242 DISALLOW_COPY_AND_ASSIGN(PythonContentHandlerApp); 238 DISALLOW_COPY_AND_ASSIGN(PythonContentHandlerApp);
243 }; 239 };
244 240
245 } // namespace content_handler 241 } // namespace content_handler
246 } // namespace python 242 } // namespace python
247 } // namespace services 243 } // namespace services
248 244
249 MojoResult MojoMain(MojoHandle application_request) { 245 MojoResult MojoMain(MojoHandle application_request) {
250 mojo::ApplicationRunnerChromium runner( 246 mojo::ApplicationRunnerChromium runner(
251 new services::python::content_handler::PythonContentHandlerApp()); 247 new services::python::content_handler::PythonContentHandlerApp());
252 return runner.Run(application_request); 248 return runner.Run(application_request);
253 } 249 }
OLDNEW
« no previous file with comments | « services/nacl/sfi/content_handler_main.cc ('k') | shell/android/android_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698