| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_REQUEST_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_REQUEST_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_REQUEST_HANDLER_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_REQUEST_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "content/browser/service_worker/service_worker_request_handler.h" | 11 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 class ServiceWorkerVersion; | 15 class ServiceWorkerVersion; |
| 16 | 16 |
| 17 // A request handler derivative used to handle requests from | 17 // A request handler derivative used to handle requests from |
| 18 // service workers. | 18 // service workers. |
| 19 class CONTENT_EXPORT ServiceWorkerContextRequestHandler | 19 class CONTENT_EXPORT ServiceWorkerContextRequestHandler |
| 20 : public ServiceWorkerRequestHandler { | 20 : public ServiceWorkerRequestHandler { |
| 21 public: | 21 public: |
| 22 enum class CreateJobStatus { | 22 enum class CreateJobStatus { |
| 23 UNINITIALIZED, | 23 UNINITIALIZED, |
| 24 CREATED_WRITE_JOB_FOR_REGISTER, | 24 WRITE_JOB_FOR_REGISTER, |
| 25 CREATED_WRITE_JOB_FOR_UPDATE, | 25 WRITE_JOB_FOR_UPDATE, |
| 26 CREATED_READ_JOB, | 26 READ_JOB, |
| 27 NO_PROVIDER, | 27 // When a new worker imports a script that was already imported. |
| 28 NO_VERSION, | 28 READ_JOB_FOR_DUPLICATE_SCRIPT_IMPORT, |
| 29 NO_CONTEXT, | 29 ERROR_NO_PROVIDER, |
| 30 IGNORE_REDIRECT, | 30 ERROR_NO_VERSION, |
| 31 IGNORE_NON_SCRIPT, | 31 ERROR_REDUNDANT_VERSION, |
| 32 OUT_OF_RESOURCE_IDS, | 32 ERROR_NO_CONTEXT, |
| 33 IGNORE_UNKNOWN, | 33 ERROR_REDIRECT, |
| 34 // This is just to distinguish from UNINITIALIZED in case the function that | 34 // When an installed worker imports a script that was not stored at |
| 35 // is supposed to set status didn't do so. | 35 // installation time. |
| 36 DID_NOT_SET_STATUS | 36 ERROR_UNINSTALLED_SCRIPT_IMPORT, |
| 37 ERROR_OUT_OF_RESOURCE_IDS, |
| 38 NUM_TYPES |
| 37 }; | 39 }; |
| 38 | 40 |
| 39 ServiceWorkerContextRequestHandler( | 41 ServiceWorkerContextRequestHandler( |
| 40 base::WeakPtr<ServiceWorkerContextCore> context, | 42 base::WeakPtr<ServiceWorkerContextCore> context, |
| 41 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 43 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
| 42 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 44 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
| 43 ResourceType resource_type); | 45 ResourceType resource_type); |
| 44 ~ServiceWorkerContextRequestHandler() override; | 46 ~ServiceWorkerContextRequestHandler() override; |
| 45 | 47 |
| 46 // Called via custom URLRequestJobFactory. | 48 // Called via custom URLRequestJobFactory. |
| 47 net::URLRequestJob* MaybeCreateJob( | 49 net::URLRequestJob* MaybeCreateJob( |
| 48 net::URLRequest* request, | 50 net::URLRequest* request, |
| 49 net::NetworkDelegate* network_delegate, | 51 net::NetworkDelegate* network_delegate, |
| 50 ResourceContext* resource_context) override; | 52 ResourceContext* resource_context) override; |
| 51 | 53 |
| 54 static std::string CreateJobStatusToString(CreateJobStatus status); |
| 55 |
| 52 private: | 56 private: |
| 53 net::URLRequestJob* MaybeCreateJobImpl(CreateJobStatus* out_status, | 57 net::URLRequestJob* MaybeCreateJobImpl(net::URLRequest* request, |
| 54 net::URLRequest* request, | |
| 55 net::NetworkDelegate* network_delegate, | 58 net::NetworkDelegate* network_delegate, |
| 56 ResourceContext* resource_context); | 59 CreateJobStatus* out_status); |
| 57 bool ShouldAddToScriptCache(const GURL& url); | |
| 58 bool ShouldReadFromScriptCache(const GURL& url, int64_t* resource_id_out); | |
| 59 | 60 |
| 60 scoped_refptr<ServiceWorkerVersion> version_; | 61 scoped_refptr<ServiceWorkerVersion> version_; |
| 61 | 62 |
| 62 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextRequestHandler); | 63 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextRequestHandler); |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 } // namespace content | 66 } // namespace content |
| 66 | 67 |
| 67 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_REQUEST_HANDLER
_H_ | 68 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_REQUEST_HANDLER
_H_ |
| OLD | NEW |