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

Side by Side Diff: shell/dynamic_application_loader.cc

Issue 930243006: Simplify the ApplicationLoader interface in preparation for changes. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: trybot debugging ftw Created 5 years, 10 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 "shell/dynamic_application_loader.h" 5 #include "shell/dynamic_application_loader.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/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 // Async operations are done with WeakPtr to protect against 53 // Async operations are done with WeakPtr to protect against
54 // DynamicApplicationLoader going away (and taking all the Loaders with it) 54 // DynamicApplicationLoader going away (and taking all the Loaders with it)
55 // while the async operation is outstanding. 55 // while the async operation is outstanding.
56 class DynamicApplicationLoader::Loader { 56 class DynamicApplicationLoader::Loader {
57 public: 57 public:
58 Loader(DynamicServiceRunner::CleanupBehavior cleanup_behavior, 58 Loader(DynamicServiceRunner::CleanupBehavior cleanup_behavior,
59 MimeTypeToURLMap* mime_type_to_url, 59 MimeTypeToURLMap* mime_type_to_url,
60 Context* context, 60 Context* context,
61 DynamicServiceRunnerFactory* runner_factory, 61 DynamicServiceRunnerFactory* runner_factory,
62 InterfaceRequest<Application> application_request, 62 InterfaceRequest<Application> application_request,
63 ApplicationLoader::LoadCallback load_callback, 63 LoadCallback load_callback,
64 const LoaderCompleteCallback& loader_complete_callback) 64 const LoaderCompleteCallback& loader_complete_callback)
65 : cleanup_behavior_(cleanup_behavior), 65 : cleanup_behavior_(cleanup_behavior),
66 application_request_(application_request.Pass()), 66 application_request_(application_request.Pass()),
67 load_callback_(load_callback), 67 load_callback_(load_callback),
68 loader_complete_callback_(loader_complete_callback), 68 loader_complete_callback_(loader_complete_callback),
69 context_(context), 69 context_(context),
70 mime_type_to_url_(mime_type_to_url), 70 mime_type_to_url_(mime_type_to_url),
71 runner_factory_(runner_factory), 71 runner_factory_(runner_factory),
72 weak_ptr_factory_(this) {} 72 weak_ptr_factory_(this) {}
73 73
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 144 }
145 145
146 runner_ = runner_factory_->Create(context_); 146 runner_ = runner_factory_->Create(context_);
147 runner_->Start( 147 runner_->Start(
148 path, cleanup_behavior_, application_request_.Pass(), 148 path, cleanup_behavior_, application_request_.Pass(),
149 base::Bind(&Loader::ReportComplete, weak_ptr_factory_.GetWeakPtr())); 149 base::Bind(&Loader::ReportComplete, weak_ptr_factory_.GetWeakPtr()));
150 } 150 }
151 151
152 DynamicServiceRunner::CleanupBehavior cleanup_behavior_; 152 DynamicServiceRunner::CleanupBehavior cleanup_behavior_;
153 InterfaceRequest<Application> application_request_; 153 InterfaceRequest<Application> application_request_;
154 ApplicationLoader::LoadCallback load_callback_; 154 LoadCallback load_callback_;
155 LoaderCompleteCallback loader_complete_callback_; 155 LoaderCompleteCallback loader_complete_callback_;
156 Context* context_; 156 Context* context_;
157 MimeTypeToURLMap* mime_type_to_url_; 157 MimeTypeToURLMap* mime_type_to_url_;
158 DynamicServiceRunnerFactory* runner_factory_; 158 DynamicServiceRunnerFactory* runner_factory_;
159 scoped_ptr<DynamicServiceRunner> runner_; 159 scoped_ptr<DynamicServiceRunner> runner_;
160 base::WeakPtrFactory<Loader> weak_ptr_factory_; 160 base::WeakPtrFactory<Loader> weak_ptr_factory_;
161 }; 161 };
162 162
163 // A loader for local files. 163 // A loader for local files.
164 class DynamicApplicationLoader::LocalLoader : public Loader { 164 class DynamicApplicationLoader::LocalLoader : public Loader {
165 public: 165 public:
166 LocalLoader(const GURL& url, 166 LocalLoader(const GURL& url,
167 MimeTypeToURLMap* mime_type_to_url, 167 MimeTypeToURLMap* mime_type_to_url,
168 Context* context, 168 Context* context,
169 DynamicServiceRunnerFactory* runner_factory, 169 DynamicServiceRunnerFactory* runner_factory,
170 InterfaceRequest<Application> application_request, 170 InterfaceRequest<Application> application_request,
171 ApplicationLoader::LoadCallback load_callback, 171 LoadCallback load_callback,
172 const LoaderCompleteCallback& loader_complete_callback) 172 const LoaderCompleteCallback& loader_complete_callback)
173 : Loader(DynamicServiceRunner::DontDeleteAppPath, 173 : Loader(DynamicServiceRunner::DontDeleteAppPath,
174 mime_type_to_url, 174 mime_type_to_url,
175 context, 175 context,
176 runner_factory, 176 runner_factory,
177 application_request.Pass(), 177 application_request.Pass(),
178 load_callback, 178 load_callback,
179 loader_complete_callback), 179 loader_complete_callback),
180 url_(url), 180 url_(url),
181 path_(UrlToFile(url)) { 181 path_(UrlToFile(url)) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 250
251 // A loader for network files. 251 // A loader for network files.
252 class DynamicApplicationLoader::NetworkLoader : public Loader { 252 class DynamicApplicationLoader::NetworkLoader : public Loader {
253 public: 253 public:
254 NetworkLoader(const GURL& url, 254 NetworkLoader(const GURL& url,
255 NetworkService* network_service, 255 NetworkService* network_service,
256 MimeTypeToURLMap* mime_type_to_url, 256 MimeTypeToURLMap* mime_type_to_url,
257 Context* context, 257 Context* context,
258 DynamicServiceRunnerFactory* runner_factory, 258 DynamicServiceRunnerFactory* runner_factory,
259 InterfaceRequest<Application> application_request, 259 InterfaceRequest<Application> application_request,
260 ApplicationLoader::LoadCallback load_callback, 260 LoadCallback load_callback,
261 const LoaderCompleteCallback& loader_complete_callback) 261 const LoaderCompleteCallback& loader_complete_callback)
262 : Loader(DynamicServiceRunner::DeleteAppPath, 262 : Loader(DynamicServiceRunner::DeleteAppPath,
263 mime_type_to_url, 263 mime_type_to_url,
264 context, 264 context,
265 runner_factory, 265 runner_factory,
266 application_request.Pass(), 266 application_request.Pass(),
267 load_callback, 267 load_callback,
268 loader_complete_callback), 268 loader_complete_callback),
269 url_(url), 269 url_(url),
270 weak_ptr_factory_(this) { 270 weak_ptr_factory_(this) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 463
464 void DynamicApplicationLoader::RegisterContentHandler( 464 void DynamicApplicationLoader::RegisterContentHandler(
465 const std::string& mime_type, 465 const std::string& mime_type,
466 const GURL& content_handler_url) { 466 const GURL& content_handler_url) {
467 DCHECK(content_handler_url.is_valid()) 467 DCHECK(content_handler_url.is_valid())
468 << "Content handler URL is invalid for mime type " << mime_type; 468 << "Content handler URL is invalid for mime type " << mime_type;
469 mime_type_to_url_[mime_type] = content_handler_url; 469 mime_type_to_url_[mime_type] = content_handler_url;
470 } 470 }
471 471
472 void DynamicApplicationLoader::Load( 472 void DynamicApplicationLoader::Load(
473 ApplicationManager* manager,
474 const GURL& url, 473 const GURL& url,
475 InterfaceRequest<Application> application_request, 474 InterfaceRequest<Application> application_request,
476 LoadCallback load_callback) { 475 LoadCallback load_callback) {
477 if (url.SchemeIsFile()) { 476 if (url.SchemeIsFile()) {
478 loaders_.push_back(new LocalLoader( 477 loaders_.push_back(new LocalLoader(
479 url, &mime_type_to_url_, context_, runner_factory_.get(), 478 url, &mime_type_to_url_, context_, runner_factory_.get(),
480 application_request.Pass(), load_callback, loader_complete_callback_)); 479 application_request.Pass(), load_callback, loader_complete_callback_));
481 return; 480 return;
482 } 481 }
483 482
484 if (!network_service_) { 483 if (!network_service_) {
485 context_->application_manager()->ConnectToService( 484 context_->application_manager()->ConnectToService(
486 GURL("mojo:network_service"), &network_service_); 485 GURL("mojo:network_service"), &network_service_);
487 } 486 }
488 487
489 loaders_.push_back(new NetworkLoader( 488 loaders_.push_back(new NetworkLoader(
490 url, network_service_.get(), &mime_type_to_url_, context_, 489 url, network_service_.get(), &mime_type_to_url_, context_,
491 runner_factory_.get(), application_request.Pass(), load_callback, 490 runner_factory_.get(), application_request.Pass(), load_callback,
492 loader_complete_callback_)); 491 loader_complete_callback_));
493 } 492 }
494 493
495 void DynamicApplicationLoader::OnApplicationError(ApplicationManager* manager,
496 const GURL& url) {
497 // TODO(darin): What should we do about service errors? This implies that
498 // the app closed its handle to the service manager. Maybe we don't care?
499 }
500
501 void DynamicApplicationLoader::LoaderComplete(Loader* loader) { 494 void DynamicApplicationLoader::LoaderComplete(Loader* loader) {
502 loaders_.erase(std::find(loaders_.begin(), loaders_.end(), loader)); 495 loaders_.erase(std::find(loaders_.begin(), loaders_.end(), loader));
503 } 496 }
504 497
505 } // namespace shell 498 } // namespace shell
506 } // namespace mojo 499 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698