Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: content/browser/appcache/appcache_request_handler.h

Issue 2848493007: Reduce/Remove URLRequest dependencies from AppCacheRequestHandler (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_REQUEST_HANDLER_H_ 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/supports_user_data.h" 15 #include "base/supports_user_data.h"
16 #include "content/browser/appcache/appcache_entry.h" 16 #include "content/browser/appcache/appcache_entry.h"
17 #include "content/browser/appcache/appcache_host.h" 17 #include "content/browser/appcache/appcache_host.h"
18 #include "content/browser/appcache/appcache_service_impl.h" 18 #include "content/browser/appcache/appcache_service_impl.h"
19 #include "content/common/content_export.h" 19 #include "content/common/content_export.h"
20 #include "content/public/common/resource_type.h" 20 #include "content/public/common/resource_type.h"
21 21
22 namespace net { 22 namespace net {
23 class NetworkDelegate; 23 class NetworkDelegate;
24 class URLRequest; 24 class URLRequest;
25 } // namespace net 25 } // namespace net
26 26
27 namespace content { 27 namespace content {
28 class AppCacheRequest;
28 class AppCacheRequestHandlerTest; 29 class AppCacheRequestHandlerTest;
29 class AppCacheURLRequestJob; 30 class AppCacheURLRequestJob;
30 31
31 // An instance is created for each net::URLRequest. The instance survives all 32 // An instance is created for each net::URLRequest. The instance survives all
32 // http transactions involved in the processing of its net::URLRequest, and is 33 // http transactions involved in the processing of its net::URLRequest, and is
33 // given the opportunity to hijack the request along the way. Callers 34 // given the opportunity to hijack the request along the way. Callers
34 // should use AppCacheHost::CreateRequestHandler to manufacture instances 35 // should use AppCacheHost::CreateRequestHandler to manufacture instances
35 // that can retrieve resources for a particular host. 36 // that can retrieve resources for a particular host.
36 class CONTENT_EXPORT AppCacheRequestHandler 37 class CONTENT_EXPORT AppCacheRequestHandler
37 : public base::SupportsUserData::Data, 38 : public base::SupportsUserData::Data,
38 public AppCacheHost::Observer, 39 public AppCacheHost::Observer,
39 public AppCacheServiceImpl::Observer, 40 public AppCacheServiceImpl::Observer,
40 public AppCacheStorage::Delegate { 41 public AppCacheStorage::Delegate {
41 public: 42 public:
42 ~AppCacheRequestHandler() override; 43 ~AppCacheRequestHandler() override;
43 44
44 // These are called on each request intercept opportunity. 45 // These are called on each request intercept opportunity.
45 AppCacheURLRequestJob* MaybeLoadResource( 46 AppCacheURLRequestJob* MaybeLoadResource(
46 net::URLRequest* request,
47 net::NetworkDelegate* network_delegate); 47 net::NetworkDelegate* network_delegate);
48 AppCacheURLRequestJob* MaybeLoadFallbackForRedirect( 48 AppCacheURLRequestJob* MaybeLoadFallbackForRedirect(
49 net::URLRequest* request,
50 net::NetworkDelegate* network_delegate, 49 net::NetworkDelegate* network_delegate,
51 const GURL& location); 50 const GURL& location);
52 AppCacheURLRequestJob* MaybeLoadFallbackForResponse( 51 AppCacheURLRequestJob* MaybeLoadFallbackForResponse(
53 net::URLRequest* request,
54 net::NetworkDelegate* network_delegate); 52 net::NetworkDelegate* network_delegate);
55 53
56 void GetExtraResponseInfo(int64_t* cache_id, GURL* manifest_url); 54 void GetExtraResponseInfo(int64_t* cache_id, GURL* manifest_url);
57 55
58 // Methods to support cross site navigations. 56 // Methods to support cross site navigations.
59 void PrepareForCrossSiteTransfer(int old_process_id); 57 void PrepareForCrossSiteTransfer(int old_process_id);
60 void CompleteCrossSiteTransfer(int new_process_id, int new_host_id); 58 void CompleteCrossSiteTransfer(int new_process_id, int new_host_id);
61 void MaybeCompleteCrossSiteTransferInOldProcess(int old_process_id); 59 void MaybeCompleteCrossSiteTransferInOldProcess(int old_process_id);
62 60
63 // Useful for detecting storage partition mismatches in the context 61 // Useful for detecting storage partition mismatches in the context
64 // of cross site transfer navigations. 62 // of cross site transfer navigations.
65 bool SanityCheckIsSameService(AppCacheService* service) { 63 bool SanityCheckIsSameService(AppCacheService* service) {
66 return !host_ || (host_->service() == service); 64 return !host_ || (host_->service() == service);
67 } 65 }
68 66
69 static bool IsMainResourceType(ResourceType type) { 67 static bool IsMainResourceType(ResourceType type) {
70 return IsResourceTypeFrame(type) || 68 return IsResourceTypeFrame(type) ||
71 type == RESOURCE_TYPE_SHARED_WORKER; 69 type == RESOURCE_TYPE_SHARED_WORKER;
72 } 70 }
73 71
74 private: 72 private:
75 friend class AppCacheHost; 73 friend class AppCacheHost;
76 74
77 // Callers should use AppCacheHost::CreateRequestHandler. 75 // Callers should use AppCacheHost::CreateRequestHandler.
78 AppCacheRequestHandler(AppCacheHost* host, ResourceType resource_type, 76 AppCacheRequestHandler(AppCacheHost* host,
79 bool should_reset_appcache); 77 ResourceType resource_type,
78 bool should_reset_appcache,
79 AppCacheRequest* request);
80 80
81 // AppCacheHost::Observer override 81 // AppCacheHost::Observer override
82 void OnDestructionImminent(AppCacheHost* host) override; 82 void OnDestructionImminent(AppCacheHost* host) override;
83 83
84 // AppCacheServiceImpl::Observer override 84 // AppCacheServiceImpl::Observer override
85 void OnServiceDestructionImminent(AppCacheServiceImpl* service) override; 85 void OnServiceDestructionImminent(AppCacheServiceImpl* service) override;
86 86
87 // Helpers to instruct a waiting job with what response to 87 // Helpers to instruct a waiting job with what response to
88 // deliver for the request we're handling. 88 // deliver for the request we're handling.
89 void DeliverAppCachedResponse(const AppCacheEntry& entry, 89 void DeliverAppCachedResponse(const AppCacheEntry& entry,
90 int64_t cache_id, 90 int64_t cache_id,
91 const GURL& manifest_url, 91 const GURL& manifest_url,
92 bool is_fallback, 92 bool is_fallback,
93 const GURL& namespace_entry_url); 93 const GURL& namespace_entry_url);
94 void DeliverNetworkResponse(); 94 void DeliverNetworkResponse();
95 void DeliverErrorResponse(); 95 void DeliverErrorResponse();
96 96
97 // Called just before the request is restarted. Grabs the reason for 97 // Called just before the request is restarted. Grabs the reason for
98 // restarting, so can correctly continue to handle the request. 98 // restarting, so can correctly continue to handle the request.
99 void OnPrepareToRestart(); 99 void OnPrepareToRestart();
100 100
101 // Helper method to create an AppCacheURLRequestJob and populate job_. 101 // Helper method to create an AppCacheURLRequestJob and populate job_.
102 // Caller takes ownership of returned value. 102 // Caller takes ownership of returned value.
103 std::unique_ptr<AppCacheURLRequestJob> CreateJob( 103 std::unique_ptr<AppCacheURLRequestJob> CreateJob(
104 net::URLRequest* request,
105 net::NetworkDelegate* network_delegate); 104 net::NetworkDelegate* network_delegate);
106 105
107 // Helper to retrieve a pointer to the storage object. 106 // Helper to retrieve a pointer to the storage object.
108 AppCacheStorage* storage() const; 107 AppCacheStorage* storage() const;
109 108
110 bool is_main_resource() const { 109 bool is_main_resource() const {
111 return IsMainResourceType(resource_type_); 110 return IsMainResourceType(resource_type_);
112 } 111 }
113 112
114 // Main-resource loading ------------------------------------- 113 // Main-resource loading -------------------------------------
115 // Frame and SharedWorker main resources are handled here. 114 // Frame and SharedWorker main resources are handled here.
116 115
117 std::unique_ptr<AppCacheURLRequestJob> MaybeLoadMainResource( 116 std::unique_ptr<AppCacheURLRequestJob> MaybeLoadMainResource(
118 net::URLRequest* request,
119 net::NetworkDelegate* network_delegate); 117 net::NetworkDelegate* network_delegate);
120 118
121 // AppCacheStorage::Delegate methods 119 // AppCacheStorage::Delegate methods
122 void OnMainResponseFound(const GURL& url, 120 void OnMainResponseFound(const GURL& url,
123 const AppCacheEntry& entry, 121 const AppCacheEntry& entry,
124 const GURL& fallback_url, 122 const GURL& fallback_url,
125 const AppCacheEntry& fallback_entry, 123 const AppCacheEntry& fallback_entry,
126 int64_t cache_id, 124 int64_t cache_id,
127 int64_t group_id, 125 int64_t group_id,
128 const GURL& mainfest_url) override; 126 const GURL& mainfest_url) override;
129 127
130 // Sub-resource loading ------------------------------------- 128 // Sub-resource loading -------------------------------------
131 // Dedicated worker and all manner of sub-resources are handled here. 129 // Dedicated worker and all manner of sub-resources are handled here.
132 130
133 std::unique_ptr<AppCacheURLRequestJob> MaybeLoadSubResource( 131 std::unique_ptr<AppCacheURLRequestJob> MaybeLoadSubResource(
134 net::URLRequest* request,
135 net::NetworkDelegate* network_delegate); 132 net::NetworkDelegate* network_delegate);
136 void ContinueMaybeLoadSubResource(); 133 void ContinueMaybeLoadSubResource();
137 134
138 // AppCacheHost::Observer override 135 // AppCacheHost::Observer override
139 void OnCacheSelectionComplete(AppCacheHost* host) override; 136 void OnCacheSelectionComplete(AppCacheHost* host) override;
140 137
141 // Data members ----------------------------------------------- 138 // Data members -----------------------------------------------
142 139
143 // What host we're servicing a request for. 140 // What host we're servicing a request for.
144 AppCacheHost* host_; 141 AppCacheHost* host_;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 int old_host_id_; 186 int old_host_id_;
190 187
191 // Cached information about the response being currently served by the 188 // Cached information about the response being currently served by the
192 // AppCache, if there is one. 189 // AppCache, if there is one.
193 int cache_id_; 190 int cache_id_;
194 GURL manifest_url_; 191 GURL manifest_url_;
195 192
196 // Backptr to the central service object. 193 // Backptr to the central service object.
197 AppCacheServiceImpl* service_; 194 AppCacheServiceImpl* service_;
198 195
196 std::unique_ptr<AppCacheRequest> request_;
michaeln 2017/05/01 20:53:58 i was wondering how object ownership was arranged,
197
199 friend class content::AppCacheRequestHandlerTest; 198 friend class content::AppCacheRequestHandlerTest;
200 DISALLOW_COPY_AND_ASSIGN(AppCacheRequestHandler); 199 DISALLOW_COPY_AND_ASSIGN(AppCacheRequestHandler);
201 }; 200 };
202 201
203 } // namespace content 202 } // namespace content
204 203
205 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ 204 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698