Chromium Code Reviews| 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" | |
| 9 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "base/time/time.h" | |
| 12 #include "content/browser/appcache/appcache_entry.h" | |
| 10 #include "content/browser/appcache/appcache_job.h" | 13 #include "content/browser/appcache/appcache_job.h" |
| 14 #include "content/browser/appcache/appcache_response.h" | |
| 15 #include "content/browser/appcache/appcache_storage.h" | |
| 16 #include "content/browser/loader/url_loader_request_handler.h" | |
| 11 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 18 #include "content/common/resource_request.h" | |
| 19 #include "content/common/url_loader.mojom.h" | |
| 20 #include "mojo/public/cpp/bindings/binding.h" | |
| 21 #include "mojo/public/cpp/system/data_pipe.h" | |
| 12 | 22 |
| 13 namespace content { | 23 namespace content { |
| 14 | 24 |
| 15 class AppCacheHost; | |
| 16 class AppCacheRequest; | 25 class AppCacheRequest; |
| 17 class AppCacheStorage; | 26 class URLLoaderFactoryGetter; |
| 27 class NetToMojoIOBuffer; | |
| 28 class NetToMojoPendingBuffer; | |
| 18 | 29 |
| 19 // AppCacheJob wrapper for a mojom::URLLoader implementation which returns | 30 // AppCacheJob wrapper for a mojom::URLLoader implementation which returns |
| 20 // responses stored in the AppCache. | 31 // responses stored in the AppCache. |
| 21 class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob { | 32 class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob, |
| 33 public AppCacheStorage::Delegate, | |
| 34 public mojom::URLLoader { | |
| 22 public: | 35 public: |
| 23 ~AppCacheURLLoaderJob() override; | 36 ~AppCacheURLLoaderJob() override; |
| 24 | 37 |
| 38 // Sets up the bindings. | |
| 39 void Start(int routing_id, | |
| 40 int request_id, | |
|
michaeln
2017/06/09 01:48:30
the id's aren't needed yet
ananta
2017/06/09 04:48:19
Removed
| |
| 41 mojom::URLLoaderRequest request, | |
| 42 mojom::URLLoaderClientPtr client); | |
| 43 | |
| 25 // AppCacheJob overrides. | 44 // AppCacheJob overrides. |
| 26 void Kill() override; | 45 void Kill() override; |
| 27 bool IsStarted() const override; | 46 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, | 47 void DeliverAppCachedResponse(const GURL& manifest_url, |
| 34 int64_t cache_id, | 48 int64_t cache_id, |
| 35 const AppCacheEntry& entry, | 49 const AppCacheEntry& entry, |
| 36 bool is_fallback) override; | 50 bool is_fallback) override; |
| 37 void DeliverNetworkResponse() override; | 51 void DeliverNetworkResponse() override; |
| 38 void DeliverErrorResponse() override; | 52 void DeliverErrorResponse() override; |
| 39 const GURL& GetURL() const override; | 53 const GURL& GetURL() const override; |
| 54 AppCacheURLLoaderJob* AsURLLoaderJob() override; | |
| 55 | |
| 56 // mojom::URLLoader implementation: | |
| 57 void FollowRedirect() override; | |
| 58 void SetPriority(net::RequestPriority priority, | |
| 59 int32_t intra_priority_value) override; | |
| 60 | |
| 61 void SetURLLoaderFactoryGetter( | |
| 62 URLLoaderFactoryGetter* url_loader_factory_getter); | |
| 63 | |
| 64 void set_loader_callback(LoaderCallback callback) { | |
| 65 loader_callback_ = std::move(callback); | |
| 66 } | |
| 40 | 67 |
| 41 protected: | 68 protected: |
| 42 // AppCacheJob::Create() creates this instance. | 69 // AppCacheJob::Create() creates this instance. |
| 43 friend class AppCacheJob; | 70 friend class AppCacheJob; |
| 44 | 71 |
| 45 AppCacheURLLoaderJob(); | 72 AppCacheURLLoaderJob(const ResourceRequest& request, |
| 73 AppCacheStorage* storage); | |
| 46 | 74 |
| 47 GURL url_; | 75 // AppCacheStorage::Delegate methods |
| 76 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info, | |
| 77 int64_t response_id) override; | |
| 78 void OnCacheLoaded(AppCache* cache, int64_t cache_id) override; | |
| 79 | |
| 80 // AppCacheResponseReader completion callback | |
| 81 void OnReadComplete(int result); | |
| 82 | |
| 83 void OnConnectionError(); | |
| 84 | |
| 85 // Helper to send the AppCacheResponseInfo to the URLLoaderClient. | |
| 86 void SendResponseInfo(); | |
| 87 | |
| 88 // Helper function to read the data from the AppCache. | |
| 89 void ReadMore(); | |
| 90 | |
| 91 // Callback invoked when the data pipe can be written to. | |
| 92 void OnResponseBodyStreamReady(MojoResult result); | |
| 93 | |
| 94 // Notifies the client about request completion. | |
| 95 void NotifyCompleted(int error_code); | |
| 96 | |
| 97 // The current request. | |
| 98 ResourceRequest request_; | |
| 99 | |
| 100 AppCacheStorage* storage_; | |
|
michaeln
2017/06/09 01:48:30
this rawptr could become dangling, we need to be c
ananta
2017/06/09 04:48:19
Set it to nullptr in DeliverErrorResponse() like t
| |
| 101 | |
| 102 // The response details. | |
| 103 scoped_refptr<AppCacheResponseInfo> info_; | |
| 104 | |
| 105 // Used to read the cache. | |
| 106 std::unique_ptr<AppCacheResponseReader> reader_; | |
| 107 | |
| 108 // Time when the request started. | |
| 109 base::TimeTicks start_time_tick_; | |
| 110 | |
| 111 // The AppCache manifest URL. | |
| 112 GURL manifest_url_; | |
| 113 | |
| 114 // The AppCache id. | |
| 115 int64_t cache_id_; | |
| 116 | |
| 117 AppCacheEntry entry_; | |
| 118 | |
| 119 // Set to true if we are loading fallback content. | |
| 120 bool is_fallback_; | |
| 121 | |
| 122 // The buffer used to read AppCache data. | |
| 123 scoped_refptr<NetToMojoIOBuffer> buffer_; | |
| 124 | |
| 125 // The data pipe used to transfer AppCache data to the client. | |
| 126 mojo::DataPipe data_pipe_; | |
| 127 | |
| 128 // Binds the URLLoaderClient with us. | |
| 129 mojo::Binding<mojom::URLLoader> binding_; | |
| 130 | |
| 131 // The URLLoaderClient pointer. We call this interface with notifications | |
| 132 // about the URL load | |
| 133 mojom::URLLoaderClientPtr client_info_; | |
| 134 | |
| 135 // URLLoader proxy for the network service. | |
| 136 mojom::URLLoaderAssociatedPtr url_loader_network_; | |
|
michaeln
2017/06/09 01:48:30
since we don't need this yet, i'd vote to remove i
ananta
2017/06/09 04:48:19
Done.
| |
| 137 | |
| 138 // Routing id of the request. This is 0 for navigation requests. For | |
| 139 // subresource requests it is non zero. | |
| 140 int routing_id_; | |
|
michaeln
2017/06/09 01:48:30
ditto
ananta
2017/06/09 04:48:19
Done.
| |
| 141 | |
| 142 // Request id. | |
| 143 int request_id_; | |
| 144 | |
| 145 // Getter for the network service URL loader. | |
| 146 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter_; | |
|
michaeln
2017/06/09 01:48:30
ditto
ananta
2017/06/09 04:48:19
Done.
| |
| 147 | |
| 148 // mojo data pipe entities. | |
| 149 mojo::ScopedDataPipeProducerHandle response_body_stream_; | |
| 150 | |
| 151 scoped_refptr<NetToMojoPendingBuffer> pending_write_; | |
| 152 | |
| 153 mojo::SimpleWatcher writable_handle_watcher_; | |
| 154 | |
| 155 // The Callback to be invoked in the network service land to indicate if | |
| 156 // the request can be serviced via the AppCache. | |
| 157 LoaderCallback loader_callback_; | |
| 48 | 158 |
| 49 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderJob); | 159 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderJob); |
| 50 }; | 160 }; |
| 51 | 161 |
| 52 } // namespace content | 162 } // namespace content |
| 53 | 163 |
| 54 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ | 164 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ |
| OLD | NEW |