blob: 78752b1df1d800230a2c1ca237ffe6e4768c4fbe [file] [log] [blame]
[email protected]7ee2e882012-06-04 08:54:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]f430b5712009-08-21 21:46:312// 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]7e8e3dd2009-09-18 01:05:098#include <string>
[email protected]f430b5712009-08-21 21:46:319#include <vector>
10#include "base/basictypes.h"
[email protected]4cccc222010-04-02 22:12:5611#include "base/file_path.h"
[email protected]ec5c1922010-07-28 03:14:3712#include "base/time.h"
13#include "googleurl/src/gurl.h"
[email protected]4cea3542012-10-23 04:18:4014#include "webkit/storage/webkit_storage_export.h"
[email protected]f430b5712009-08-21 21:46:3115
[email protected]edfe7fab2010-11-28 13:11:5216namespace net {
[email protected]7e8e3dd2009-09-18 01:05:0917class URLRequest;
[email protected]edfe7fab2010-11-28 13:11:5218} // namespace net
[email protected]f430b5712009-08-21 21:46:3119
20namespace appcache {
21
22// Defines constants, types, and abstract classes used in the main
23// process and in child processes.
24
25static const int kNoHostId = 0;
26static const int64 kNoCacheId = 0;
[email protected]e7dff7ba2009-10-09 03:25:5127static const int64 kNoResponseId = 0;
[email protected]f430b5712009-08-21 21:46:3128static const int64 kUnknownCacheId = -1;
29
30enum Status {
31 UNCACHED,
32 IDLE,
33 CHECKING,
34 DOWNLOADING,
35 UPDATE_READY,
36 OBSOLETE
37};
38
39enum 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]53c570b2010-06-18 02:02:0550enum LogLevel {
[email protected]df4cd152010-06-25 00:46:0251 LOG_TIP,
[email protected]53c570b2010-06-18 02:02:0552 LOG_INFO,
53 LOG_WARNING,
54 LOG_ERROR,
55};
56
[email protected]e2cadec82011-12-13 02:00:5357enum NamespaceType {
58 FALLBACK_NAMESPACE,
59 INTERCEPT_NAMESPACE
60};
61
[email protected]4cea3542012-10-23 04:18:4062struct WEBKIT_STORAGE_EXPORT AppCacheInfo {
[email protected]20f0487a2010-09-30 20:06:3063 AppCacheInfo();
64 ~AppCacheInfo();
65
[email protected]ec5c1922010-07-28 03:14:3766 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]4252f602011-10-21 19:18:3671 int64 group_id;
[email protected]ec5c1922010-07-28 03:14:3772 Status status;
73 int64 size;
74 bool is_complete;
[email protected]ec5c1922010-07-28 03:14:3775};
76
77typedef std::vector<AppCacheInfo> AppCacheInfoVector;
78
[email protected]20f0487a2010-09-30 20:06:3079// Type to hold information about a single appcache resource.
[email protected]4cea3542012-10-23 04:18:4080struct WEBKIT_STORAGE_EXPORT AppCacheResourceInfo {
[email protected]20f0487a2010-09-30 20:06:3081 AppCacheResourceInfo();
82 ~AppCacheResourceInfo();
83
[email protected]ec5c1922010-07-28 03:14:3784 GURL url;
85 int64 size;
86 bool is_master;
87 bool is_manifest;
[email protected]e2cadec82011-12-13 02:00:5388 bool is_intercept;
[email protected]ec5c1922010-07-28 03:14:3789 bool is_fallback;
90 bool is_foreign;
91 bool is_explicit;
[email protected]5e5bbf402011-07-12 23:34:1292 int64 response_id;
[email protected]ec5c1922010-07-28 03:14:3793};
94
[email protected]5e5bbf402011-07-12 23:34:1295typedef std::vector<AppCacheResourceInfo> AppCacheResourceInfoVector;
96
[email protected]4cea3542012-10-23 04:18:4097struct WEBKIT_STORAGE_EXPORT Namespace {
[email protected]e2cadec82011-12-13 02:00:5398 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
107typedef std::vector<Namespace> NamespaceVector;
108
[email protected]19251af2010-05-13 18:24:46109// Interface used by backend (browser-process) to talk to frontend (renderer).
[email protected]4cea3542012-10-23 04:18:40110class WEBKIT_STORAGE_EXPORT AppCacheFrontend {
[email protected]f430b5712009-08-21 21:46:31111 public:
[email protected]ec5c1922010-07-28 03:14:37112 virtual void OnCacheSelected(
113 int host_id, const appcache::AppCacheInfo& info) = 0;
[email protected]f430b5712009-08-21 21:46:31114 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]697af4a2010-05-25 21:15:31118 virtual void OnProgressEventRaised(const std::vector<int>& host_ids,
119 const GURL& url,
120 int num_total, int num_complete) = 0;
[email protected]097dde22010-07-14 02:31:55121 virtual void OnErrorEventRaised(const std::vector<int>& host_ids,
122 const std::string& message) = 0;
[email protected]5c7d5982010-07-12 09:12:59123 virtual void OnContentBlocked(int host_id,
124 const GURL& manifest_url) = 0;
[email protected]53c570b2010-06-18 02:02:05125 virtual void OnLogMessage(int host_id, LogLevel log_level,
126 const std::string& message) = 0;
[email protected]f430b5712009-08-21 21:46:31127 virtual ~AppCacheFrontend() {}
128};
129
[email protected]19251af2010-05-13 18:24:46130// Interface used by frontend (renderer) to talk to backend (browser-process).
[email protected]4cea3542012-10-23 04:18:40131class WEBKIT_STORAGE_EXPORT AppCacheBackend {
[email protected]f430b5712009-08-21 21:46:31132 public:
133 virtual void RegisterHost(int host_id) = 0;
134 virtual void UnregisterHost(int host_id) = 0;
[email protected]e16b8af72011-03-21 22:11:42135 virtual void SetSpawningHostId(int host_id, int spawning_host_id) = 0;
[email protected]f430b5712009-08-21 21:46:31136 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]19251af2010-05-13 18:24:46140 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]f430b5712009-08-21 21:46:31147 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]ec5c1922010-07-28 03:14:37152 virtual void GetResourceList(
153 int host_id, std::vector<AppCacheResourceInfo>* resource_infos) = 0;
[email protected]f430b5712009-08-21 21:46:31154
[email protected]7ee2e882012-06-04 08:54:10155 protected:
[email protected]f430b5712009-08-21 21:46:31156 virtual ~AppCacheBackend() {}
157};
158
[email protected]7e8e3dd2009-09-18 01:05:09159// 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.
163extern const char kHttpScheme[];
164extern const char kHttpsScheme[];
165extern const char kHttpGETMethod[];
166extern const char kHttpHEADMethod[];
167
168bool IsSchemeSupported(const GURL& url);
169bool IsMethodSupported(const std::string& method);
[email protected]edfe7fab2010-11-28 13:11:52170bool IsSchemeAndMethodSupported(const net::URLRequest* request);
[email protected]7e8e3dd2009-09-18 01:05:09171
[email protected]a3ef4832013-02-02 05:12:33172WEBKIT_STORAGE_EXPORT extern const base::FilePath::CharType
173 kAppCacheDatabaseName[];
[email protected]4cccc222010-04-02 22:12:56174
[email protected]f430b5712009-08-21 21:46:31175} // namespace
176
177#endif // WEBKIT_APPCACHE_APPCACHE_INTERFACES_H_