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" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 public: | 21 public: |
22 NetworkFetcher(bool disable_cache, | 22 NetworkFetcher(bool disable_cache, |
23 const GURL& url, | 23 const GURL& url, |
24 mojo::URLResponseDiskCache* url_response_disk_cache, | 24 mojo::URLResponseDiskCache* url_response_disk_cache, |
25 mojo::NetworkService* network_service, | 25 mojo::NetworkService* network_service, |
26 const FetchCallback& loader_callback); | 26 const FetchCallback& loader_callback); |
27 | 27 |
28 ~NetworkFetcher() override; | 28 ~NetworkFetcher() override; |
29 | 29 |
30 private: | 30 private: |
31 // TODO(hansmuller): Revisit this when a real peek operation is available. | |
32 static const MojoDeadline kPeekTimeout = MOJO_DEADLINE_INDEFINITE; | |
33 | |
34 // The network fetcher will first try to request an application from the | |
35 // network. If that request fails, it will then try to request the application | |
36 // from the cache. | |
37 enum RequestType { | |
38 FROM_NETWORK, | |
39 FROM_CACHE, | |
40 }; | |
41 | |
42 const GURL& GetURL() const override; | 31 const GURL& GetURL() const override; |
43 GURL GetRedirectURL() const override; | 32 GURL GetRedirectURL() const override; |
44 | 33 |
45 mojo::URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, | 34 mojo::URLResponsePtr AsURLResponse(base::TaskRunner* task_runner, |
46 uint32_t skip) override; | 35 uint32_t skip) override; |
47 | 36 |
48 static void RecordCacheToURLMapping(const base::FilePath& path, | |
49 const GURL& url); | |
50 | |
51 void OnFileRetrievedFromCache( | |
52 base::Callback<void(const base::FilePath&, bool)> callback, | |
53 mojo::Array<uint8_t> path_as_array, | |
54 mojo::Array<uint8_t> cache_dir); | |
55 | |
56 void AsPath( | 37 void AsPath( |
57 base::TaskRunner* task_runner, | 38 base::TaskRunner* task_runner, |
58 base::Callback<void(const base::FilePath&, bool)> callback) override; | 39 base::Callback<void(const base::FilePath&, bool)> callback) override; |
59 | 40 |
60 std::string MimeType() override; | 41 std::string MimeType() override; |
61 | 42 |
62 bool HasMojoMagic() override; | 43 bool HasMojoMagic() override; |
63 | 44 |
64 bool PeekFirstLine(std::string* line) override; | 45 bool PeekFirstLine(std::string* line) override; |
65 | 46 |
66 void StartNetworkRequest(RequestType request_type); | 47 // Returns whether the content can be loaded directly from cache. Local hosts |
48 // are not loaded from cache to allow effective development. | |
49 bool CanLoadDirectlyFromCache(); | |
67 | 50 |
68 void OnLoadComplete(RequestType request_type, mojo::URLResponsePtr response); | 51 void LoadFromCache(bool sheduleUpdate); |
ppi
2015/09/15 15:21:23
We probably want "shedule_update" (I see that I go
qsr
2015/09/16 11:46:39
Done.
| |
52 | |
53 void OnCachedResponseReceived(bool sheduleUpdate, | |
54 mojo::URLResponsePtr response, | |
55 mojo::Array<uint8_t> path_as_array, | |
56 mojo::Array<uint8_t> cache_dir); | |
57 | |
58 void StartNetworkRequest(); | |
59 | |
60 void OnLoadComplete(mojo::URLResponsePtr response); | |
61 | |
62 void OnFileSavedToCache(mojo::Array<uint8_t> path_as_array, | |
63 mojo::Array<uint8_t> cache_dir); | |
64 | |
65 static void RecordCacheToURLMapping(const base::FilePath& path, | |
66 const GURL& url); | |
69 | 67 |
70 const bool disable_cache_; | 68 const bool disable_cache_; |
71 const GURL url_; | 69 const GURL url_; |
72 mojo::URLResponseDiskCache* url_response_disk_cache_; | 70 mojo::URLResponseDiskCache* url_response_disk_cache_; |
73 mojo::NetworkService* network_service_; | 71 mojo::NetworkService* network_service_; |
74 mojo::URLLoaderPtr url_loader_; | 72 mojo::URLLoaderPtr url_loader_; |
75 mojo::URLResponsePtr response_; | 73 mojo::URLResponsePtr response_; |
76 base::FilePath path_; | 74 base::FilePath path_; |
77 base::WeakPtrFactory<NetworkFetcher> weak_ptr_factory_; | 75 base::WeakPtrFactory<NetworkFetcher> weak_ptr_factory_; |
78 | 76 |
79 DISALLOW_COPY_AND_ASSIGN(NetworkFetcher); | 77 DISALLOW_COPY_AND_ASSIGN(NetworkFetcher); |
80 }; | 78 }; |
81 | 79 |
82 } // namespace shell | 80 } // namespace shell |
83 | 81 |
84 #endif // SHELL_APPLICATION_MANAGER_NETWORK_FETCHER_H_ | 82 #endif // SHELL_APPLICATION_MANAGER_NETWORK_FETCHER_H_ |
OLD | NEW |