Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / webkit / appcache / appcache_interfaces.h
blob0dfa4c45a3fbcff78dc2047579aa314769404dc4
1 // Copyright (c) 2012 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.
5 #ifndef WEBKIT_APPCACHE_APPCACHE_INTERFACES_H_
6 #define WEBKIT_APPCACHE_APPCACHE_INTERFACES_H_
8 #include <string>
9 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/files/file_path.h"
12 #include "base/time.h"
13 #include "googleurl/src/gurl.h"
14 #include "webkit/storage/webkit_storage_export.h"
16 namespace net {
17 class URLRequest;
18 } // namespace net
20 namespace appcache {
22 // Defines constants, types, and abstract classes used in the main
23 // process and in child processes.
25 static const int kNoHostId = 0;
26 static const int64 kNoCacheId = 0;
27 static const int64 kNoResponseId = 0;
28 static const int64 kUnknownCacheId = -1;
30 enum Status {
31 UNCACHED,
32 IDLE,
33 CHECKING,
34 DOWNLOADING,
35 UPDATE_READY,
36 OBSOLETE
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
50 // Temporarily renumber them in wierd way, to help remove LOG_TIP from WebKit
51 enum LogLevel {
52 LOG_DEBUG = 4,
53 LOG_INFO = 1,
54 LOG_WARNING = 2,
55 LOG_ERROR = 3,
58 enum NamespaceType {
59 FALLBACK_NAMESPACE,
60 INTERCEPT_NAMESPACE,
61 NETWORK_NAMESPACE
64 struct WEBKIT_STORAGE_EXPORT AppCacheInfo {
65 AppCacheInfo();
66 ~AppCacheInfo();
68 GURL manifest_url;
69 base::Time creation_time;
70 base::Time last_update_time;
71 base::Time last_access_time;
72 int64 cache_id;
73 int64 group_id;
74 Status status;
75 int64 size;
76 bool is_complete;
79 typedef std::vector<AppCacheInfo> AppCacheInfoVector;
81 // Type to hold information about a single appcache resource.
82 struct WEBKIT_STORAGE_EXPORT AppCacheResourceInfo {
83 AppCacheResourceInfo();
84 ~AppCacheResourceInfo();
86 GURL url;
87 int64 size;
88 bool is_master;
89 bool is_manifest;
90 bool is_intercept;
91 bool is_fallback;
92 bool is_foreign;
93 bool is_explicit;
94 int64 response_id;
97 typedef std::vector<AppCacheResourceInfo> AppCacheResourceInfoVector;
99 struct WEBKIT_STORAGE_EXPORT Namespace {
100 Namespace(); // Type is set to FALLBACK_NAMESPACE by default.
101 Namespace(NamespaceType type, const GURL& url, const GURL& target,
102 bool is_pattern);
103 ~Namespace();
105 bool IsMatch(const GURL& url) const;
107 NamespaceType type;
108 GURL namespace_url;
109 GURL target_url;
110 bool is_pattern;
113 typedef std::vector<Namespace> NamespaceVector;
115 // Interface used by backend (browser-process) to talk to frontend (renderer).
116 class WEBKIT_STORAGE_EXPORT AppCacheFrontend {
117 public:
118 virtual void OnCacheSelected(
119 int host_id, const appcache::AppCacheInfo& info) = 0;
120 virtual void OnStatusChanged(const std::vector<int>& host_ids,
121 Status status) = 0;
122 virtual void OnEventRaised(const std::vector<int>& host_ids,
123 EventID event_id) = 0;
124 virtual void OnProgressEventRaised(const std::vector<int>& host_ids,
125 const GURL& url,
126 int num_total, int num_complete) = 0;
127 virtual void OnErrorEventRaised(const std::vector<int>& host_ids,
128 const std::string& message) = 0;
129 virtual void OnContentBlocked(int host_id,
130 const GURL& manifest_url) = 0;
131 virtual void OnLogMessage(int host_id, LogLevel log_level,
132 const std::string& message) = 0;
133 virtual ~AppCacheFrontend() {}
136 // Interface used by frontend (renderer) to talk to backend (browser-process).
137 class WEBKIT_STORAGE_EXPORT AppCacheBackend {
138 public:
139 virtual void RegisterHost(int host_id) = 0;
140 virtual void UnregisterHost(int host_id) = 0;
141 virtual void SetSpawningHostId(int host_id, int spawning_host_id) = 0;
142 virtual void SelectCache(int host_id,
143 const GURL& document_url,
144 const int64 cache_document_was_loaded_from,
145 const GURL& manifest_url) = 0;
146 virtual void SelectCacheForWorker(
147 int host_id,
148 int parent_process_id,
149 int parent_host_id) = 0;
150 virtual void SelectCacheForSharedWorker(
151 int host_id,
152 int64 appcache_id) = 0;
153 virtual void MarkAsForeignEntry(int host_id, const GURL& document_url,
154 int64 cache_document_was_loaded_from) = 0;
155 virtual Status GetStatus(int host_id) = 0;
156 virtual bool StartUpdate(int host_id) = 0;
157 virtual bool SwapCache(int host_id) = 0;
158 virtual void GetResourceList(
159 int host_id, std::vector<AppCacheResourceInfo>* resource_infos) = 0;
161 protected:
162 virtual ~AppCacheBackend() {}
165 // Useful string constants.
166 // Note: These are also defined elsewhere in the chrome code base in
167 // url_contants.h .cc, however the appcache library doesn't not have
168 // any dependencies on the chrome library, so we can't use them in here.
169 extern const char kHttpScheme[];
170 extern const char kHttpsScheme[];
171 extern const char kHttpGETMethod[];
172 extern const char kHttpHEADMethod[];
174 WEBKIT_STORAGE_EXPORT void AddSupportedScheme(const char* scheme);
176 bool IsSchemeSupported(const GURL& url);
177 bool IsMethodSupported(const std::string& method);
178 bool IsSchemeAndMethodSupported(const net::URLRequest* request);
180 WEBKIT_STORAGE_EXPORT extern const base::FilePath::CharType
181 kAppCacheDatabaseName[];
183 } // namespace
185 #endif // WEBKIT_APPCACHE_APPCACHE_INTERFACES_H_