| 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> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // BrowsingDataIndexedDBHelper is an interface for classes dealing with | 23 // BrowsingDataIndexedDBHelper is an interface for classes dealing with |
| 24 // aggregating and deleting browsing data stored in indexed databases. A | 24 // aggregating and deleting browsing data stored in indexed databases. A |
| 25 // 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 |
| 26 // 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 |
| 27 // some later point. | 27 // some later point. |
| 28 class BrowsingDataIndexedDBHelper | 28 class BrowsingDataIndexedDBHelper |
| 29 : public base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper> { | 29 : public base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper> { |
| 30 public: | 30 public: |
| 31 // Create a BrowsingDataIndexedDBHelper instance for the indexed databases | 31 // Create a BrowsingDataIndexedDBHelper instance for the indexed databases |
| 32 // stored in |profile|'s user data directory. | 32 // stored in |profile|'s user data directory. |
| 33 static BrowsingDataIndexedDBHelper* Create( | 33 explicit BrowsingDataIndexedDBHelper(content::IndexedDBContext* content); |
| 34 content::IndexedDBContext* context); | |
| 35 | 34 |
| 36 // Starts the fetching process, which will notify its completion via | 35 // Starts the fetching process, which will notify its completion via |
| 37 // callback. | 36 // callback. |
| 38 // This must be called only in the UI thread. | 37 // This must be called only in the UI thread. |
| 39 virtual void StartFetching( | 38 virtual void StartFetching( |
| 40 const base::Callback<void(const std::list<content::IndexedDBInfo>&)>& | 39 const base::Callback<void(const std::list<content::IndexedDBInfo>&)>& |
| 41 callback) = 0; | 40 callback); |
| 42 // Requests a single indexed database to be deleted in the IndexedDB thread. | 41 // Requests a single indexed database to be deleted in the IndexedDB thread. |
| 43 virtual void DeleteIndexedDB(const GURL& origin) = 0; | 42 virtual void DeleteIndexedDB(const GURL& origin); |
| 44 | 43 |
| 45 protected: | 44 protected: |
| 45 virtual ~BrowsingDataIndexedDBHelper(); |
| 46 |
| 47 scoped_refptr<content::IndexedDBContext> indexed_db_context_; |
| 48 |
| 49 // Access to |indexed_db_info_| is triggered indirectly via the UI thread and |
| 50 // guarded by |is_fetching_|. This means |indexed_db_info_| is only accessed |
| 51 // while |is_fetching_| is true. The flag |is_fetching_| is only accessed on |
| 52 // the UI thread. |
| 53 // In the context of this class |indexed_db_info_| is only accessed on the |
| 54 // context's IndexedDB thread. |
| 55 std::list<content::IndexedDBInfo> indexed_db_info_; |
| 56 |
| 57 // This only mutates on the UI thread. |
| 58 base::Callback<void(const std::list<content::IndexedDBInfo>&)> |
| 59 completion_callback_; |
| 60 |
| 61 // Indicates whether or not we're currently fetching information: |
| 62 // it's true when StartFetching() is called in the UI thread, and it's reset |
| 63 // after we notified the callback in the UI thread. |
| 64 // This only mutates on the UI thread. |
| 65 bool is_fetching_; |
| 66 |
| 67 private: |
| 46 friend class base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper>; | 68 friend class base::RefCountedThreadSafe<BrowsingDataIndexedDBHelper>; |
| 47 virtual ~BrowsingDataIndexedDBHelper() {} | 69 |
| 70 // Enumerates all indexed database files in the IndexedDB thread. |
| 71 void FetchIndexedDBInfoInIndexedDBThread(); |
| 72 // Notifies the completion callback in the UI thread. |
| 73 void NotifyInUIThread(); |
| 74 // Delete a single indexed database in the IndexedDB thread. |
| 75 void DeleteIndexedDBInIndexedDBThread(const GURL& origin); |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(BrowsingDataIndexedDBHelper); |
| 48 }; | 78 }; |
| 49 | 79 |
| 50 // This class is an implementation of BrowsingDataIndexedDBHelper that does | 80 // This class is an implementation of BrowsingDataIndexedDBHelper that does |
| 51 // not fetch its information from the indexed database tracker, but gets them | 81 // not fetch its information from the indexed database tracker, but gets them |
| 52 // passed as a parameter. | 82 // passed as a parameter. |
| 53 class CannedBrowsingDataIndexedDBHelper | 83 class CannedBrowsingDataIndexedDBHelper |
| 54 : public BrowsingDataIndexedDBHelper { | 84 : public BrowsingDataIndexedDBHelper { |
| 55 public: | 85 public: |
| 56 // Contains information about an indexed database. | 86 // Contains information about an indexed database. |
| 57 struct PendingIndexedDBInfo { | 87 struct PendingIndexedDBInfo { |
| 58 PendingIndexedDBInfo(const GURL& origin, const base::string16& name); | 88 PendingIndexedDBInfo(const GURL& origin, const base::string16& name); |
| 59 ~PendingIndexedDBInfo(); | 89 ~PendingIndexedDBInfo(); |
| 60 | 90 |
| 61 bool operator<(const PendingIndexedDBInfo& other) const; | 91 bool operator<(const PendingIndexedDBInfo& other) const; |
| 62 | 92 |
| 63 GURL origin; | 93 GURL origin; |
| 64 base::string16 name; | 94 base::string16 name; |
| 65 }; | 95 }; |
| 66 | 96 |
| 67 CannedBrowsingDataIndexedDBHelper(); | 97 explicit CannedBrowsingDataIndexedDBHelper( |
| 98 content::IndexedDBContext* context); |
| 68 | 99 |
| 69 // Return a copy of the IndexedDB helper. Only one consumer can use the | 100 // Return a copy of the IndexedDB helper. Only one consumer can use the |
| 70 // StartFetching method at a time, so we need to create a copy of the helper | 101 // StartFetching method at a time, so we need to create a copy of the helper |
| 71 // every time we instantiate a cookies tree model for it. | 102 // every time we instantiate a cookies tree model for it. |
| 72 CannedBrowsingDataIndexedDBHelper* Clone(); | 103 CannedBrowsingDataIndexedDBHelper* Clone(); |
| 73 | 104 |
| 74 // Add a indexed database to the set of canned indexed databases that is | 105 // Add a indexed database to the set of canned indexed databases that is |
| 75 // returned by this helper. | 106 // returned by this helper. |
| 76 void AddIndexedDB(const GURL& origin, | 107 void AddIndexedDB(const GURL& origin, |
| 77 const base::string16& name); | 108 const base::string16& name); |
| 78 | 109 |
| 79 // Clear the list of canned indexed databases. | 110 // Clear the list of canned indexed databases. |
| 80 void Reset(); | 111 void Reset(); |
| 81 | 112 |
| 82 // True if no indexed databases are currently stored. | 113 // True if no indexed databases are currently stored. |
| 83 bool empty() const; | 114 bool empty() const; |
| 84 | 115 |
| 85 // Returns the number of currently stored indexed databases. | 116 // Returns the number of currently stored indexed databases. |
| 86 size_t GetIndexedDBCount() const; | 117 size_t GetIndexedDBCount() const; |
| 87 | 118 |
| 88 // Returns the current list of indexed data bases. | 119 // Returns the current list of indexed data bases. |
| 89 const std::set<CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo>& | 120 const std::set<CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo>& |
| 90 GetIndexedDBInfo() const; | 121 GetIndexedDBInfo() const; |
| 91 | 122 |
| 92 // BrowsingDataIndexedDBHelper methods. | 123 // BrowsingDataIndexedDBHelper methods. |
| 93 virtual void StartFetching( | 124 virtual void StartFetching( |
| 94 const base::Callback<void(const std::list<content::IndexedDBInfo>&)>& | 125 const base::Callback<void(const std::list<content::IndexedDBInfo>&)>& |
| 95 callback) OVERRIDE; | 126 callback) OVERRIDE; |
| 96 | 127 virtual void DeleteIndexedDB(const GURL& origin) OVERRIDE; |
| 97 virtual void DeleteIndexedDB(const GURL& origin) OVERRIDE {} | |
| 98 | 128 |
| 99 private: | 129 private: |
| 100 virtual ~CannedBrowsingDataIndexedDBHelper(); | 130 virtual ~CannedBrowsingDataIndexedDBHelper(); |
| 101 | 131 |
| 102 // Convert the pending indexed db info to indexed db info objects. | |
| 103 void ConvertPendingInfo(); | |
| 104 | |
| 105 std::set<PendingIndexedDBInfo> pending_indexed_db_info_; | 132 std::set<PendingIndexedDBInfo> pending_indexed_db_info_; |
| 106 | 133 |
| 107 // Access to |indexed_db_info_| is triggered indirectly via the UI thread and | |
| 108 // guarded by |is_fetching_|. This means |indexed_db_info_| is only accessed | |
| 109 // while |is_fetching_| is true. The flag |is_fetching_| is only accessed on | |
| 110 // the UI thread. | |
| 111 // In the context of this class |indexed_db_info_| is only accessed on the UI | |
| 112 // thread. | |
| 113 std::list<content::IndexedDBInfo> indexed_db_info_; | |
| 114 | |
| 115 // This only mutates on the UI thread. | |
| 116 base::Callback<void(const std::list<content::IndexedDBInfo>&)> | |
| 117 completion_callback_; | |
| 118 | |
| 119 // Indicates whether or not we're currently fetching information: | |
| 120 // it's true when StartFetching() is called in the UI thread, and it's reset | |
| 121 // after we notified the callback in the UI thread. | |
| 122 // This only mutates on the UI thread. | |
| 123 bool is_fetching_; | |
| 124 | |
| 125 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataIndexedDBHelper); | 134 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataIndexedDBHelper); |
| 126 }; | 135 }; |
| 127 | 136 |
| 128 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_INDEXED_DB_HELPER_H_ | 137 #endif // CHROME_BROWSER_BROWSING_DATA_BROWSING_DATA_INDEXED_DB_HELPER_H_ |
| OLD | NEW |