[email protected] | 7ee2e88 | 2012-06-04 08:54:10 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 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 WEBKIT_APPCACHE_APPCACHE_INTERFACES_H_ |
| 6 | #define WEBKIT_APPCACHE_APPCACHE_INTERFACES_H_ |
| 7 | |
[email protected] | 7e8e3dd | 2009-09-18 01:05:09 | [diff] [blame] | 8 | #include <string> |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 9 | #include <vector> |
| 10 | #include "base/basictypes.h" |
[email protected] | 4cccc22 | 2010-04-02 22:12:56 | [diff] [blame] | 11 | #include "base/file_path.h" |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 12 | #include "base/time.h" |
| 13 | #include "googleurl/src/gurl.h" |
[email protected] | 4cea354 | 2012-10-23 04:18:40 | [diff] [blame] | 14 | #include "webkit/storage/webkit_storage_export.h" |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 15 | |
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 16 | namespace net { |
[email protected] | 7e8e3dd | 2009-09-18 01:05:09 | [diff] [blame] | 17 | class URLRequest; |
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 18 | } // namespace net |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 19 | |
| 20 | namespace appcache { |
| 21 | |
| 22 | // Defines constants, types, and abstract classes used in the main |
| 23 | // process and in child processes. |
| 24 | |
| 25 | static const int kNoHostId = 0; |
| 26 | static const int64 kNoCacheId = 0; |
[email protected] | e7dff7ba | 2009-10-09 03:25:51 | [diff] [blame] | 27 | static const int64 kNoResponseId = 0; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 28 | static const int64 kUnknownCacheId = -1; |
| 29 | |
| 30 | enum Status { |
| 31 | UNCACHED, |
| 32 | IDLE, |
| 33 | CHECKING, |
| 34 | DOWNLOADING, |
| 35 | UPDATE_READY, |
| 36 | OBSOLETE |
| 37 | }; |
| 38 | |
| 39 | enum EventID { |
| 40 | CHECKING_EVENT, |
| 41 | ERROR_EVENT, |
| 42 | NO_UPDATE_EVENT, |
| 43 | DOWNLOADING_EVENT, |
| 44 | PROGRESS_EVENT, |
| 45 | UPDATE_READY_EVENT, |
| 46 | CACHED_EVENT, |
| 47 | OBSOLETE_EVENT |
| 48 | }; |
| 49 | |
[email protected] | 53c570b | 2010-06-18 02:02:05 | [diff] [blame] | 50 | enum LogLevel { |
[email protected] | df4cd15 | 2010-06-25 00:46:02 | [diff] [blame] | 51 | LOG_TIP, |
[email protected] | 53c570b | 2010-06-18 02:02:05 | [diff] [blame] | 52 | LOG_INFO, |
| 53 | LOG_WARNING, |
| 54 | LOG_ERROR, |
| 55 | }; |
| 56 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 57 | enum NamespaceType { |
| 58 | FALLBACK_NAMESPACE, |
| 59 | INTERCEPT_NAMESPACE |
| 60 | }; |
| 61 | |
[email protected] | 4cea354 | 2012-10-23 04:18:40 | [diff] [blame] | 62 | struct WEBKIT_STORAGE_EXPORT AppCacheInfo { |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 63 | AppCacheInfo(); |
| 64 | ~AppCacheInfo(); |
| 65 | |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 66 | GURL manifest_url; |
| 67 | base::Time creation_time; |
| 68 | base::Time last_update_time; |
| 69 | base::Time last_access_time; |
| 70 | int64 cache_id; |
[email protected] | 4252f60 | 2011-10-21 19:18:36 | [diff] [blame] | 71 | int64 group_id; |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 72 | Status status; |
| 73 | int64 size; |
| 74 | bool is_complete; |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | typedef std::vector<AppCacheInfo> AppCacheInfoVector; |
| 78 | |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 79 | // Type to hold information about a single appcache resource. |
[email protected] | 4cea354 | 2012-10-23 04:18:40 | [diff] [blame] | 80 | struct WEBKIT_STORAGE_EXPORT AppCacheResourceInfo { |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 81 | AppCacheResourceInfo(); |
| 82 | ~AppCacheResourceInfo(); |
| 83 | |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 84 | GURL url; |
| 85 | int64 size; |
| 86 | bool is_master; |
| 87 | bool is_manifest; |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 88 | bool is_intercept; |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 89 | bool is_fallback; |
| 90 | bool is_foreign; |
| 91 | bool is_explicit; |
[email protected] | 5e5bbf40 | 2011-07-12 23:34:12 | [diff] [blame] | 92 | int64 response_id; |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 93 | }; |
| 94 | |
[email protected] | 5e5bbf40 | 2011-07-12 23:34:12 | [diff] [blame] | 95 | typedef std::vector<AppCacheResourceInfo> AppCacheResourceInfoVector; |
| 96 | |
[email protected] | 4cea354 | 2012-10-23 04:18:40 | [diff] [blame] | 97 | struct WEBKIT_STORAGE_EXPORT Namespace { |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 98 | Namespace(); // Type is set to FALLBACK_NAMESPACE by default. |
| 99 | Namespace(NamespaceType type, const GURL& url, const GURL& target); |
| 100 | ~Namespace(); |
| 101 | |
| 102 | NamespaceType type; |
| 103 | GURL namespace_url; |
| 104 | GURL target_url; |
| 105 | }; |
| 106 | |
| 107 | typedef std::vector<Namespace> NamespaceVector; |
| 108 | |
[email protected] | 19251af | 2010-05-13 18:24:46 | [diff] [blame] | 109 | // Interface used by backend (browser-process) to talk to frontend (renderer). |
[email protected] | 4cea354 | 2012-10-23 04:18:40 | [diff] [blame] | 110 | class WEBKIT_STORAGE_EXPORT AppCacheFrontend { |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 111 | public: |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 112 | virtual void OnCacheSelected( |
| 113 | int host_id, const appcache::AppCacheInfo& info) = 0; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 114 | virtual void OnStatusChanged(const std::vector<int>& host_ids, |
| 115 | Status status) = 0; |
| 116 | virtual void OnEventRaised(const std::vector<int>& host_ids, |
| 117 | EventID event_id) = 0; |
[email protected] | 697af4a | 2010-05-25 21:15:31 | [diff] [blame] | 118 | virtual void OnProgressEventRaised(const std::vector<int>& host_ids, |
| 119 | const GURL& url, |
| 120 | int num_total, int num_complete) = 0; |
[email protected] | 097dde2 | 2010-07-14 02:31:55 | [diff] [blame] | 121 | virtual void OnErrorEventRaised(const std::vector<int>& host_ids, |
| 122 | const std::string& message) = 0; |
[email protected] | 5c7d598 | 2010-07-12 09:12:59 | [diff] [blame] | 123 | virtual void OnContentBlocked(int host_id, |
| 124 | const GURL& manifest_url) = 0; |
[email protected] | 53c570b | 2010-06-18 02:02:05 | [diff] [blame] | 125 | virtual void OnLogMessage(int host_id, LogLevel log_level, |
| 126 | const std::string& message) = 0; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 127 | virtual ~AppCacheFrontend() {} |
| 128 | }; |
| 129 | |
[email protected] | 19251af | 2010-05-13 18:24:46 | [diff] [blame] | 130 | // Interface used by frontend (renderer) to talk to backend (browser-process). |
[email protected] | 4cea354 | 2012-10-23 04:18:40 | [diff] [blame] | 131 | class WEBKIT_STORAGE_EXPORT AppCacheBackend { |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 132 | public: |
| 133 | virtual void RegisterHost(int host_id) = 0; |
| 134 | virtual void UnregisterHost(int host_id) = 0; |
[email protected] | e16b8af7 | 2011-03-21 22:11:42 | [diff] [blame] | 135 | virtual void SetSpawningHostId(int host_id, int spawning_host_id) = 0; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 136 | virtual void SelectCache(int host_id, |
| 137 | const GURL& document_url, |
| 138 | const int64 cache_document_was_loaded_from, |
| 139 | const GURL& manifest_url) = 0; |
[email protected] | 19251af | 2010-05-13 18:24:46 | [diff] [blame] | 140 | virtual void SelectCacheForWorker( |
| 141 | int host_id, |
| 142 | int parent_process_id, |
| 143 | int parent_host_id) = 0; |
| 144 | virtual void SelectCacheForSharedWorker( |
| 145 | int host_id, |
| 146 | int64 appcache_id) = 0; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 147 | virtual void MarkAsForeignEntry(int host_id, const GURL& document_url, |
| 148 | int64 cache_document_was_loaded_from) = 0; |
| 149 | virtual Status GetStatus(int host_id) = 0; |
| 150 | virtual bool StartUpdate(int host_id) = 0; |
| 151 | virtual bool SwapCache(int host_id) = 0; |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 152 | virtual void GetResourceList( |
| 153 | int host_id, std::vector<AppCacheResourceInfo>* resource_infos) = 0; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 154 | |
[email protected] | 7ee2e88 | 2012-06-04 08:54:10 | [diff] [blame] | 155 | protected: |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 156 | virtual ~AppCacheBackend() {} |
| 157 | }; |
| 158 | |
[email protected] | 7e8e3dd | 2009-09-18 01:05:09 | [diff] [blame] | 159 | // Useful string constants. |
| 160 | // Note: These are also defined elsewhere in the chrome code base in |
| 161 | // url_contants.h .cc, however the appcache library doesn't not have |
| 162 | // any dependencies on the chrome library, so we can't use them in here. |
| 163 | extern const char kHttpScheme[]; |
| 164 | extern const char kHttpsScheme[]; |
| 165 | extern const char kHttpGETMethod[]; |
| 166 | extern const char kHttpHEADMethod[]; |
| 167 | |
| 168 | bool IsSchemeSupported(const GURL& url); |
| 169 | bool IsMethodSupported(const std::string& method); |
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 170 | bool IsSchemeAndMethodSupported(const net::URLRequest* request); |
[email protected] | 7e8e3dd | 2009-09-18 01:05:09 | [diff] [blame] | 171 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame^] | 172 | WEBKIT_STORAGE_EXPORT extern const base::FilePath::CharType |
| 173 | kAppCacheDatabaseName[]; |
[email protected] | 4cccc22 | 2010-04-02 22:12:56 | [diff] [blame] | 174 | |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 175 | } // namespace |
| 176 | |
| 177 | #endif // WEBKIT_APPCACHE_APPCACHE_INTERFACES_H_ |