chrome_appcache_service.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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. 4 5#ifndef CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ 6#define CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ 7 8#include "base/compiler_specific.h" 9#include "base/memory/ref_counted.h" 10#include "base/sequenced_task_runner_helpers.h" 11#include "content/common/content_export.h" 12#include "webkit/appcache/appcache_policy.h" 13#include "webkit/appcache/appcache_service.h" 14#include "webkit/quota/special_storage_policy.h" 15 16namespace base { 17class FilePath; 18} 19 20namespace net { 21class URLRequestContextGetter; 22} 23 24namespace content { 25class ResourceContext; 26 27struct ChromeAppCacheServiceDeleter; 28 29// An AppCacheService subclass used by the chrome. There is an instance 30// associated with each BrowserContext. This derivation adds refcounting 31// semantics since a browser context has multiple URLRequestContexts which refer 32// to the same object, and those URLRequestContexts are refcounted independently 33// of the owning browser context. 34// 35// All methods, except the ctor, are expected to be called on 36// the IO thread (unless specifically called out in doc comments). 37// 38// TODO(dpranke): Fix dependencies on AppCacheService so that we don't have 39// to worry about clients calling AppCacheService methods. 40class CONTENT_EXPORT ChromeAppCacheService 41 : public base::RefCountedThreadSafe<ChromeAppCacheService, 42 ChromeAppCacheServiceDeleter>, 43 NON_EXPORTED_BASE(public appcache::AppCacheService), 44 NON_EXPORTED_BASE(public appcache::AppCachePolicy) { 45 public: 46 explicit ChromeAppCacheService(quota::QuotaManagerProxy* proxy); 47 48 void InitializeOnIOThread( 49 const base::FilePath& cache_path, // May be empty to use in-memory structs. 50 ResourceContext* resource_context, 51 net::URLRequestContextGetter* request_context_getter, 52 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy); 53 54 // AppCachePolicy overrides 55 virtual bool CanLoadAppCache(const GURL& manifest_url, 56 const GURL& first_party) OVERRIDE; 57 virtual bool CanCreateAppCache(const GURL& manifest_url, 58 const GURL& first_party) OVERRIDE; 59 60 protected: 61 virtual ~ChromeAppCacheService(); 62 63 private: 64 friend class base::DeleteHelper<ChromeAppCacheService>; 65 friend class base::RefCountedThreadSafe<ChromeAppCacheService, 66 ChromeAppCacheServiceDeleter>; 67 friend struct ChromeAppCacheServiceDeleter; 68 69 void DeleteOnCorrectThread() const; 70 71 ResourceContext* resource_context_; 72 base::FilePath cache_path_; 73 74 DISALLOW_COPY_AND_ASSIGN(ChromeAppCacheService); 75}; 76 77struct ChromeAppCacheServiceDeleter { 78 static void Destruct(const ChromeAppCacheService* service) { 79 service->DeleteOnCorrectThread(); 80 } 81}; 82 83} // namespace content 84 85#endif // CONTENT_BROWSER_APPCACHE_CHROME_APPCACHE_SERVICE_H_ 86