Allow overlapping sync and async startup requests
[chromium-blink-merge.git] / webkit / common / appcache / appcache_interfaces.cc
blob07034513f3942b163f35a30159f25b61fcabcc34
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 #include "webkit/common/appcache/appcache_interfaces.h"
7 #include <set>
9 #include "base/lazy_instance.h"
10 #include "base/strings/string_util.h"
11 #include "net/url_request/url_request.h"
12 #include "url/gurl.h"
14 namespace {
16 base::LazyInstance<std::set<std::string> >::Leaky g_supported_schemes =
17 LAZY_INSTANCE_INITIALIZER;
19 } // namespace
21 namespace appcache {
23 const char kHttpScheme[] = "http";
24 const char kHttpsScheme[] = "https";
25 const char kHttpGETMethod[] = "GET";
26 const char kHttpHEADMethod[] = "HEAD";
28 const char kEnableExecutableHandlers[] = "enable-appcache-executable-handlers";
30 const base::FilePath::CharType kAppCacheDatabaseName[] =
31 FILE_PATH_LITERAL("Index");
33 AppCacheInfo::AppCacheInfo()
34 : cache_id(kNoCacheId),
35 group_id(0),
36 status(UNCACHED),
37 size(0),
38 is_complete(false) {
41 AppCacheInfo::~AppCacheInfo() {
44 AppCacheResourceInfo::AppCacheResourceInfo()
45 : url(),
46 size(0),
47 is_master(false),
48 is_manifest(false),
49 is_intercept(false),
50 is_fallback(false),
51 is_foreign(false),
52 is_explicit(false),
53 response_id(kNoResponseId) {
56 AppCacheResourceInfo::~AppCacheResourceInfo() {
59 Namespace::Namespace()
60 : type(FALLBACK_NAMESPACE),
61 is_pattern(false),
62 is_executable(false) {
65 Namespace::Namespace(
66 NamespaceType type, const GURL& url, const GURL& target, bool is_pattern)
67 : type(type),
68 namespace_url(url),
69 target_url(target),
70 is_pattern(is_pattern),
71 is_executable(false) {
74 Namespace::Namespace(
75 NamespaceType type, const GURL& url, const GURL& target,
76 bool is_pattern, bool is_executable)
77 : type(type),
78 namespace_url(url),
79 target_url(target),
80 is_pattern(is_pattern),
81 is_executable(is_executable) {
84 Namespace::~Namespace() {
87 bool Namespace::IsMatch(const GURL& url) const {
88 if (is_pattern) {
89 // We have to escape '?' characters since MatchPattern also treats those
90 // as wildcards which we don't want here, we only do '*'s.
91 std::string pattern = namespace_url.spec();
92 if (namespace_url.has_query())
93 ReplaceSubstringsAfterOffset(&pattern, 0, "?", "\\?");
94 return MatchPattern(url.spec(), pattern);
96 return StartsWithASCII(url.spec(), namespace_url.spec(), true);
99 void AddSupportedScheme(const char* scheme) {
100 g_supported_schemes.Get().insert(scheme);
103 bool IsSchemeSupported(const GURL& url) {
104 bool supported = url.SchemeIs(kHttpScheme) || url.SchemeIs(kHttpsScheme) ||
105 (!(g_supported_schemes == NULL) &&
106 g_supported_schemes.Get().find(url.scheme()) !=
107 g_supported_schemes.Get().end());
109 #ifndef NDEBUG
110 // TODO(michaeln): It would be really nice if this could optionally work for
111 // file and filesystem urls too to help web developers experiment and test
112 // their apps, perhaps enabled via a cmd line flag or some other developer
113 // tool setting. Unfortunately file scheme net::URLRequests don't produce the
114 // same signalling (200 response codes, headers) as http URLRequests, so this
115 // doesn't work just yet.
116 // supported |= url.SchemeIsFile();
117 #endif
118 return supported;
121 bool IsMethodSupported(const std::string& method) {
122 return (method == kHttpGETMethod) || (method == kHttpHEADMethod);
125 bool IsSchemeAndMethodSupported(const net::URLRequest* request) {
126 return IsSchemeSupported(request->url()) &&
127 IsMethodSupported(request->method());
130 } // namespace appcache