| 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/url_response_disk_cache/public/interfaces/url_response_d
isk_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::url_response_disk_cache::URLResponseDiskCache* |
| 29 url_response_disk_cache, |
| 27 const FetchCallback& loader_callback); | 30 const FetchCallback& loader_callback); |
| 28 | 31 |
| 29 ~NetworkFetcher() override; | 32 ~NetworkFetcher() override; |
| 30 | 33 |
| 31 private: | 34 private: |
| 32 // TODO(hansmuller): Revisit this when a real peek operation is available. | 35 // TODO(hansmuller): Revisit this when a real peek operation is available. |
| 33 static const MojoDeadline kPeekTimeout = MOJO_DEADLINE_INDEFINITE; | 36 static const MojoDeadline kPeekTimeout = MOJO_DEADLINE_INDEFINITE; |
| 34 | 37 |
| 35 const GURL& GetURL() const override; | 38 const GURL& GetURL() const override; |
| 36 GURL GetRedirectURL() const override; | 39 GURL GetRedirectURL() const override; |
| 37 | 40 |
| 38 mojo::URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, | 41 mojo::URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, |
| 39 uint32_t skip) override; | 42 uint32_t skip) override; |
| 40 | 43 |
| 41 static void RecordCacheToURLMapping(const base::FilePath& path, | 44 static void RecordCacheToURLMapping(const base::FilePath& path, |
| 42 const GURL& url); | 45 const GURL& url); |
| 43 | 46 |
| 44 // AppIds should be be both predictable and unique, but any hash would work. | 47 // AppIds should be be both predictable and unique, but any hash would work. |
| 45 // Currently we use sha256 from crypto/secure_hash.h | 48 // Currently we use sha256 from crypto/secure_hash.h |
| 46 static bool ComputeAppId(const base::FilePath& path, | 49 static bool ComputeAppId(const base::FilePath& path, |
| 47 std::string* digest_string); | 50 std::string* digest_string); |
| 48 | 51 |
| 49 static bool RenameToAppId(const GURL& url, | 52 static bool RenameToAppId(const GURL& url, |
| 50 const base::FilePath& old_path, | 53 const base::FilePath& old_path, |
| 51 base::FilePath* new_path); | 54 base::FilePath* new_path); |
| 52 | 55 |
| 53 void CopyCompleted(base::Callback<void(const base::FilePath&, bool)> callback, | 56 void OnFileRetrievedFromCache( |
| 54 bool success); | 57 base::Callback<void(const base::FilePath&, bool)> callback, |
| 58 mojo::Array<uint8_t> path_as_array, |
| 59 mojo::Array<uint8_t> cache_dir); |
| 55 | 60 |
| 56 void AsPath( | 61 void AsPath( |
| 57 base::TaskRunner* task_runner, | 62 base::TaskRunner* task_runner, |
| 58 base::Callback<void(const base::FilePath&, bool)> callback) override; | 63 base::Callback<void(const base::FilePath&, bool)> callback) override; |
| 59 | 64 |
| 60 std::string MimeType() override; | 65 std::string MimeType() override; |
| 61 | 66 |
| 62 bool HasMojoMagic() override; | 67 bool HasMojoMagic() override; |
| 63 | 68 |
| 64 bool PeekFirstLine(std::string* line) override; | 69 bool PeekFirstLine(std::string* line) override; |
| 65 | 70 |
| 66 void StartNetworkRequest(const GURL& url, | 71 void StartNetworkRequest(const GURL& url, |
| 67 mojo::NetworkService* network_service); | 72 mojo::NetworkService* network_service); |
| 68 | 73 |
| 69 void OnLoadComplete(mojo::URLResponsePtr response); | 74 void OnLoadComplete(mojo::URLResponsePtr response); |
| 70 | 75 |
| 71 bool disable_cache_; | 76 bool disable_cache_; |
| 72 const GURL url_; | 77 const GURL url_; |
| 78 mojo::url_response_disk_cache::URLResponseDiskCache* url_response_disk_cache_; |
| 73 mojo::URLLoaderPtr url_loader_; | 79 mojo::URLLoaderPtr url_loader_; |
| 74 mojo::URLResponsePtr response_; | 80 mojo::URLResponsePtr response_; |
| 75 base::FilePath path_; | 81 base::FilePath path_; |
| 76 base::WeakPtrFactory<NetworkFetcher> weak_ptr_factory_; | 82 base::WeakPtrFactory<NetworkFetcher> weak_ptr_factory_; |
| 77 | 83 |
| 78 DISALLOW_COPY_AND_ASSIGN(NetworkFetcher); | 84 DISALLOW_COPY_AND_ASSIGN(NetworkFetcher); |
| 79 }; | 85 }; |
| 80 | 86 |
| 81 } // namespace shell | 87 } // namespace shell |
| 82 | 88 |
| 83 #endif // SHELL_APPLICATION_MANAGER_NETWORK_FETCHER_H_ | 89 #endif // SHELL_APPLICATION_MANAGER_NETWORK_FETCHER_H_ |
| OLD | NEW |