Chromium Code Reviews| 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. Subclasses implement this interface to | |
|
jam
2017/05/05 23:15:25
nit: can you describe what the purpose of this int
ananta
2017/05/06 03:01:35
Done.
| |
| 31 // wrap custom job objects like URLRequestJob, URLLoaderJob, etc to ensure that | |
| 32 // these dependencies stay out of the AppCache code. | |
| 33 class CONTENT_EXPORT AppCacheJob | |
| 34 : NON_EXPORTED_BASE(public base::NonThreadSafe), | |
| 35 public base::SupportsWeakPtr<AppCacheJob> { | |
|
jam
2017/05/05 23:15:25
nit: don't need to derive from SupportsWeakPtr sin
ananta
2017/05/06 03:01:34
Unfortunately we need this as the AppCacheURLReque
jam
2017/05/08 14:03:12
AppCacheURLRequestJob used to call weak_factory_.G
| |
| 36 public: | |
| 37 // Callback that will be invoked before the request is restarted. The caller | |
| 38 // can use this opportunity to grab state from the job to determine how it | |
| 39 // should behave when the request is restarted. | |
| 40 // TODO(ananta) | |
| 41 // This applies only to the URLRequestJob at the moment. Look into taking | |
| 42 // this knowledge out of this class. | |
| 43 using OnPrepareToRestartCallback = base::Closure; | |
| 44 | |
| 45 // Controls which job gets created. | |
| 46 enum class kJobType { | |
| 47 URL_REQUEST_JOB, // The regular URLRequestJob. | |
| 48 URL_LOADER_JOB, // The URLLoader job used by the mojo network service. | |
| 49 }; | |
| 50 | |
| 51 // Factory function to create the AppCacheJob instance for the |request| | |
| 52 // passed in. The |job_type| parameter controls the type of job which is | |
| 53 // created. | |
| 54 static std::unique_ptr<AppCacheJob> Create( | |
| 55 kJobType job_type, | |
| 56 bool is_main_resource, | |
| 57 AppCacheHost* host, | |
| 58 AppCacheStorage* storage, | |
| 59 AppCacheRequest* request, | |
| 60 net::NetworkDelegate* network_delegate, | |
| 61 const OnPrepareToRestartCallback& restart_callback); | |
| 62 | |
| 63 virtual ~AppCacheJob(); | |
| 64 | |
| 65 // Kills the job. | |
| 66 virtual void Kill() = 0; | |
| 67 | |
| 68 // Returns true if the job was started. | |
| 69 virtual bool IsStarted() const = 0; | |
| 70 | |
| 71 // Returns true if the job is waiting for instructions. | |
| 72 virtual bool IsWaiting() const = 0; | |
| 73 | |
| 74 // Returns true if the job is delivering a response from the cache. | |
| 75 virtual bool IsDeliveringAppCacheResponse() const = 0; | |
| 76 | |
| 77 // Returns true if the job is delivering a response from the network. | |
| 78 virtual bool IsDeliveringNetworkResponse() const = 0; | |
| 79 | |
| 80 // Returns true if the job is delivering an error response. | |
| 81 virtual bool IsDeliveringErrorResponse() const = 0; | |
| 82 | |
| 83 // Returns true if the cache entry was not found in the cache. | |
| 84 virtual bool IsCacheEntryNotFound() const = 0; | |
| 85 | |
| 86 // Informs the job of what response it should deliver. Only one of these | |
| 87 // methods should be called, and only once per job. A job will sit idle and | |
| 88 // wait indefinitely until one of the deliver methods is called. | |
| 89 virtual void DeliverAppCachedResponse(const GURL& manifest_url, | |
| 90 int64_t cache_id, | |
| 91 const AppCacheEntry& entry, | |
| 92 bool is_fallback) = 0; | |
| 93 | |
| 94 // Informs the job that it should deliver the response from the network. This | |
| 95 // is generally controlled by the entries in the manifest file. | |
| 96 virtual void DeliverNetworkResponse() = 0; | |
| 97 | |
| 98 // Informs the job that it should deliver an error response. | |
| 99 virtual void DeliverErrorResponse() = 0; | |
| 100 | |
| 101 // Returns a weak pointer reference to the job. | |
| 102 virtual base::WeakPtr<AppCacheJob> GetWeakPtr(); | |
| 103 | |
| 104 // Returns the URL of the job. | |
| 105 virtual const GURL& GetURL() const = 0; | |
| 106 | |
| 107 // Returns the underlying URLRequestJob if any. This only applies to | |
| 108 // AppCaches loaded via the URLRequest mechanism. | |
| 109 virtual net::URLRequestJob* AsURLRequestJob(); | |
| 110 | |
| 111 protected: | |
| 112 AppCacheJob(); | |
| 113 | |
| 114 base::WeakPtrFactory<AppCacheJob> weak_factory_; | |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(AppCacheJob); | |
| 117 }; | |
| 118 | |
| 119 } // namespace content | |
| 120 | |
| 121 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_JOB_H_ | |
| OLD | NEW |