Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / appcache / chrome_appcache_service.cc
blob11d107ce5a367369ceaee02f26b566871d20c915
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 "base/profiler/scoped_tracker.h"
9 #include "content/browser/appcache/appcache_storage_impl.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/content_browser_client.h"
12 #include "content/public/browser/resource_context.h"
13 #include "net/base/net_errors.h"
14 #include "net/url_request/url_request_context_getter.h"
15 #include "storage/browser/quota/quota_manager.h"
17 namespace content {
19 ChromeAppCacheService::ChromeAppCacheService(
20 storage::QuotaManagerProxy* quota_manager_proxy)
21 : AppCacheServiceImpl(quota_manager_proxy), 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<storage::SpecialStoragePolicy> special_storage_policy) {
29 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
30 tracked_objects::ScopedTracker tracking_profile(
31 FROM_HERE_WITH_EXPLICIT_FUNCTION(
32 "477117 ChromeAppCacheService::InitializeOnIOThread"));
33 DCHECK_CURRENTLY_ON(BrowserThread::IO);
35 cache_path_ = cache_path;
36 resource_context_ = resource_context;
38 // The |request_context_getter| can be NULL in some unit tests.
40 // TODO(ajwong): TestProfile is difficult to work with. The
41 // SafeBrowsing tests require that GetRequestContext return NULL
42 // so we can't depend on having a non-NULL value here. See crbug/149783.
43 if (request_context_getter)
44 set_request_context(request_context_getter->GetURLRequestContext());
46 // Init our base class.
47 Initialize(
48 cache_path_,
49 BrowserThread::GetMessageLoopProxyForThread(
50 BrowserThread::FILE_USER_BLOCKING)
51 .get(),
52 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE).get());
53 set_appcache_policy(this);
54 set_special_storage_policy(special_storage_policy.get());
57 bool ChromeAppCacheService::CanLoadAppCache(const GURL& manifest_url,
58 const GURL& first_party) {
59 DCHECK_CURRENTLY_ON(BrowserThread::IO);
60 // We don't prompt for read access.
61 return GetContentClient()->browser()->AllowAppCache(
62 manifest_url, first_party, resource_context_);
65 bool ChromeAppCacheService::CanCreateAppCache(
66 const GURL& manifest_url, const GURL& first_party) {
67 DCHECK_CURRENTLY_ON(BrowserThread::IO);
68 return GetContentClient()->browser()->AllowAppCache(
69 manifest_url, first_party, resource_context_);
72 ChromeAppCacheService::~ChromeAppCacheService() {}
74 void ChromeAppCacheService::DeleteOnCorrectThread() const {
75 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) {
76 delete this;
77 return;
79 if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) {
80 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, this);
81 return;
83 // Better to leak than crash on shutdown.
86 } // namespace content