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_JOB_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_JOB_H_ |
6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_JOB_H_ | 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_JOB_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // Interface for an AppCache job. This is used to send data stored in the | 31 // Interface for an AppCache job. This is used to send data stored in the |
32 // AppCache to networking consumers. | 32 // AppCache to networking consumers. |
33 // Subclasses implement this interface to wrap custom job objects like | 33 // Subclasses implement this interface to wrap custom job objects like |
34 // URLRequestJob, URLLoaderJob, etc to ensure that these dependencies stay out | 34 // URLRequestJob, URLLoaderJob, etc to ensure that these dependencies stay out |
35 // of the AppCache code. | 35 // of the AppCache code. |
36 class CONTENT_EXPORT AppCacheJob | 36 class CONTENT_EXPORT AppCacheJob |
37 : NON_EXPORTED_BASE(public base::NonThreadSafe), | 37 : NON_EXPORTED_BASE(public base::NonThreadSafe), |
38 public base::SupportsWeakPtr<AppCacheJob> { | 38 public base::SupportsWeakPtr<AppCacheJob> { |
39 public: | 39 public: |
| 40 enum DeliveryType { |
| 41 AWAITING_DELIVERY_ORDERS, |
| 42 APPCACHED_DELIVERY, |
| 43 NETWORK_DELIVERY, |
| 44 ERROR_DELIVERY |
| 45 }; |
| 46 |
40 // Callback that will be invoked before the request is restarted. The caller | 47 // Callback that will be invoked before the request is restarted. The caller |
41 // can use this opportunity to grab state from the job to determine how it | 48 // can use this opportunity to grab state from the job to determine how it |
42 // should behave when the request is restarted. | 49 // should behave when the request is restarted. |
43 // TODO(ananta) | 50 // TODO(ananta) |
44 // This applies only to the URLRequestJob at the moment. Look into taking | 51 // This applies only to the URLRequestJob at the moment. Look into taking |
45 // this knowledge out of this class. | 52 // this knowledge out of this class. |
46 using OnPrepareToRestartCallback = base::Closure; | 53 using OnPrepareToRestartCallback = base::Closure; |
47 | 54 |
48 // Factory function to create the AppCacheJob instance for the |request| | 55 // Factory function to create the AppCacheJob instance for the |request| |
49 // passed in. The |job_type| parameter controls the type of job which is | 56 // passed in. The |job_type| parameter controls the type of job which is |
50 // created. | 57 // created. |
51 static std::unique_ptr<AppCacheJob> Create( | 58 static std::unique_ptr<AppCacheJob> Create( |
52 bool is_main_resource, | 59 bool is_main_resource, |
53 AppCacheHost* host, | 60 AppCacheHost* host, |
54 AppCacheStorage* storage, | 61 AppCacheStorage* storage, |
55 AppCacheRequest* request, | 62 AppCacheRequest* request, |
56 net::NetworkDelegate* network_delegate, | 63 net::NetworkDelegate* network_delegate, |
57 const OnPrepareToRestartCallback& restart_callback); | 64 const OnPrepareToRestartCallback& restart_callback); |
58 | 65 |
59 virtual ~AppCacheJob(); | 66 virtual ~AppCacheJob(); |
60 | 67 |
61 // Kills the job. | 68 // Kills the job. |
62 virtual void Kill() = 0; | 69 virtual void Kill() = 0; |
63 | 70 |
64 // Returns true if the job was started. | 71 // Returns true if the job was started. |
65 virtual bool IsStarted() const = 0; | 72 virtual bool IsStarted() const = 0; |
66 | 73 |
67 // Returns true if the job is waiting for instructions. | 74 // Returns true if the job is waiting for instructions. |
68 virtual bool IsWaiting() const = 0; | 75 virtual bool IsWaiting() const; |
69 | 76 |
70 // Returns true if the job is delivering a response from the cache. | 77 // Returns true if the job is delivering a response from the cache. |
71 virtual bool IsDeliveringAppCacheResponse() const = 0; | 78 virtual bool IsDeliveringAppCacheResponse() const; |
72 | 79 |
73 // Returns true if the job is delivering a response from the network. | 80 // Returns true if the job is delivering a response from the network. |
74 virtual bool IsDeliveringNetworkResponse() const = 0; | 81 virtual bool IsDeliveringNetworkResponse() const; |
75 | 82 |
76 // Returns true if the job is delivering an error response. | 83 // Returns true if the job is delivering an error response. |
77 virtual bool IsDeliveringErrorResponse() const = 0; | 84 virtual bool IsDeliveringErrorResponse() const; |
78 | 85 |
79 // Returns true if the cache entry was not found in the cache. | 86 // Returns true if the cache entry was not found in the cache. |
80 virtual bool IsCacheEntryNotFound() const = 0; | 87 virtual bool IsCacheEntryNotFound() const; |
81 | 88 |
82 // Informs the job of what response it should deliver. Only one of these | 89 // Informs the job of what response it should deliver. Only one of these |
83 // methods should be called, and only once per job. A job will sit idle and | 90 // methods should be called, and only once per job. A job will sit idle and |
84 // wait indefinitely until one of the deliver methods is called. | 91 // wait indefinitely until one of the deliver methods is called. |
85 virtual void DeliverAppCachedResponse(const GURL& manifest_url, | 92 virtual void DeliverAppCachedResponse(const GURL& manifest_url, |
86 int64_t cache_id, | 93 int64_t cache_id, |
87 const AppCacheEntry& entry, | 94 const AppCacheEntry& entry, |
88 bool is_fallback) = 0; | 95 bool is_fallback) = 0; |
89 | 96 |
90 // Informs the job that it should deliver the response from the network. This | 97 // Informs the job that it should deliver the response from the network. This |
(...skipping 13 matching lines...) Expand all Loading... |
104 // AppCaches loaded via the URLLoader mechanism. | 111 // AppCaches loaded via the URLLoader mechanism. |
105 virtual net::URLRequestJob* AsURLRequestJob(); | 112 virtual net::URLRequestJob* AsURLRequestJob(); |
106 | 113 |
107 // Returns the underlying ApppCacheURLLoaderJob if any. This only applies to | 114 // Returns the underlying ApppCacheURLLoaderJob if any. This only applies to |
108 // AppCaches loaded via the URLRequest mechanism. | 115 // AppCaches loaded via the URLRequest mechanism. |
109 virtual AppCacheURLLoaderJob* AsURLLoaderJob(); | 116 virtual AppCacheURLLoaderJob* AsURLLoaderJob(); |
110 | 117 |
111 protected: | 118 protected: |
112 AppCacheJob(); | 119 AppCacheJob(); |
113 | 120 |
| 121 // Set to true if the AppCache entry is not found. |
| 122 bool cache_entry_not_found_; |
| 123 |
| 124 // The jobs delivery status. |
| 125 DeliveryType delivery_type_; |
| 126 |
114 base::WeakPtrFactory<AppCacheJob> weak_factory_; | 127 base::WeakPtrFactory<AppCacheJob> weak_factory_; |
115 | 128 |
116 DISALLOW_COPY_AND_ASSIGN(AppCacheJob); | 129 DISALLOW_COPY_AND_ASSIGN(AppCacheJob); |
117 }; | 130 }; |
118 | 131 |
119 } // namespace content | 132 } // namespace content |
120 | 133 |
121 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_JOB_H_ | 134 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_JOB_H_ |
OLD | NEW |