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.
5 #include "content/browser/appcache/chrome_appcache_service.h"
7 #include "base/files/file_path.h"
8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/content_browser_client.h"
10 #include "content/public/browser/resource_context.h"
11 #include "net/base/net_errors.h"
12 #include "net/url_request/url_request_context_getter.h"
13 #include "webkit/browser/appcache/appcache_storage_impl.h"
14 #include "webkit/browser/quota/quota_manager.h"
18 ChromeAppCacheService::ChromeAppCacheService(
19 quota::QuotaManagerProxy* quota_manager_proxy)
20 : AppCacheService(quota_manager_proxy),
21 resource_context_(NULL) {
24 void ChromeAppCacheService::InitializeOnIOThread(
25 const base::FilePath& cache_path,
26 ResourceContext* resource_context,
27 net::URLRequestContextGetter* request_context_getter,
28 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
31 cache_path_ = cache_path;
32 resource_context_ = resource_context;
34 // The |request_context_getter| can be NULL in some unit tests.
36 // TODO(ajwong): TestProfile is difficult to work with. The
37 // SafeBrowsing tests require that GetRequestContext return NULL
38 // so we can't depend on having a non-NULL value here. See crbug/149783.
39 if (request_context_getter)
40 set_request_context(request_context_getter->GetURLRequestContext());
42 // Init our base class.
45 BrowserThread::GetMessageLoopProxyForThread(
46 BrowserThread::FILE_USER_BLOCKING)
48 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE).get());
49 set_appcache_policy(this);
50 set_special_storage_policy(special_storage_policy.get());
53 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url,
54 const GURL& first_party) {
55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
56 // We don't prompt for read access.
57 return GetContentClient()->browser()->AllowAppCache(
58 manifest_url, first_party, resource_context_);
61 bool ChromeAppCacheService::CanCreateAppCache(
62 const GURL& manifest_url, const GURL& first_party) {
63 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
64 return GetContentClient()->browser()->AllowAppCache(
65 manifest_url, first_party, resource_context_);
68 ChromeAppCacheService::~ChromeAppCacheService() {}
70 void ChromeAppCacheService::DeleteOnCorrectThread() const {
71 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) {
75 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
76 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this);
79 // Better to leak than crash on shutdown.
82 } // namespace content