OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ |
7 | 7 |
| 8 #include "base/macros.h" |
8 #include "content/common/content_export.h" | 9 #include "content/common/content_export.h" |
9 #include "content/common/service_worker/service_worker_status_code.h" | 10 #include "content/common/service_worker/service_worker_status_code.h" |
10 #include "content/public/common/resource_type.h" | 11 #include "content/public/common/resource_type.h" |
11 | 12 #include "url/gurl.h" |
12 class GURL; | |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 class ServiceWorkerUtils { | 16 class ServiceWorkerUtils { |
17 public: | 17 public: |
18 static bool IsMainResourceType(ResourceType::Type type) { | 18 static bool IsMainResourceType(ResourceType type) { |
19 return ResourceType::IsFrame(type) || | 19 return IsResourceTypeFrame(type) || type == RESOURCE_TYPE_SHARED_WORKER; |
20 ResourceType::IsSharedWorker(type); | |
21 } | |
22 | |
23 static bool IsServiceWorkerResourceType(ResourceType::Type type) { | |
24 return ResourceType::IsServiceWorker(type); | |
25 } | 20 } |
26 | 21 |
27 // A helper for creating a do-nothing status callback. | 22 // A helper for creating a do-nothing status callback. |
28 static void NoOpStatusCallback(ServiceWorkerStatusCode status) {} | 23 static void NoOpStatusCallback(ServiceWorkerStatusCode status) {} |
29 | 24 |
30 // Returns true if |scope| matches |url|. | 25 // Returns true if |scope| matches |url|. |
31 CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url); | 26 CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url); |
32 }; | 27 }; |
33 | 28 |
34 class CONTENT_EXPORT LongestScopeMatcher { | 29 class CONTENT_EXPORT LongestScopeMatcher { |
35 public: | 30 public: |
36 explicit LongestScopeMatcher(const GURL& url) : url_(url) {} | 31 explicit LongestScopeMatcher(const GURL& url) : url_(url) {} |
37 virtual ~LongestScopeMatcher() {} | 32 virtual ~LongestScopeMatcher() {} |
38 | 33 |
39 // Returns true if |scope| matches |url_| longer than |match_|. | 34 // Returns true if |scope| matches |url_| longer than |match_|. |
40 bool MatchLongest(const GURL& scope); | 35 bool MatchLongest(const GURL& scope); |
41 | 36 |
42 private: | 37 private: |
43 const GURL url_; | 38 const GURL url_; |
44 GURL match_; | 39 GURL match_; |
45 | 40 |
46 DISALLOW_COPY_AND_ASSIGN(LongestScopeMatcher); | 41 DISALLOW_COPY_AND_ASSIGN(LongestScopeMatcher); |
47 }; | 42 }; |
48 | 43 |
49 } // namespace content | 44 } // namespace content |
50 | 45 |
51 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ | 46 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ |
OLD | NEW |