blob: 9e62809b0a7fd487c8305818e5c11e0b13f26743 [file] [log] [blame]
[email protected]f26795eb2010-02-26 23:45:351// 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]d68a4fc62010-03-05 23:40:026#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
11using appcache::AppCacheDatabase;
[email protected]f26795eb2010-02-26 23:45:3512
13BrowsingDataAppCacheHelper::BrowsingDataAppCacheHelper(Profile* profile)
[email protected]d68a4fc62010-03-05 23:40:0214 : request_context_getter_(profile->GetRequestContext()),
15 is_fetching_(false) {
16 DCHECK(request_context_getter_.get());
[email protected]f26795eb2010-02-26 23:45:3517}
18
19void BrowsingDataAppCacheHelper::StartFetching(Callback0::Type* callback) {
[email protected]d68a4fc62010-03-05 23:40:0220 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]f26795eb2010-02-26 23:45:3537}
38
39void BrowsingDataAppCacheHelper::CancelNotification() {
[email protected]d68a4fc62010-03-05 23:40:0240 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]f26795eb2010-02-26 23:45:3549}
50
[email protected]d68a4fc62010-03-05 23:40:0251void 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]f26795eb2010-02-26 23:45:3560}
61
[email protected]d68a4fc62010-03-05 23:40:0262void 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]f26795eb2010-02-26 23:45:3569
[email protected]f26795eb2010-02-26 23:45:3570 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]d68a4fc62010-03-05 23:40:0279ChromeAppCacheService* BrowsingDataAppCacheHelper::GetAppCacheService() {
[email protected]f26795eb2010-02-26 23:45:3580 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
[email protected]d68a4fc62010-03-05 23:40:0281 ChromeURLRequestContext* request_context =
82 reinterpret_cast<ChromeURLRequestContext*>(
83 request_context_getter_->GetURLRequestContext());
84 return request_context ? request_context->appcache_service()
85 : NULL;
[email protected]f26795eb2010-02-26 23:45:3586}