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