| 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 "content/common/content_export.h" | 8 #include "content/common/content_export.h" |
| 9 #include "content/common/service_worker/service_worker_status_code.h" | 9 #include "content/common/service_worker/service_worker_status_code.h" |
| 10 #include "webkit/common/resource_type.h" | 10 #include "webkit/common/resource_type.h" |
| 11 | 11 |
| 12 class GURL; | 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 type) { |
| 19 return ResourceType::IsFrame(type) || | 19 return ResourceType::IsFrame(type) || |
| 20 ResourceType::IsSharedWorker(type); | 20 ResourceType::IsSharedWorker(type); |
| 21 } | 21 } |
| 22 | 22 |
| 23 static bool IsServiceWorkerResourceType(ResourceType::Type type) { | 23 static bool IsServiceWorkerResourceType(ResourceType::Type type) { |
| 24 return ResourceType::IsServiceWorker(type); | 24 return ResourceType::IsServiceWorker(type); |
| 25 } | 25 } |
| 26 | 26 |
| 27 // Returns true if the feature is enabled (or not disabled) by command-line | |
| 28 // flag. | |
| 29 static bool IsFeatureEnabled(); | |
| 30 | |
| 31 // A helper for creating a do-nothing status callback. | 27 // A helper for creating a do-nothing status callback. |
| 32 static void NoOpStatusCallback(ServiceWorkerStatusCode status) {} | 28 static void NoOpStatusCallback(ServiceWorkerStatusCode status) {} |
| 33 | 29 |
| 34 // Returns true if |scope| matches |url|. | 30 // Returns true if |scope| matches |url|. |
| 35 CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url); | 31 CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url); |
| 36 }; | 32 }; |
| 37 | 33 |
| 38 class CONTENT_EXPORT LongestScopeMatcher { | 34 class CONTENT_EXPORT LongestScopeMatcher { |
| 39 public: | 35 public: |
| 40 explicit LongestScopeMatcher(const GURL& url) : url_(url) {} | 36 explicit LongestScopeMatcher(const GURL& url) : url_(url) {} |
| 41 virtual ~LongestScopeMatcher() {} | 37 virtual ~LongestScopeMatcher() {} |
| 42 | 38 |
| 43 // Returns true if |scope| matches |url_| longer than |match_|. | 39 // Returns true if |scope| matches |url_| longer than |match_|. |
| 44 bool MatchLongest(const GURL& scope); | 40 bool MatchLongest(const GURL& scope); |
| 45 | 41 |
| 46 private: | 42 private: |
| 47 const GURL url_; | 43 const GURL url_; |
| 48 GURL match_; | 44 GURL match_; |
| 49 | 45 |
| 50 DISALLOW_COPY_AND_ASSIGN(LongestScopeMatcher); | 46 DISALLOW_COPY_AND_ASSIGN(LongestScopeMatcher); |
| 51 }; | 47 }; |
| 52 | 48 |
| 53 } // namespace content | 49 } // namespace content |
| 54 | 50 |
| 55 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ | 51 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ |
| OLD | NEW |