| 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 SHELL_APPLICATION_MANAGER_NETWORK_FETCHER_H_ | 5 #ifndef SHELL_APPLICATION_MANAGER_NETWORK_FETCHER_H_ |
| 6 #define SHELL_APPLICATION_MANAGER_NETWORK_FETCHER_H_ | 6 #define SHELL_APPLICATION_MANAGER_NETWORK_FETCHER_H_ |
| 7 | 7 |
| 8 #include "shell/application_manager/fetcher.h" | 8 #include "shell/application_manager/fetcher.h" |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | 12 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" |
| 13 #include "mojo/services/service_cache/public/interfaces/service_cache.mojom.h" |
| 13 #include "url/gurl.h" | 14 #include "url/gurl.h" |
| 14 | 15 |
| 15 namespace mojo { | 16 namespace mojo { |
| 16 class NetworkService; | 17 class NetworkService; |
| 17 } // namespace mojo | 18 } // namespace mojo |
| 18 | 19 |
| 19 namespace shell { | 20 namespace shell { |
| 20 | 21 |
| 21 // Implements Fetcher for http[s] files. | 22 // Implements Fetcher for http[s] files. |
| 22 class NetworkFetcher : public Fetcher { | 23 class NetworkFetcher : public Fetcher { |
| 23 public: | 24 public: |
| 24 NetworkFetcher(bool disable_cache, | 25 NetworkFetcher(bool disable_cache, |
| 25 const GURL& url, | 26 const GURL& url, |
| 26 mojo::NetworkService* network_service, | 27 mojo::NetworkService* network_service, |
| 28 mojo::service_cache::ServiceCache* service_cache, |
| 27 const FetchCallback& loader_callback); | 29 const FetchCallback& loader_callback); |
| 28 | 30 |
| 29 ~NetworkFetcher() override; | 31 ~NetworkFetcher() override; |
| 30 | 32 |
| 31 private: | 33 private: |
| 32 // TODO(hansmuller): Revisit this when a real peek operation is available. | 34 // TODO(hansmuller): Revisit this when a real peek operation is available. |
| 33 static const MojoDeadline kPeekTimeout = MOJO_DEADLINE_INDEFINITE; | 35 static const MojoDeadline kPeekTimeout = MOJO_DEADLINE_INDEFINITE; |
| 34 | 36 |
| 35 const GURL& GetURL() const override; | 37 const GURL& GetURL() const override; |
| 36 GURL GetRedirectURL() const override; | 38 GURL GetRedirectURL() const override; |
| 37 | 39 |
| 38 mojo::URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, | 40 mojo::URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, |
| 39 uint32_t skip) override; | 41 uint32_t skip) override; |
| 40 | 42 |
| 41 static void RecordCacheToURLMapping(const base::FilePath& path, | 43 static void RecordCacheToURLMapping(const base::FilePath& path, |
| 42 const GURL& url); | 44 const GURL& url); |
| 43 | 45 |
| 44 // AppIds should be be both predictable and unique, but any hash would work. | 46 // AppIds should be be both predictable and unique, but any hash would work. |
| 45 // Currently we use sha256 from crypto/secure_hash.h | 47 // Currently we use sha256 from crypto/secure_hash.h |
| 46 static bool ComputeAppId(const base::FilePath& path, | 48 static bool ComputeAppId(const base::FilePath& path, |
| 47 std::string* digest_string); | 49 std::string* digest_string); |
| 48 | 50 |
| 49 static bool RenameToAppId(const GURL& url, | 51 static bool RenameToAppId(const GURL& url, |
| 50 const base::FilePath& old_path, | 52 const base::FilePath& old_path, |
| 51 base::FilePath* new_path); | 53 base::FilePath* new_path); |
| 52 | 54 |
| 53 void CopyCompleted(base::Callback<void(const base::FilePath&, bool)> callback, | 55 void CacheFileRetrieved( |
| 54 bool success); | 56 base::Callback<void(const base::FilePath&, bool)> callback, |
| 57 mojo::Array<uint8_t> path_as_array, |
| 58 mojo::Array<uint8_t> cache_dir); |
| 55 | 59 |
| 56 void AsPath( | 60 void AsPath( |
| 57 base::TaskRunner* task_runner, | 61 base::TaskRunner* task_runner, |
| 58 base::Callback<void(const base::FilePath&, bool)> callback) override; | 62 base::Callback<void(const base::FilePath&, bool)> callback) override; |
| 59 | 63 |
| 60 std::string MimeType() override; | 64 std::string MimeType() override; |
| 61 | 65 |
| 62 bool HasMojoMagic() override; | 66 bool HasMojoMagic() override; |
| 63 | 67 |
| 64 bool PeekFirstLine(std::string* line) override; | 68 bool PeekFirstLine(std::string* line) override; |
| 65 | 69 |
| 66 void StartNetworkRequest(const GURL& url, | 70 void StartNetworkRequest(const GURL& url, |
| 67 mojo::NetworkService* network_service); | 71 mojo::NetworkService* network_service); |
| 68 | 72 |
| 69 void OnLoadComplete(mojo::URLResponsePtr response); | 73 void OnLoadComplete(mojo::URLResponsePtr response); |
| 70 | 74 |
| 71 bool disable_cache_; | 75 bool disable_cache_; |
| 72 const GURL url_; | 76 const GURL url_; |
| 77 mojo::service_cache::ServiceCache* service_cache_; |
| 73 mojo::URLLoaderPtr url_loader_; | 78 mojo::URLLoaderPtr url_loader_; |
| 74 mojo::URLResponsePtr response_; | 79 mojo::URLResponsePtr response_; |
| 75 base::FilePath path_; | 80 base::FilePath path_; |
| 76 base::WeakPtrFactory<NetworkFetcher> weak_ptr_factory_; | 81 base::WeakPtrFactory<NetworkFetcher> weak_ptr_factory_; |
| 77 | 82 |
| 78 DISALLOW_COPY_AND_ASSIGN(NetworkFetcher); | 83 DISALLOW_COPY_AND_ASSIGN(NetworkFetcher); |
| 79 }; | 84 }; |
| 80 | 85 |
| 81 } // namespace shell | 86 } // namespace shell |
| 82 | 87 |
| 83 #endif // SHELL_APPLICATION_MANAGER_NETWORK_FETCHER_H_ | 88 #endif // SHELL_APPLICATION_MANAGER_NETWORK_FETCHER_H_ |
| OLD | NEW |