15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 56e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#ifndef MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_ 66e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#define MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_ 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <map> 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/callback.h" 11effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "base/macros.h" 121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/memory/scoped_vector.h" 135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/memory/weak_ptr.h" 146e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "mojo/application_manager/application_loader.h" 15effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "mojo/public/cpp/system/core.h" 16f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "mojo/services/public/interfaces/network/network_service.mojom.h" 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "mojo/shell/dynamic_service_runner.h" 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "url/gurl.h" 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace mojo { 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace shell { 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Context; 24a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class DynamicServiceRunnerFactory; 251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass DynamicServiceRunner; 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 276e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// An implementation of ApplicationLoader that retrieves a dynamic library 28effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// containing the implementation of the service and loads/runs it (via a 29effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch// DynamicServiceRunner). 306e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class DynamicApplicationLoader : public ApplicationLoader { 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 326e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) DynamicApplicationLoader( 336e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) Context* context, 346e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) scoped_ptr<DynamicServiceRunnerFactory> runner_factory); 356e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual ~DynamicApplicationLoader(); 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void RegisterContentHandler(const std::string& mime_type, 385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const GURL& content_handler_url); 395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) // ApplicationLoader methods: 416e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) virtual void Load(ApplicationManager* manager, 425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const GURL& url, 435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) scoped_refptr<LoadCallbacks> callbacks) OVERRIDE; 441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci virtual void OnApplicationError(ApplicationManager* manager, 451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci const GURL& url) OVERRIDE; 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci class Loader; 491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci class LocalLoader; 501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci class NetworkLoader; 511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) typedef std::map<std::string, GURL> MimeTypeToURLMap; 531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci typedef base::Callback<void(Loader*)> LoaderCompleteCallback; 545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci void LoaderComplete(Loader* loader); 565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) Context* const context_; 58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) scoped_ptr<DynamicServiceRunnerFactory> runner_factory_; 59f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) NetworkServicePtr network_service_; 605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MimeTypeToURLMap mime_type_to_url_; 611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci ScopedVector<Loader> loaders_; 621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci LoaderCompleteCallback loader_complete_callback_; 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 646e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(DynamicApplicationLoader); 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace shell 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace mojo 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#endif // MOJO_SHELL_DYNAMIC_APPLICATION_LOADER_H_ 71