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