| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_INDEXED_DB_HELPER_H_ | 5 #ifndef CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_INDEXED_DB_HELPER_H_ |
| 6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_INDEXED_DB_HELPER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_INDEXED_DB_HELPER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "content/public/browser/indexed_db_context.h" |
| 18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 19 | 20 |
| 20 class Profile; | 21 class Profile; |
| 21 | 22 |
| 22 namespace content { | |
| 23 class IndexedDBContext; | |
| 24 } | |
| 25 | |
| 26 // BrowsingDataIndexedDBHelper is an interface for classes dealing with | 23 // BrowsingDataIndexedDBHelper is an interface for classes dealing with |
| 27 // aggregating and deleting browsing data stored in indexed databases. A | 24 // aggregating and deleting browsing data stored in indexed databases. A |
| 28 // client of this class need to call StartFetching from the UI thread to | 25 // client of this class need to call StartFetching from the UI thread to |
| 29 // initiate the flow, and it'll be notified by the callback in its UI thread at | 26 // initiate the flow, and it'll be notified by the callback in its UI thread at |
| 30 // some later point. | 27 // some later point. |
| 31 class BrowsingDataIndexedDBHelper | 28 class BrowsingDataIndexedDBHelper |
| 32 : public base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper> { | 29 : public base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper> { |
| 33 public: | 30 public: |
| 34 // Contains detailed information about an indexed database. | |
| 35 struct IndexedDBInfo { | |
| 36 IndexedDBInfo( | |
| 37 const GURL& origin, | |
| 38 int64 size, | |
| 39 base::Time last_modified); | |
| 40 ~IndexedDBInfo(); | |
| 41 | |
| 42 GURL origin; | |
| 43 int64 size; | |
| 44 base::Time last_modified; | |
| 45 }; | |
| 46 | |
| 47 // Create a BrowsingDataIndexedDBHelper instance for the indexed databases | 31 // Create a BrowsingDataIndexedDBHelper instance for the indexed databases |
| 48 // stored in |profile|'s user data directory. | 32 // stored in |profile|'s user data directory. |
| 49 static BrowsingDataIndexedDBHelper* Create( | 33 static BrowsingDataIndexedDBHelper* Create( |
| 50 content::IndexedDBContext* context); | 34 content::IndexedDBContext* context); |
| 51 | 35 |
| 52 // Starts the fetching process, which will notify its completion via | 36 // Starts the fetching process, which will notify its completion via |
| 53 // callback. | 37 // callback. |
| 54 // This must be called only in the UI thread. | 38 // This must be called only in the UI thread. |
| 55 virtual void StartFetching( | 39 virtual void StartFetching( |
| 56 const base::Callback<void(const std::list<IndexedDBInfo>&)>& | 40 const base::Callback<void(const std::list<content::IndexedDBInfo>&)>& |
| 57 callback) = 0; | 41 callback) = 0; |
| 58 // Requests a single indexed database to be deleted in the WEBKIT thread. | 42 // Requests a single indexed database to be deleted in the WEBKIT thread. |
| 59 virtual void DeleteIndexedDB(const GURL& origin) = 0; | 43 virtual void DeleteIndexedDB(const GURL& origin) = 0; |
| 60 | 44 |
| 61 protected: | 45 protected: |
| 62 friend class base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper>; | 46 friend class base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper>; |
| 63 virtual ~BrowsingDataIndexedDBHelper() {} | 47 virtual ~BrowsingDataIndexedDBHelper() {} |
| 64 }; | 48 }; |
| 65 | 49 |
| 66 // This class is an implementation of BrowsingDataIndexedDBHelper that does | 50 // This class is an implementation of BrowsingDataIndexedDBHelper that does |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 | 84 |
| 101 // Returns the number of currently stored indexed databases. | 85 // Returns the number of currently stored indexed databases. |
| 102 size_t GetIndexedDBCount() const; | 86 size_t GetIndexedDBCount() const; |
| 103 | 87 |
| 104 // Returns the current list of indexed data bases. | 88 // Returns the current list of indexed data bases. |
| 105 const std::set<CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo>& | 89 const std::set<CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo>& |
| 106 GetIndexedDBInfo() const; | 90 GetIndexedDBInfo() const; |
| 107 | 91 |
| 108 // BrowsingDataIndexedDBHelper methods. | 92 // BrowsingDataIndexedDBHelper methods. |
| 109 virtual void StartFetching( | 93 virtual void StartFetching( |
| 110 const base::Callback<void(const std::list<IndexedDBInfo>&)>& | 94 const base::Callback<void(const std::list<content::IndexedDBInfo>&)>& |
| 111 callback) OVERRIDE; | 95 callback) OVERRIDE; |
| 112 | 96 |
| 113 virtual void DeleteIndexedDB(const GURL& origin) OVERRIDE {} | 97 virtual void DeleteIndexedDB(const GURL& origin) OVERRIDE {} |
| 114 | 98 |
| 115 private: | 99 private: |
| 116 virtual ~CannedBrowsingDataIndexedDBHelper(); | 100 virtual ~CannedBrowsingDataIndexedDBHelper(); |
| 117 | 101 |
| 118 // Convert the pending indexed db info to indexed db info objects. | 102 // Convert the pending indexed db info to indexed db info objects. |
| 119 void ConvertPendingInfoInWebKitThread(); | 103 void ConvertPendingInfoInWebKitThread(); |
| 120 | 104 |
| 121 void NotifyInUIThread(); | 105 void NotifyInUIThread(); |
| 122 | 106 |
| 123 // Lock to protect access to pending_indexed_db_info_; | 107 // Lock to protect access to pending_indexed_db_info_; |
| 124 mutable base::Lock lock_; | 108 mutable base::Lock lock_; |
| 125 | 109 |
| 126 // Access to |pending_indexed_db_info_| is protected by |lock_| since it can | 110 // Access to |pending_indexed_db_info_| is protected by |lock_| since it can |
| 127 // be accessed on the UI and on the WEBKIT thread. | 111 // be accessed on the UI and on the WEBKIT thread. |
| 128 std::set<PendingIndexedDBInfo> pending_indexed_db_info_; | 112 std::set<PendingIndexedDBInfo> pending_indexed_db_info_; |
| 129 | 113 |
| 130 // Access to |indexed_db_info_| is triggered indirectly via the UI thread and | 114 // Access to |indexed_db_info_| is triggered indirectly via the UI thread and |
| 131 // guarded by |is_fetching_|. This means |indexed_db_info_| is only accessed | 115 // guarded by |is_fetching_|. This means |indexed_db_info_| is only accessed |
| 132 // while |is_fetching_| is true. The flag |is_fetching_| is only accessed on | 116 // while |is_fetching_| is true. The flag |is_fetching_| is only accessed on |
| 133 // the UI thread. | 117 // the UI thread. |
| 134 // In the context of this class |indexed_db_info_| is only accessed on the UI | 118 // In the context of this class |indexed_db_info_| is only accessed on the UI |
| 135 // thread. | 119 // thread. |
| 136 std::list<IndexedDBInfo> indexed_db_info_; | 120 std::list<content::IndexedDBInfo> indexed_db_info_; |
| 137 | 121 |
| 138 // This only mutates on the UI thread. | 122 // This only mutates on the UI thread. |
| 139 base::Callback<void(const std::list<IndexedDBInfo>&)> completion_callback_; | 123 base::Callback<void(const std::list<content::IndexedDBInfo>&)> |
| 124 completion_callback_; |
| 140 | 125 |
| 141 // Indicates whether or not we're currently fetching information: | 126 // Indicates whether or not we're currently fetching information: |
| 142 // it's true when StartFetching() is called in the UI thread, and it's reset | 127 // it's true when StartFetching() is called in the UI thread, and it's reset |
| 143 // after we notified the callback in the UI thread. | 128 // after we notified the callback in the UI thread. |
| 144 // This only mutates on the UI thread. | 129 // This only mutates on the UI thread. |
| 145 bool is_fetching_; | 130 bool is_fetching_; |
| 146 | 131 |
| 147 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataIndexedDBHelper); | 132 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataIndexedDBHelper); |
| 148 }; | 133 }; |
| 149 | 134 |
| 150 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_INDEXED_DB_HELPER_H_ | 135 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_INDEXED_DB_HELPER_H_ |
| OLD | NEW |