OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/browser/appcache/chrome_appcache_service.h" | 5 #include "content/browser/appcache/chrome_appcache_service.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "content/public/browser/content_browser_client.h" | 9 #include "content/public/browser/content_browser_client.h" |
10 #include "content/public/browser/resource_context.h" | 10 #include "content/public/browser/resource_context.h" |
11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 #include "net/url_request/url_request_context_getter.h" |
| 13 #include "webkit/appcache/appcache_storage_impl.h" |
12 #include "webkit/quota/quota_manager.h" | 14 #include "webkit/quota/quota_manager.h" |
13 | 15 |
14 using content::BrowserThread; | 16 using content::BrowserThread; |
15 | 17 |
16 ChromeAppCacheService::ChromeAppCacheService( | 18 ChromeAppCacheService::ChromeAppCacheService( |
17 quota::QuotaManagerProxy* quota_manager_proxy) | 19 quota::QuotaManagerProxy* quota_manager_proxy) |
18 : AppCacheService(quota_manager_proxy), | 20 : AppCacheService(quota_manager_proxy), |
19 resource_context_(NULL) { | 21 resource_context_(NULL) { |
20 } | 22 } |
21 | 23 |
22 void ChromeAppCacheService::InitializeOnIOThread( | 24 void ChromeAppCacheService::InitializeOnIOThread( |
23 const FilePath& cache_path, | 25 const FilePath& cache_path, |
24 content::ResourceContext* resource_context, | 26 content::ResourceContext* resource_context, |
| 27 net::URLRequestContextGetter* request_context_getter, |
25 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { | 28 scoped_refptr<quota::SpecialStoragePolicy> special_storage_policy) { |
26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
27 | 30 |
28 cache_path_ = cache_path; | 31 cache_path_ = cache_path; |
29 resource_context_ = resource_context; | 32 resource_context_ = resource_context; |
30 set_request_context(resource_context->GetRequestContext()); | 33 if (request_context_getter) |
| 34 set_request_context(request_context_getter->GetURLRequestContext()); |
31 | 35 |
32 // Init our base class. | 36 // Init our base class. |
33 Initialize( | 37 Initialize( |
34 cache_path_, | 38 cache_path_, |
35 BrowserThread::GetMessageLoopProxyForThread( | 39 BrowserThread::GetMessageLoopProxyForThread( |
36 BrowserThread::FILE_USER_BLOCKING), | 40 BrowserThread::FILE_USER_BLOCKING), |
37 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); | 41 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); |
38 set_appcache_policy(this); | 42 set_appcache_policy(this); |
39 set_special_storage_policy(special_storage_policy); | 43 set_special_storage_policy(special_storage_policy); |
| 44 |
| 45 if (!request_context()) |
| 46 static_cast<appcache::AppCacheStorageImpl*>(storage())->Disable(); |
40 } | 47 } |
41 | 48 |
42 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url, | 49 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url, |
43 const GURL& first_party) { | 50 const GURL& first_party) { |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
45 // We don't prompt for read access. | 52 // We don't prompt for read access. |
46 return content::GetContentClient()->browser()->AllowAppCache( | 53 return content::GetContentClient()->browser()->AllowAppCache( |
47 manifest_url, first_party, resource_context_); | 54 manifest_url, first_party, resource_context_); |
48 } | 55 } |
49 | 56 |
50 bool ChromeAppCacheService::CanCreateAppCache( | 57 bool ChromeAppCacheService::CanCreateAppCache( |
51 const GURL& manifest_url, const GURL& first_party) { | 58 const GURL& manifest_url, const GURL& first_party) { |
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
53 return content::GetContentClient()->browser()->AllowAppCache( | 60 return content::GetContentClient()->browser()->AllowAppCache( |
54 manifest_url, first_party, resource_context_); | 61 manifest_url, first_party, resource_context_); |
55 } | 62 } |
56 | 63 |
57 ChromeAppCacheService::~ChromeAppCacheService() {} | 64 ChromeAppCacheService::~ChromeAppCacheService() {} |
58 | 65 |
59 void ChromeAppCacheService::DeleteOnCorrectThread() const { | 66 void ChromeAppCacheService::DeleteOnCorrectThread() const { |
60 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && | 67 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO) && |
61 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 68 !BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
62 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); | 69 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this); |
63 return; | 70 return; |
64 } | 71 } |
65 delete this; | 72 delete this; |
66 } | 73 } |
OLD | NEW |