OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_JOB_H_ |
| 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_JOB_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/strings/string16.h" |
| 13 #include "base/threading/non_thread_safe.h" |
| 14 #include "content/common/content_export.h" |
| 15 #include "url/gurl.h" |
| 16 |
| 17 namespace net { |
| 18 class NetworkDelegate; |
| 19 class URLRequestJob; |
| 20 } |
| 21 |
| 22 namespace content { |
| 23 |
| 24 class AppCacheEntry; |
| 25 class AppCacheHost; |
| 26 class AppCacheRequest; |
| 27 class AppCacheStorage; |
| 28 class URLRequestJob; |
| 29 |
| 30 // Interface for an AppCache job. This is used to send data stored in the |
| 31 // AppCache to networking consumers. |
| 32 // Subclasses implement this interface to wrap custom job objects like |
| 33 // URLRequestJob, URLLoaderJob, etc to ensure that these dependencies stay out |
| 34 // of the AppCache code. |
| 35 class CONTENT_EXPORT AppCacheJob |
| 36 : NON_EXPORTED_BASE(public base::NonThreadSafe), |
| 37 public base::SupportsWeakPtr<AppCacheJob> { |
| 38 public: |
| 39 // Callback that will be invoked before the request is restarted. The caller |
| 40 // can use this opportunity to grab state from the job to determine how it |
| 41 // should behave when the request is restarted. |
| 42 // TODO(ananta) |
| 43 // This applies only to the URLRequestJob at the moment. Look into taking |
| 44 // this knowledge out of this class. |
| 45 using OnPrepareToRestartCallback = base::Closure; |
| 46 |
| 47 // Factory function to create the AppCacheJob instance for the |request| |
| 48 // passed in. The |job_type| parameter controls the type of job which is |
| 49 // created. |
| 50 static std::unique_ptr<AppCacheJob> Create( |
| 51 bool is_main_resource, |
| 52 AppCacheHost* host, |
| 53 AppCacheStorage* storage, |
| 54 AppCacheRequest* request, |
| 55 net::NetworkDelegate* network_delegate, |
| 56 const OnPrepareToRestartCallback& restart_callback); |
| 57 |
| 58 virtual ~AppCacheJob(); |
| 59 |
| 60 // Kills the job. |
| 61 virtual void Kill() = 0; |
| 62 |
| 63 // Returns true if the job was started. |
| 64 virtual bool IsStarted() const = 0; |
| 65 |
| 66 // Returns true if the job is waiting for instructions. |
| 67 virtual bool IsWaiting() const = 0; |
| 68 |
| 69 // Returns true if the job is delivering a response from the cache. |
| 70 virtual bool IsDeliveringAppCacheResponse() const = 0; |
| 71 |
| 72 // Returns true if the job is delivering a response from the network. |
| 73 virtual bool IsDeliveringNetworkResponse() const = 0; |
| 74 |
| 75 // Returns true if the job is delivering an error response. |
| 76 virtual bool IsDeliveringErrorResponse() const = 0; |
| 77 |
| 78 // Returns true if the cache entry was not found in the cache. |
| 79 virtual bool IsCacheEntryNotFound() const = 0; |
| 80 |
| 81 // Informs the job of what response it should deliver. Only one of these |
| 82 // methods should be called, and only once per job. A job will sit idle and |
| 83 // wait indefinitely until one of the deliver methods is called. |
| 84 virtual void DeliverAppCachedResponse(const GURL& manifest_url, |
| 85 int64_t cache_id, |
| 86 const AppCacheEntry& entry, |
| 87 bool is_fallback) = 0; |
| 88 |
| 89 // Informs the job that it should deliver the response from the network. This |
| 90 // is generally controlled by the entries in the manifest file. |
| 91 virtual void DeliverNetworkResponse() = 0; |
| 92 |
| 93 // Informs the job that it should deliver an error response. |
| 94 virtual void DeliverErrorResponse() = 0; |
| 95 |
| 96 // Returns a weak pointer reference to the job. |
| 97 virtual base::WeakPtr<AppCacheJob> GetWeakPtr(); |
| 98 |
| 99 // Returns the URL of the job. |
| 100 virtual const GURL& GetURL() const = 0; |
| 101 |
| 102 // Returns the underlying URLRequestJob if any. This only applies to |
| 103 // AppCaches loaded via the URLRequest mechanism. |
| 104 virtual net::URLRequestJob* AsURLRequestJob(); |
| 105 |
| 106 protected: |
| 107 AppCacheJob(); |
| 108 |
| 109 base::WeakPtrFactory<AppCacheJob> weak_factory_; |
| 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(AppCacheJob); |
| 112 }; |
| 113 |
| 114 } // namespace content |
| 115 |
| 116 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_JOB_H_ |
OLD | NEW |