blob: c0d7cedd2fa8b533c53530b691367f9013700166 [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"
6
7BrowsingDataAppCacheHelper::BrowsingDataAppCacheHelper(Profile* profile)
8 : is_fetching_(false) {
9}
10
11void BrowsingDataAppCacheHelper::StartFetching(Callback0::Type* callback) {
12 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
13 DCHECK(!is_fetching_);
14 DCHECK(callback);
15 is_fetching_ = true;
16 info_list_.clear();
17 completion_callback_.reset(callback);
18 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, NewRunnableMethod(
19 this, &BrowsingDataAppCacheHelper::StartFetchingInIOThread));
20}
21
22void BrowsingDataAppCacheHelper::CancelNotification() {
23 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
24 completion_callback_.reset();
25}
26
27void BrowsingDataAppCacheHelper::DeleteAppCache(int64 group_id) {
28 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
29 ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, NewRunnableMethod(
30 this, &BrowsingDataAppCacheHelper::DeleteAppCacheInIOThread,
31 group_id));
32}
33
34void BrowsingDataAppCacheHelper::StartFetchingInIOThread() {
35 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
36
37#ifndef NDEBUG
38 // TODO(michaeln): get real data from the appcache service
39 info_list_.push_back(
40 AppCacheInfo(GURL("http://bogus/manifest"),
41 1 * 1024 * 1024, base::Time::Now(), base::Time::Now(), 1));
42 info_list_.push_back(
43 AppCacheInfo(GURL("https://bogus/manifest"),
44 2 * 1024 * 1024, base::Time::Now(), base::Time::Now(), 2));
45 info_list_.push_back(
46 AppCacheInfo(GURL("http://bogus:8080/manifest"),
47 3 * 1024 * 1024, base::Time::Now(), base::Time::Now(), 3));
48#endif
49
50 ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, NewRunnableMethod(
51 this, &BrowsingDataAppCacheHelper::OnFetchComplete));
52}
53
54void BrowsingDataAppCacheHelper::OnFetchComplete() {
55 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
56 DCHECK(is_fetching_);
57 is_fetching_ = false;
58 if (completion_callback_ != NULL) {
59 completion_callback_->Run();
60 completion_callback_.reset();
61 }
62}
63
64void BrowsingDataAppCacheHelper::DeleteAppCacheInIOThread(
65 int64 group_id) {
66 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
67 // TODO(michaeln): plumb to the appcache service
68}