Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / browsing_data / browsing_data_appcache_helper.h
1 // Copyright (c) 2012 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_BROWSING_DATA_APPCACHE_HELPER_H_
6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_APPCACHE_HELPER_H_
7
8 #include <map>
9
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "content/public/browser/appcache_service.h"
13 #include "net/base/completion_callback.h"
14 #include "url/gurl.h"
15
16 class Profile;
17
18 namespace content {
19 class AppCacheService;
20 }
21
22 // This class fetches appcache information on behalf of a caller
23 // on the UI thread.
24 class BrowsingDataAppCacheHelper
25     : public base::RefCountedThreadSafe<BrowsingDataAppCacheHelper> {
26  public:
27   typedef std::map<GURL, content::AppCacheInfoVector> OriginAppCacheInfoMap;
28
29   explicit BrowsingDataAppCacheHelper(Profile* profile);
30
31   virtual void StartFetching(const base::Closure& completion_callback);
32   virtual void DeleteAppCacheGroup(const GURL& manifest_url);
33
34   content::AppCacheInfoCollection* info_collection() const {
35     DCHECK(!is_fetching_);
36     return info_collection_.get();
37   }
38
39  protected:
40   friend class base::RefCountedThreadSafe<BrowsingDataAppCacheHelper>;
41   virtual ~BrowsingDataAppCacheHelper();
42
43   base::Closure completion_callback_;
44   scoped_refptr<content::AppCacheInfoCollection> info_collection_;
45
46  private:
47   void OnFetchComplete(int rv);
48
49   bool is_fetching_;
50   content::AppCacheService* appcache_service_;
51   net::CancelableCompletionCallback appcache_info_callback_;
52
53   DISALLOW_COPY_AND_ASSIGN(BrowsingDataAppCacheHelper);
54 };
55
56 // This class is a thin wrapper around BrowsingDataAppCacheHelper that does not
57 // fetch its information from the appcache service, but gets them passed as
58 // a parameter during construction.
59 class CannedBrowsingDataAppCacheHelper : public BrowsingDataAppCacheHelper {
60  public:
61   explicit CannedBrowsingDataAppCacheHelper(Profile* profile);
62
63   // Return a copy of the appcache helper. Only one consumer can use the
64   // StartFetching method at a time, so we need to create a copy of the helper
65   // every time we instantiate a cookies tree model for it.
66   CannedBrowsingDataAppCacheHelper* Clone();
67
68   // Add an appcache to the set of canned caches that is returned by this
69   // helper.
70   void AddAppCache(const GURL& manifest_url);
71
72   // Clears the list of canned caches.
73   void Reset();
74
75   // True if no appcaches are currently stored.
76   bool empty() const;
77
78   // Returns the number of app cache resources.
79   size_t GetAppCacheCount() const;
80
81   // Returns a current map with the |AppCacheInfoVector|s per origin.
82   const OriginAppCacheInfoMap& GetOriginAppCacheInfoMap() const;
83
84   // BrowsingDataAppCacheHelper methods.
85   virtual void StartFetching(const base::Closure& completion_callback) OVERRIDE;
86   virtual void DeleteAppCacheGroup(const GURL& manifest_url) OVERRIDE;
87
88  private:
89   virtual ~CannedBrowsingDataAppCacheHelper();
90
91   Profile* profile_;
92
93   DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataAppCacheHelper);
94 };
95
96 #endif  // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_APPCACHE_HELPER_H_