OLD | NEW |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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 CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ |
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ | 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/weak_ptr.h" |
9 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "base/time/time.h" |
| 13 #include "content/browser/appcache/appcache_entry.h" |
10 #include "content/browser/appcache/appcache_job.h" | 14 #include "content/browser/appcache/appcache_job.h" |
| 15 #include "content/browser/appcache/appcache_response.h" |
| 16 #include "content/browser/appcache/appcache_storage.h" |
| 17 #include "content/browser/loader/url_loader_request_handler.h" |
11 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "content/common/resource_request.h" |
| 20 #include "content/common/url_loader.mojom.h" |
| 21 #include "mojo/public/cpp/bindings/binding.h" |
| 22 #include "mojo/public/cpp/system/data_pipe.h" |
12 | 23 |
13 namespace content { | 24 namespace content { |
14 | 25 |
15 class AppCacheHost; | |
16 class AppCacheRequest; | 26 class AppCacheRequest; |
17 class AppCacheStorage; | 27 class NetToMojoPendingBuffer; |
18 | 28 |
19 // AppCacheJob wrapper for a mojom::URLLoader implementation which returns | 29 // AppCacheJob wrapper for a mojom::URLLoader implementation which returns |
20 // responses stored in the AppCache. | 30 // responses stored in the AppCache. |
21 class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob { | 31 class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob, |
| 32 public AppCacheStorage::Delegate, |
| 33 public mojom::URLLoader { |
22 public: | 34 public: |
23 ~AppCacheURLLoaderJob() override; | 35 ~AppCacheURLLoaderJob() override; |
24 | 36 |
| 37 // Sets up the bindings. |
| 38 void Start(mojom::URLLoaderRequest request, mojom::URLLoaderClientPtr client); |
| 39 |
25 // AppCacheJob overrides. | 40 // AppCacheJob overrides. |
26 void Kill() override; | 41 void Kill() override; |
27 bool IsStarted() const override; | 42 bool IsStarted() const override; |
28 bool IsWaiting() const override; | |
29 bool IsDeliveringAppCacheResponse() const override; | |
30 bool IsDeliveringNetworkResponse() const override; | |
31 bool IsDeliveringErrorResponse() const override; | |
32 bool IsCacheEntryNotFound() const override; | |
33 void DeliverAppCachedResponse(const GURL& manifest_url, | 43 void DeliverAppCachedResponse(const GURL& manifest_url, |
34 int64_t cache_id, | 44 int64_t cache_id, |
35 const AppCacheEntry& entry, | 45 const AppCacheEntry& entry, |
36 bool is_fallback) override; | 46 bool is_fallback) override; |
37 void DeliverNetworkResponse() override; | 47 void DeliverNetworkResponse() override; |
38 void DeliverErrorResponse() override; | 48 void DeliverErrorResponse() override; |
39 const GURL& GetURL() const override; | 49 const GURL& GetURL() const override; |
| 50 AppCacheURLLoaderJob* AsURLLoaderJob() override; |
| 51 |
| 52 // mojom::URLLoader implementation: |
| 53 void FollowRedirect() override; |
| 54 void SetPriority(net::RequestPriority priority, |
| 55 int32_t intra_priority_value) override; |
| 56 |
| 57 void set_loader_callback(LoaderCallback callback) { |
| 58 loader_callback_ = std::move(callback); |
| 59 } |
40 | 60 |
41 protected: | 61 protected: |
42 // AppCacheJob::Create() creates this instance. | 62 // AppCacheJob::Create() creates this instance. |
43 friend class AppCacheJob; | 63 friend class AppCacheJob; |
44 | 64 |
45 AppCacheURLLoaderJob(); | 65 AppCacheURLLoaderJob(const ResourceRequest& request, |
| 66 AppCacheStorage* storage); |
46 | 67 |
47 GURL url_; | 68 // AppCacheStorage::Delegate methods |
| 69 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info, |
| 70 int64_t response_id) override; |
| 71 |
| 72 // AppCacheResponseReader completion callback |
| 73 void OnReadComplete(int result); |
| 74 |
| 75 void OnConnectionError(); |
| 76 |
| 77 // Helper to send the AppCacheResponseInfo to the URLLoaderClient. |
| 78 void SendResponseInfo(); |
| 79 |
| 80 // Helper function to read the data from the AppCache. |
| 81 void ReadMore(); |
| 82 |
| 83 // Callback invoked when the data pipe can be written to. |
| 84 void OnResponseBodyStreamReady(MojoResult result); |
| 85 |
| 86 // Notifies the client about request completion. |
| 87 void NotifyCompleted(int error_code); |
| 88 |
| 89 // The current request. |
| 90 ResourceRequest request_; |
| 91 |
| 92 base::WeakPtr<AppCacheStorage> storage_; |
| 93 |
| 94 // The response details. |
| 95 scoped_refptr<AppCacheResponseInfo> info_; |
| 96 |
| 97 // Used to read the cache. |
| 98 std::unique_ptr<AppCacheResponseReader> reader_; |
| 99 |
| 100 // Time when the request started. |
| 101 base::TimeTicks start_time_tick_; |
| 102 |
| 103 // The AppCache manifest URL. |
| 104 GURL manifest_url_; |
| 105 |
| 106 // The AppCache id. |
| 107 int64_t cache_id_; |
| 108 |
| 109 AppCacheEntry entry_; |
| 110 |
| 111 // Set to true if we are loading fallback content. |
| 112 bool is_fallback_; |
| 113 |
| 114 // The data pipe used to transfer AppCache data to the client. |
| 115 mojo::DataPipe data_pipe_; |
| 116 |
| 117 // Binds the URLLoaderClient with us. |
| 118 mojo::Binding<mojom::URLLoader> binding_; |
| 119 |
| 120 // The URLLoaderClient pointer. We call this interface with notifications |
| 121 // about the URL load |
| 122 mojom::URLLoaderClientPtr client_info_; |
| 123 |
| 124 // mojo data pipe entities. |
| 125 mojo::ScopedDataPipeProducerHandle response_body_stream_; |
| 126 |
| 127 scoped_refptr<NetToMojoPendingBuffer> pending_write_; |
| 128 |
| 129 mojo::SimpleWatcher writable_handle_watcher_; |
| 130 |
| 131 // The Callback to be invoked in the network service land to indicate if |
| 132 // the request can be serviced via the AppCache. |
| 133 LoaderCallback loader_callback_; |
48 | 134 |
49 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderJob); | 135 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderJob); |
50 }; | 136 }; |
51 | 137 |
52 } // namespace content | 138 } // namespace content |
53 | 139 |
54 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ | 140 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ |
OLD | NEW |