summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browsing_data_appcache_helper.cc
blob: c0d7cedd2fa8b533c53530b691367f9013700166 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/browsing_data_appcache_helper.h"

BrowsingDataAppCacheHelper::BrowsingDataAppCacheHelper(Profile* profile)
    : is_fetching_(false) {
}

void BrowsingDataAppCacheHelper::StartFetching(Callback0::Type* callback) {
  DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
  DCHECK(!is_fetching_);
  DCHECK(callback);
  is_fetching_ = true;
  info_list_.clear();
  completion_callback_.reset(callback);
  ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, NewRunnableMethod(
      this, &BrowsingDataAppCacheHelper::StartFetchingInIOThread));
}

void BrowsingDataAppCacheHelper::CancelNotification() {
  DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
  completion_callback_.reset();
}

void BrowsingDataAppCacheHelper::DeleteAppCache(int64 group_id) {
  DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
  ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, NewRunnableMethod(
      this, &BrowsingDataAppCacheHelper::DeleteAppCacheInIOThread,
      group_id));
}

void BrowsingDataAppCacheHelper::StartFetchingInIOThread() {
  DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));

#ifndef NDEBUG
  // TODO(michaeln): get real data from the appcache service
  info_list_.push_back(
      AppCacheInfo(GURL("http://bogus/manifest"),
      1 * 1024 * 1024, base::Time::Now(), base::Time::Now(), 1));
  info_list_.push_back(
      AppCacheInfo(GURL("https://bogus/manifest"),
      2 * 1024 * 1024, base::Time::Now(), base::Time::Now(), 2));
  info_list_.push_back(
      AppCacheInfo(GURL("http://bogus:8080/manifest"),
      3 * 1024 * 1024, base::Time::Now(), base::Time::Now(), 3));
#endif

  ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, NewRunnableMethod(
      this, &BrowsingDataAppCacheHelper::OnFetchComplete));
}

void BrowsingDataAppCacheHelper::OnFetchComplete() {
  DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
  DCHECK(is_fetching_);
  is_fetching_ = false;
  if (completion_callback_ != NULL) {
    completion_callback_->Run();
    completion_callback_.reset();
  }
}

void BrowsingDataAppCacheHelper::DeleteAppCacheInIOThread(
    int64 group_id) {
  DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
  // TODO(michaeln): plumb to the appcache service
}