• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_BROWSING_DATA_APPCACHE_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_APPCACHE_HELPER_H_
7 #pragma once
8 
9 #include "base/memory/scoped_ptr.h"
10 #include "base/task.h"
11 #include "content/browser/appcache/chrome_appcache_service.h"
12 #include "googleurl/src/gurl.h"
13 #include "net/url_request/url_request_context_getter.h"
14 
15 class Profile;
16 
17 // This class fetches appcache information on behalf of a caller
18 // on the UI thread.
19 class BrowsingDataAppCacheHelper
20     : public base::RefCountedThreadSafe<BrowsingDataAppCacheHelper> {
21  public:
22   explicit BrowsingDataAppCacheHelper(Profile* profile);
23 
24   virtual void StartFetching(Callback0::Type* completion_callback);
25   virtual void CancelNotification();
26   virtual void DeleteAppCacheGroup(const GURL& manifest_url);
27 
info_collection()28   appcache::AppCacheInfoCollection* info_collection() const {
29     DCHECK(!is_fetching_);
30     return info_collection_;
31   }
32 
33  protected:
34   friend class base::RefCountedThreadSafe<BrowsingDataAppCacheHelper>;
35   virtual ~BrowsingDataAppCacheHelper();
36 
37   scoped_ptr<Callback0::Type> completion_callback_;
38   scoped_refptr<appcache::AppCacheInfoCollection> info_collection_;
39 
40  private:
41   void OnFetchComplete(int rv);
42   ChromeAppCacheService* GetAppCacheService();
43 
44   scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
45   bool is_fetching_;
46   scoped_refptr<net::CancelableCompletionCallback<BrowsingDataAppCacheHelper> >
47       appcache_info_callback_;
48 
49   DISALLOW_COPY_AND_ASSIGN(BrowsingDataAppCacheHelper);
50 };
51 
52 // This class is a thin wrapper around BrowsingDataAppCacheHelper that does not
53 // fetch its information from the appcache service, but gets them passed as
54 // a parameter during construction.
55 class CannedBrowsingDataAppCacheHelper : public BrowsingDataAppCacheHelper {
56  public:
57   explicit CannedBrowsingDataAppCacheHelper(Profile* profile);
58 
59   // Return a copy of the appcache helper. Only one consumer can use the
60   // StartFetching method at a time, so we need to create a copy of the helper
61   // everytime we instantiate a cookies tree model for it.
62   CannedBrowsingDataAppCacheHelper* Clone();
63 
64   // Add an appcache to the set of canned caches that is returned by this
65   // helper.
66   void AddAppCache(const GURL& manifest_url);
67 
68   // Clears the list of canned caches.
69   void Reset();
70 
71   // True if no appcaches are currently stored.
72   bool empty() const;
73 
74   // BrowsingDataAppCacheHelper methods.
75   virtual void StartFetching(Callback0::Type* completion_callback);
CancelNotification()76   virtual void CancelNotification() {}
77 
78  private:
79   virtual ~CannedBrowsingDataAppCacheHelper();
80 
81   Profile* profile_;
82 
83   DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataAppCacheHelper);
84 };
85 
86 #endif  // CHROME_BROWSER_BROWSING_DATA_APPCACHE_HELPER_H_
87