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/callback.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.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" |
11 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 18 #include "content/common/resource_request.h" |
| 19 |
| 20 namespace net { |
| 21 class IOBuffer; |
| 22 } // namespace net |
12 | 23 |
13 namespace content { | 24 namespace content { |
14 | 25 |
15 class AppCacheHost; | 26 class AppCacheHost; |
16 class AppCacheRequest; | 27 class AppCacheRequest; |
17 class AppCacheStorage; | 28 class AppCacheStorage; |
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 { |
22 public: | 34 public: |
| 35 using BufferReadCallback = base::Callback<void(void)>; |
| 36 |
| 37 class Delegate { |
| 38 public: |
| 39 // Generally called when we don't have an AppCache response for the |
| 40 // ongoing request. |
| 41 virtual void SendNetworkResponse() {} |
| 42 |
| 43 // Called when we want to send out an error response to the client. |
| 44 virtual void SendErrorResponse() {} |
| 45 |
| 46 // Called when we have a valid response from the AppCache. |
| 47 virtual void HandleAppCacheResponseStart( |
| 48 AppCacheResponseInfo* response_info) {} |
| 49 |
| 50 // Called when we have valid AppCache data to send to the client. |
| 51 virtual void HandleAppCacheData( |
| 52 net::IOBuffer* buffer, |
| 53 int buffer_size, |
| 54 AppCacheURLLoaderJob::BufferReadCallback callback) {} |
| 55 |
| 56 // Called when we have no more AppCache data to send to the client. |
| 57 virtual void HandleAppCacheDataCompleted() {} |
| 58 }; |
| 59 |
23 ~AppCacheURLLoaderJob() override; | 60 ~AppCacheURLLoaderJob() override; |
24 | 61 |
25 // AppCacheJob overrides. | 62 // AppCacheJob overrides. |
26 void Kill() override; | 63 void Kill() override; |
27 bool IsStarted() const override; | 64 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, | 65 void DeliverAppCachedResponse(const GURL& manifest_url, |
34 int64_t cache_id, | 66 int64_t cache_id, |
35 const AppCacheEntry& entry, | 67 const AppCacheEntry& entry, |
36 bool is_fallback) override; | 68 bool is_fallback) override; |
37 void DeliverNetworkResponse() override; | 69 void DeliverNetworkResponse() override; |
38 void DeliverErrorResponse() override; | 70 void DeliverErrorResponse() override; |
39 const GURL& GetURL() const override; | 71 const GURL& GetURL() const override; |
| 72 AppCacheURLLoaderJob* AsURLLoaderJob() override; |
| 73 |
| 74 void set_delegate(Delegate* delegate) { delegate_ = delegate; } |
40 | 75 |
41 protected: | 76 protected: |
42 // AppCacheJob::Create() creates this instance. | 77 // AppCacheJob::Create() creates this instance. |
43 friend class AppCacheJob; | 78 friend class AppCacheJob; |
44 | 79 |
45 AppCacheURLLoaderJob(); | 80 AppCacheURLLoaderJob(const ResourceRequest& request, |
| 81 AppCacheStorage* storage); |
46 | 82 |
47 GURL url_; | 83 // AppCacheStorage::Delegate methods |
| 84 void OnResponseInfoLoaded(AppCacheResponseInfo* response_info, |
| 85 int64_t response_id) override; |
| 86 void OnCacheLoaded(AppCache* cache, int64_t cache_id) override; |
| 87 |
| 88 // AppCacheResponseReader completion callback |
| 89 void OnReadComplete(int result); |
| 90 |
| 91 void OnBufferRead(); |
| 92 |
| 93 // The current request. |
| 94 ResourceRequest request_; |
| 95 |
| 96 // The delegate is invoked when we have data to report from the AppCache, |
| 97 // or if the request is to be sent directly to the n/w, etc. |
| 98 Delegate* delegate_; |
| 99 |
| 100 AppCacheStorage* storage_; |
| 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<net::IOBuffer> buffer_; |
48 | 124 |
49 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderJob); | 125 DISALLOW_COPY_AND_ASSIGN(AppCacheURLLoaderJob); |
50 }; | 126 }; |
51 | 127 |
52 } // namespace content | 128 } // namespace content |
53 | 129 |
54 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ | 130 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_URL_LOADER_JOB_H_ |
OLD | NEW |