[email protected] | f26795eb | 2010-02-26 23:45:35 | [diff] [blame] | 1 | // Copyright (c) 2010 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 | #include "chrome/browser/browsing_data_appcache_helper.h" |
[email protected] | d68a4fc6 | 2010-03-05 23:40:02 | [diff] [blame^] | 6 | #include "chrome/browser/net/chrome_url_request_context.h" |
| 7 | #include "chrome/browser/profile.h" |
| 8 | #include "webkit/appcache/appcache_database.h" |
| 9 | #include "webkit/appcache/appcache_storage.h" |
| 10 | |
| 11 | using appcache::AppCacheDatabase; |
[email protected] | f26795eb | 2010-02-26 23:45:35 | [diff] [blame] | 12 | |
| 13 | BrowsingDataAppCacheHelper::BrowsingDataAppCacheHelper(Profile* profile) |
[email protected] | d68a4fc6 | 2010-03-05 23:40:02 | [diff] [blame^] | 14 | : request_context_getter_(profile->GetRequestContext()), |
| 15 | is_fetching_(false) { |
| 16 | DCHECK(request_context_getter_.get()); |
[email protected] | f26795eb | 2010-02-26 23:45:35 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | void BrowsingDataAppCacheHelper::StartFetching(Callback0::Type* callback) { |
[email protected] | d68a4fc6 | 2010-03-05 23:40:02 | [diff] [blame^] | 20 | if (ChromeThread::CurrentlyOn(ChromeThread::UI)) { |
| 21 | DCHECK(!is_fetching_); |
| 22 | DCHECK(callback); |
| 23 | is_fetching_ = true; |
| 24 | info_collection_ = new appcache::AppCacheInfoCollection; |
| 25 | completion_callback_.reset(callback); |
| 26 | ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, NewRunnableMethod( |
| 27 | this, &BrowsingDataAppCacheHelper::StartFetching, callback)); |
| 28 | return; |
| 29 | } |
| 30 | |
| 31 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 32 | appcache_info_callback_ = |
| 33 | new net::CancelableCompletionCallback<BrowsingDataAppCacheHelper>( |
| 34 | this, &BrowsingDataAppCacheHelper::OnFetchComplete); |
| 35 | GetAppCacheService()->GetAllAppCacheInfo(info_collection_, |
| 36 | appcache_info_callback_); |
[email protected] | f26795eb | 2010-02-26 23:45:35 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void BrowsingDataAppCacheHelper::CancelNotification() { |
[email protected] | d68a4fc6 | 2010-03-05 23:40:02 | [diff] [blame^] | 40 | if (ChromeThread::CurrentlyOn(ChromeThread::UI)) { |
| 41 | completion_callback_.reset(); |
| 42 | ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, NewRunnableMethod( |
| 43 | this, &BrowsingDataAppCacheHelper::CancelNotification)); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | if (appcache_info_callback_) |
| 48 | appcache_info_callback_.release()->Cancel(); |
[email protected] | f26795eb | 2010-02-26 23:45:35 | [diff] [blame] | 49 | } |
| 50 | |
[email protected] | d68a4fc6 | 2010-03-05 23:40:02 | [diff] [blame^] | 51 | void BrowsingDataAppCacheHelper::DeleteAppCacheGroup( |
| 52 | const GURL& manifest_url) { |
| 53 | if (ChromeThread::CurrentlyOn(ChromeThread::UI)) { |
| 54 | ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, NewRunnableMethod( |
| 55 | this, &BrowsingDataAppCacheHelper::DeleteAppCacheGroup, |
| 56 | manifest_url)); |
| 57 | return; |
| 58 | } |
| 59 | GetAppCacheService()->DeleteAppCacheGroup(manifest_url, NULL); |
[email protected] | f26795eb | 2010-02-26 23:45:35 | [diff] [blame] | 60 | } |
| 61 | |
[email protected] | d68a4fc6 | 2010-03-05 23:40:02 | [diff] [blame^] | 62 | void BrowsingDataAppCacheHelper::OnFetchComplete(int rv) { |
| 63 | if (ChromeThread::CurrentlyOn(ChromeThread::IO)) { |
| 64 | appcache_info_callback_ = NULL; |
| 65 | ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, NewRunnableMethod( |
| 66 | this, &BrowsingDataAppCacheHelper::OnFetchComplete, rv)); |
| 67 | return; |
| 68 | } |
[email protected] | f26795eb | 2010-02-26 23:45:35 | [diff] [blame] | 69 | |
[email protected] | f26795eb | 2010-02-26 23:45:35 | [diff] [blame] | 70 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 71 | DCHECK(is_fetching_); |
| 72 | is_fetching_ = false; |
| 73 | if (completion_callback_ != NULL) { |
| 74 | completion_callback_->Run(); |
| 75 | completion_callback_.reset(); |
| 76 | } |
| 77 | } |
| 78 | |
[email protected] | d68a4fc6 | 2010-03-05 23:40:02 | [diff] [blame^] | 79 | ChromeAppCacheService* BrowsingDataAppCacheHelper::GetAppCacheService() { |
[email protected] | f26795eb | 2010-02-26 23:45:35 | [diff] [blame] | 80 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | d68a4fc6 | 2010-03-05 23:40:02 | [diff] [blame^] | 81 | ChromeURLRequestContext* request_context = |
| 82 | reinterpret_cast<ChromeURLRequestContext*>( |
| 83 | request_context_getter_->GetURLRequestContext()); |
| 84 | return request_context ? request_context->appcache_service() |
| 85 | : NULL; |
[email protected] | f26795eb | 2010-02-26 23:45:35 | [diff] [blame] | 86 | } |