service_worker_utils.h revision 116680a4aac90f2aa7413d9095a592090648e557
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 3// found in the LICENSE file. 4 5#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ 6#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ 7 8#include "content/common/content_export.h" 9#include "content/common/service_worker/service_worker_status_code.h" 10#include "content/public/common/resource_type.h" 11 12class GURL; 13 14namespace content { 15 16class ServiceWorkerUtils { 17 public: 18 static bool IsMainResourceType(ResourceType::Type type) { 19 return ResourceType::IsFrame(type) || 20 ResourceType::IsSharedWorker(type); 21 } 22 23 static bool IsServiceWorkerResourceType(ResourceType::Type type) { 24 return ResourceType::IsServiceWorker(type); 25 } 26 27 // A helper for creating a do-nothing status callback. 28 static void NoOpStatusCallback(ServiceWorkerStatusCode status) {} 29 30 // Returns true if |scope| matches |url|. 31 CONTENT_EXPORT static bool ScopeMatches(const GURL& scope, const GURL& url); 32}; 33 34class CONTENT_EXPORT LongestScopeMatcher { 35 public: 36 explicit LongestScopeMatcher(const GURL& url) : url_(url) {} 37 virtual ~LongestScopeMatcher() {} 38 39 // Returns true if |scope| matches |url_| longer than |match_|. 40 bool MatchLongest(const GURL& scope); 41 42 private: 43 const GURL url_; 44 GURL match_; 45 46 DISALLOW_COPY_AND_ASSIGN(LongestScopeMatcher); 47}; 48 49} // namespace content 50 51#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_UTILS_H_ 52