Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_controllee_request_handler.h
blob84b39c26c79cae32e25fadd717551f23b7855cdd
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER_H_
8 #include "base/gtest_prod_util.h"
9 #include "content/browser/service_worker/service_worker_request_handler.h"
10 #include "content/common/service_worker/service_worker_types.h"
11 #include "content/public/common/request_context_frame_type.h"
12 #include "content/public/common/request_context_type.h"
13 #include "content/public/common/resource_type.h"
14 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerResponseType.h"
15 #include "url/gurl.h"
17 namespace net {
18 class NetworkDelegate;
19 class URLRequest;
22 namespace content {
24 class ResourceRequestBody;
25 class ServiceWorkerRegistration;
26 class ServiceWorkerURLRequestJob;
27 class ServiceWorkerVersion;
29 // A request handler derivative used to handle requests from
30 // controlled documents.
31 class CONTENT_EXPORT ServiceWorkerControlleeRequestHandler
32 : public ServiceWorkerRequestHandler {
33 public:
34 ServiceWorkerControlleeRequestHandler(
35 base::WeakPtr<ServiceWorkerContextCore> context,
36 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
37 base::WeakPtr<storage::BlobStorageContext> blob_storage_context,
38 FetchRequestMode request_mode,
39 FetchCredentialsMode credentials_mode,
40 FetchRedirectMode redirect_mode,
41 ResourceType resource_type,
42 RequestContextType request_context_type,
43 RequestContextFrameType frame_type,
44 scoped_refptr<ResourceRequestBody> body);
45 ~ServiceWorkerControlleeRequestHandler() override;
47 // Called via custom URLRequestJobFactory.
48 net::URLRequestJob* MaybeCreateJob(
49 net::URLRequest* request,
50 net::NetworkDelegate* network_delegate,
51 ResourceContext* resource_context) override;
53 void GetExtraResponseInfo(ResourceResponseInfo* response_info) const override;
55 private:
56 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerControlleeRequestHandlerTest,
57 ActivateWaitingVersion);
58 typedef ServiceWorkerControlleeRequestHandler self;
60 // For main resource case.
61 void PrepareForMainResource(const net::URLRequest* request);
62 void DidLookupRegistrationForMainResource(
63 ServiceWorkerStatusCode status,
64 const scoped_refptr<ServiceWorkerRegistration>& registration);
65 void OnVersionStatusChanged(
66 ServiceWorkerRegistration* registration,
67 ServiceWorkerVersion* version);
69 void DidUpdateRegistration(
70 const scoped_refptr<ServiceWorkerRegistration>& original_registration,
71 ServiceWorkerStatusCode status,
72 const std::string& status_message,
73 int64 registration_id);
74 void OnUpdatedVersionStatusChanged(
75 const scoped_refptr<ServiceWorkerRegistration>& registration,
76 const scoped_refptr<ServiceWorkerVersion>& version);
78 // For sub resource case.
79 void PrepareForSubResource();
81 void FallbackToNetwork();
83 bool is_main_resource_load_;
84 scoped_refptr<ServiceWorkerURLRequestJob> job_;
85 FetchRequestMode request_mode_;
86 FetchCredentialsMode credentials_mode_;
87 FetchRedirectMode redirect_mode_;
88 RequestContextType request_context_type_;
89 RequestContextFrameType frame_type_;
90 scoped_refptr<ResourceRequestBody> body_;
91 ResourceContext* resource_context_;
92 GURL stripped_url_;
93 base::TimeTicks worker_start_time_;
94 base::TimeTicks worker_ready_time_;
95 bool skip_service_worker_;
96 bool force_update_started_;
97 base::WeakPtrFactory<ServiceWorkerControlleeRequestHandler> weak_factory_;
99 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerControlleeRequestHandler);
102 } // namespace content
104 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTROLLEE_REQUEST_HANDLER_H_