Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef MOJO_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_ | 5 #ifndef MOJO_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_ |
| 6 #define MOJO_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_ | 6 #define MOJO_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_ |
| 7 | 7 |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "mojo/fetcher/url_resolver.h" | 9 #include "mojo/fetcher/url_resolver.h" |
| 10 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | 10 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
| 11 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h" | 11 #include "mojo/services/network/public/interfaces/url_loader_factory.mojom.h" |
| 12 #include "mojo/shell/package_manager.h" | 12 #include "mojo/shell/package_manager.h" |
| 13 | 13 |
| 14 namespace base { | |
| 15 class TaskRunner; | |
| 16 } | |
| 17 | |
| 14 namespace mojo { | 18 namespace mojo { |
| 19 class ContentHandler; | |
| 15 namespace shell { | 20 namespace shell { |
| 16 class Fetcher; | 21 class Fetcher; |
| 22 class Identity; | |
| 17 } | 23 } |
| 18 namespace package_manager { | 24 namespace package_manager { |
| 25 class ContentHandlerConnection; | |
| 19 | 26 |
| 20 // This is the default implementation of shell::PackageManager. It loads | 27 // This is the default implementation of shell::PackageManager. It loads |
| 21 // http/s urls off the network as well as providing special handling for mojo: | 28 // http/s urls off the network as well as providing special handling for mojo: |
| 22 // and about: urls. | 29 // and about: urls. |
| 23 class PackageManagerImpl : public shell::PackageManager { | 30 class PackageManagerImpl : public shell::PackageManager { |
| 24 public: | 31 public: |
| 25 // mojo: urls are only supported if |shell_file_root| is non-empty. | 32 // mojo: urls are only supported if |shell_file_root| is non-empty. |
| 26 explicit PackageManagerImpl(const base::FilePath& shell_file_root); | 33 PackageManagerImpl(const base::FilePath& shell_file_root, |
| 34 base::TaskRunner* task_runner); | |
|
yzshen1
2015/09/23 16:53:46
Please comment on what this task_runner is used fo
| |
| 27 ~PackageManagerImpl() override; | 35 ~PackageManagerImpl() override; |
| 28 | 36 |
| 29 // Register a content handler to handle content of |mime_type|. | 37 // Register a content handler to handle content of |mime_type|. |
| 30 void RegisterContentHandler(const std::string& mime_type, | 38 void RegisterContentHandler(const std::string& mime_type, |
| 31 const GURL& content_handler_url); | 39 const GURL& content_handler_url); |
| 32 | 40 |
| 33 // Registers a package alias. When attempting to load |alias|, it will | 41 // Registers a package alias. When attempting to load |alias|, it will |
| 34 // instead redirect to |content_handler_package|, which is a content handler | 42 // instead redirect to |content_handler_package|, which is a content handler |
| 35 // which will be passed the |alias| as the URLResponse::url. Different values | 43 // which will be passed the |alias| as the URLResponse::url. Different values |
| 36 // of |alias| with the same |qualifier| that are in the same | 44 // of |alias| with the same |qualifier| that are in the same |
| 37 // |content_handler_package| will run in the same process in multi-process | 45 // |content_handler_package| will run in the same process in multi-process |
| 38 // mode. | 46 // mode. |
| 39 void RegisterApplicationPackageAlias( | 47 void RegisterApplicationPackageAlias( |
| 40 const GURL& alias, | 48 const GURL& alias, |
| 41 const GURL& content_handler_package, | 49 const GURL& content_handler_package, |
| 42 const std::string& qualifier); | 50 const std::string& qualifier); |
| 43 | 51 |
| 44 private: | 52 private: |
| 45 using ApplicationPackagedAlias = std::map<GURL, std::pair<GURL, std::string>>; | 53 using ApplicationPackagedAlias = std::map<GURL, std::pair<GURL, std::string>>; |
| 46 using MimeTypeToURLMap = std::map<std::string, GURL>; | 54 using MimeTypeToURLMap = std::map<std::string, GURL>; |
| 55 using IdentityToContentHandlerMap = | |
| 56 std::map<shell::Identity, ContentHandlerConnection*>; | |
| 47 | 57 |
| 48 // Overridden from shell::PackageManager: | 58 // Overridden from shell::PackageManager: |
| 49 void SetApplicationManager(shell::ApplicationManager* manager) override; | 59 void SetApplicationManager(shell::ApplicationManager* manager) override; |
| 50 void FetchRequest( | 60 void FetchRequest( |
| 51 URLRequestPtr request, | 61 URLRequestPtr request, |
| 52 const shell::Fetcher::FetchCallback& loader_callback) override; | 62 const shell::Fetcher::FetchCallback& loader_callback) override; |
| 53 bool HandleWithContentHandler(shell::Fetcher* fetcher, | 63 uint32_t HandleWithContentHandler( |
| 54 const GURL& url, | 64 shell::Fetcher* fetcher, |
| 55 base::TaskRunner* task_runner, | 65 const shell::Identity& source, |
| 56 URLResponsePtr* new_response, | 66 const GURL& target_url, |
| 57 GURL* content_handler_url, | 67 const shell::CapabilityFilter& target_filter, |
| 58 std::string* qualifier) override; | 68 InterfaceRequest<Application>* application_request) override; |
| 59 | 69 |
| 60 GURL ResolveURL(const GURL& url); | 70 GURL ResolveURL(const GURL& url); |
| 71 bool ShouldHandleWithContentHandler( | |
| 72 shell::Fetcher* fetcher, | |
| 73 const GURL& target_url, | |
| 74 const shell::CapabilityFilter& target_filter, | |
| 75 shell::Identity* content_handler_identity, | |
| 76 URLResponsePtr* response) const; | |
| 77 | |
| 78 // Returns a running ContentHandler for |content_handler_identity|, if there | |
| 79 // is not one running one is started for |source_identity|. | |
| 80 ContentHandlerConnection* GetContentHandler( | |
| 81 const shell::Identity& content_handler_identity, | |
| 82 const shell::Identity& source_identity); | |
| 83 | |
| 84 void OnContentHandlerConnectionClosed( | |
| 85 ContentHandlerConnection* content_handler); | |
| 61 | 86 |
| 62 shell::ApplicationManager* application_manager_; | 87 shell::ApplicationManager* application_manager_; |
| 63 scoped_ptr<fetcher::URLResolver> url_resolver_; | 88 scoped_ptr<fetcher::URLResolver> url_resolver_; |
| 64 const bool disable_cache_; | 89 const bool disable_cache_; |
| 65 NetworkServicePtr network_service_; | 90 NetworkServicePtr network_service_; |
| 66 URLLoaderFactoryPtr url_loader_factory_; | 91 URLLoaderFactoryPtr url_loader_factory_; |
| 67 ApplicationPackagedAlias application_package_alias_; | 92 ApplicationPackagedAlias application_package_alias_; |
| 68 MimeTypeToURLMap mime_type_to_url_; | 93 MimeTypeToURLMap mime_type_to_url_; |
| 94 IdentityToContentHandlerMap identity_to_content_handler_; | |
| 95 // Counter used to assign ids to content handlers. | |
| 96 uint32_t content_handler_id_counter_; | |
| 97 base::TaskRunner* task_runner_; | |
| 69 | 98 |
| 70 DISALLOW_COPY_AND_ASSIGN(PackageManagerImpl); | 99 DISALLOW_COPY_AND_ASSIGN(PackageManagerImpl); |
| 71 }; | 100 }; |
| 72 | 101 |
| 73 } // namespace package_manager | 102 } // namespace package_manager |
| 74 } // namespace mojo | 103 } // namespace mojo |
| 75 | 104 |
| 76 #endif // MOJO_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_ | 105 #endif // MOJO_PACKAGE_MANAGER_PACKAGE_MANAGER_IMPL_H_ |
| OLD | NEW |