9f3d76a079df73b2ea426849ef2b5fc77ea4b130
[platform/framework/web/crosswalk-tizen.git] /
1 // Copyright 2014 Samsung Electronics. 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 BROWSING_DATA_MANAGER_EFL_H
6 #define BROWSING_DATA_MANAGER_EFL_H
7
8 #include <set>
9
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/time/time.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "content/public/browser/notification_registrar.h"
15 #include "storage/common/quota/quota_types.h"
16 #include "url/gurl.h"
17
18 namespace net {
19 class URLRequestContextGetter;
20 }
21 namespace content {
22 class AppCacheService;
23 class BrowserContext;
24 class DOMStorageContext;
25 struct LocalStorageUsageInfo;
26 class StoragePartition;
27 }
28 namespace disk_cache {
29 class Backend;
30 }
31 namespace storage {
32 class QuotaManager;
33 }
34 class BrowsingDataRemoverEfl {
35  public:
36   // Mask used for Remove.
37   enum RemoveDataMask {
38     REMOVE_LOCAL_STORAGE = 1 << 0,
39     REMOVE_INDEXEDDB     = 1 << 1,
40     REMOVE_WEBSQL        = 1 << 2,
41     REMOVE_FILE_SYSTEMS  = 1 << 3,
42     REMOVE_APPCACHE      = 1 << 4,
43   };
44
45   static BrowsingDataRemoverEfl* CreateForUnboundedRange(content::BrowserContext*);
46   static BrowsingDataRemoverEfl* CreateForRange(content::BrowserContext*, base::Time, base::Time);
47   void RemoveImpl(int, const GURL&);
48
49   virtual ~BrowsingDataRemoverEfl();
50   void ClearNetworkCache();
51
52   // deletes app cache for given origin
53   void DeleteAppCachesForOrigin(const GURL& origin);
54
55  protected:
56   BrowsingDataRemoverEfl(content::BrowserContext*, base::Time start, base::Time end);
57
58   // Quota managed data uses a different bitmask for types than
59   // BrowsingDataRemover uses. This method generates that mask.
60   static int GenerateQuotaClientMask(int);
61
62  private:
63   void ClearNetworkCacheOnIOThread();
64
65   // Callback when the cache has been cleared.
66   void DoClearCache(int);
67
68   // Invoked on the UI thread to delete local storage.
69   void ClearLocalStorageOnUIThread();
70
71   // Callback to deal with the list gathered in ClearLocalStorageOnUIThread.
72   void OnGotLocalStorageUsageInfo(const std::vector<content::LocalStorageUsageInfo>&);
73
74   // Invoked on the IO thread to delete all storage types managed by the quota
75   // system: AppCache, Databases, FileSystems.
76   void ClearQuotaManagedDataOnIOThread();
77
78   // Callback to respond to QuotaManager::GetOriginsModifiedSince, which is the
79   // core of 'ClearQuotaManagedDataOnIOThread'.
80   void OnGotQuotaManagedOrigins(const std::set<GURL>&, storage::StorageType);
81
82   // Callback responding to deletion of a single quota managed origin's
83   // persistent data
84   void OnQuotaManagedOriginDeletion(const GURL&, storage::StorageType, storage::QuotaStatusCode);
85
86   // Called to check whether all temporary and persistent origin data that
87   // should be deleted has been deleted. If everything's good to go, invokes
88   // OnQuotaManagedDataDeleted on the UI thread.
89   void CheckQuotaManagedDataDeletionStatus();
90
91   // Completion handler that runs on the UI thread once persistent data has been
92   // deleted. Updates the waiting flag and invokes NotifyAndDeleteIfDone.
93   void OnQuotaManagedDataDeleted();
94
95   void ClearedCache();
96   bool AllDone();
97   void DeleteIfDone();
98
99   content::BrowserContext* browser_context_;
100   content::AppCacheService* app_cache_service_;
101
102   // The QuotaManager is owned by the profile; we can use a raw pointer here,
103   // and rely on the profile to destroy the object whenever it's reasonable.
104   storage::QuotaManager* quota_manager_;
105
106   // The DOMStorageContext is owned by the profile; we'll store a raw pointer.
107   content::DOMStorageContext* dom_storage_context_;
108
109   // Start time to delete from.
110   base::Time delete_begin_;
111
112   // End time to delete to.
113   base::Time delete_end_;
114
115   enum CacheState {
116     STATE_NONE,
117     STATE_CREATE_MAIN,
118     STATE_CREATE_MEDIA,
119     STATE_DELETE_MAIN,
120     STATE_DELETE_MEDIA,
121     STATE_DONE
122   };
123   CacheState next_cache_state_;
124   disk_cache::Backend* cache_;
125
126   content::NotificationRegistrar registrar_;
127   std::set<int> renderers_;
128
129   // Used to delete data from HTTP cache.
130   scoped_refptr<net::URLRequestContextGetter> main_context_getter_;
131   scoped_refptr<net::URLRequestContextGetter> media_context_getter_;
132
133   bool waiting_for_clear_cache_;
134   bool waiting_for_clear_local_storage_;
135   bool waiting_for_clear_quota_managed_data_;
136
137   // Tracking how many origins need to be deleted, and whether we're finished
138   // gathering origins.
139   int quota_managed_origins_to_delete_count_;
140   int quota_managed_storage_types_to_delete_count_;
141
142   // The removal mask for the current removal operation.
143   int remove_mask_;
144
145   // The origin for the current removal operation.
146   GURL remove_origin_;
147 };
148 #endif