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