| 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_DATABASE_HELPER_H_ | 5 #ifndef CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ |
| 6 #define CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ | 6 #define CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <set> |
| 10 #include <string> | 11 #include <string> |
| 11 | 12 |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 #include "webkit/database/database_tracker.h" | 19 #include "webkit/database/database_tracker.h" |
| 19 | 20 |
| 20 class Profile; | 21 class Profile; |
| 21 | 22 |
| 22 // This class fetches database information in the FILE thread, and notifies | 23 // This class fetches database information in the FILE thread, and notifies |
| 23 // the UI thread upon completion. | 24 // the UI thread upon completion. |
| 24 // A client of this class need to call StartFetching from the UI thread to | 25 // A client of this class need to call StartFetching from the UI thread to |
| 25 // initiate the flow, and it'll be notified by the callback in its UI | 26 // initiate the flow, and it'll be notified by the callback in its UI |
| 26 // thread at some later point. | 27 // thread at some later point. |
| 27 class BrowsingDataDatabaseHelper | 28 class BrowsingDataDatabaseHelper |
| 28 : public base::RefCountedThreadSafe<BrowsingDataDatabaseHelper> { | 29 : public base::RefCountedThreadSafe<BrowsingDataDatabaseHelper> { |
| 29 public: | 30 public: |
| 30 // Contains detailed information about a web database. | 31 // Contains detailed information about a web database. |
| 31 struct DatabaseInfo { | 32 struct DatabaseInfo { |
| 32 DatabaseInfo(); | |
| 33 DatabaseInfo(const std::string& host, | 33 DatabaseInfo(const std::string& host, |
| 34 const std::string& database_name, | 34 const std::string& database_name, |
| 35 const std::string& origin_identifier, | 35 const std::string& origin_identifier, |
| 36 const std::string& description, | 36 const std::string& description, |
| 37 const std::string& origin, | 37 const std::string& origin, |
| 38 int64 size, | 38 int64 size, |
| 39 base::Time last_modified); | 39 base::Time last_modified); |
| 40 ~DatabaseInfo(); | 40 ~DatabaseInfo(); |
| 41 | 41 |
| 42 std::string host; | 42 std::string host; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 scoped_refptr<webkit_database::DatabaseTracker> tracker_; | 91 scoped_refptr<webkit_database::DatabaseTracker> tracker_; |
| 92 | 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(BrowsingDataDatabaseHelper); | 93 DISALLOW_COPY_AND_ASSIGN(BrowsingDataDatabaseHelper); |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 // This class is a thin wrapper around BrowsingDataDatabaseHelper that does not | 96 // This class is a thin wrapper around BrowsingDataDatabaseHelper that does not |
| 97 // fetch its information from the database tracker, but gets them passed as | 97 // fetch its information from the database tracker, but gets them passed as |
| 98 // a parameter during construction. | 98 // a parameter during construction. |
| 99 class CannedBrowsingDataDatabaseHelper : public BrowsingDataDatabaseHelper { | 99 class CannedBrowsingDataDatabaseHelper : public BrowsingDataDatabaseHelper { |
| 100 public: | 100 public: |
| 101 struct PendingDatabaseInfo { |
| 102 PendingDatabaseInfo(const GURL& origin, |
| 103 const std::string& name, |
| 104 const std::string& description); |
| 105 ~PendingDatabaseInfo(); |
| 106 |
| 107 // The operator is needed to store |PendingDatabaseInfo| objects in a set. |
| 108 bool operator<(const PendingDatabaseInfo& other) const; |
| 109 |
| 110 GURL origin; |
| 111 std::string name; |
| 112 std::string description; |
| 113 }; |
| 114 |
| 101 explicit CannedBrowsingDataDatabaseHelper(Profile* profile); | 115 explicit CannedBrowsingDataDatabaseHelper(Profile* profile); |
| 102 | 116 |
| 103 // Return a copy of the database helper. Only one consumer can use the | 117 // Return a copy of the database helper. Only one consumer can use the |
| 104 // StartFetching method at a time, so we need to create a copy of the helper | 118 // StartFetching method at a time, so we need to create a copy of the helper |
| 105 // everytime we instantiate a cookies tree model for it. | 119 // everytime we instantiate a cookies tree model for it. |
| 106 CannedBrowsingDataDatabaseHelper* Clone(); | 120 CannedBrowsingDataDatabaseHelper* Clone(); |
| 107 | 121 |
| 108 // Add a database to the set of canned databases that is returned by this | 122 // Add a database to the set of canned databases that is returned by this |
| 109 // helper. | 123 // helper. |
| 110 void AddDatabase(const GURL& origin, | 124 void AddDatabase(const GURL& origin, |
| 111 const std::string& name, | 125 const std::string& name, |
| 112 const std::string& description); | 126 const std::string& description); |
| 113 | 127 |
| 114 // Clear the list of canned databases. | 128 // Clear the list of canned databases. |
| 115 void Reset(); | 129 void Reset(); |
| 116 | 130 |
| 117 // True if no databases are currently stored. | 131 // True if no databases are currently stored. |
| 118 bool empty() const; | 132 bool empty() const; |
| 119 | 133 |
| 120 // Returns the number of currently stored databases. | 134 // Returns the number of currently stored databases. |
| 121 size_t GetDatabaseCount() const; | 135 size_t GetDatabaseCount() const; |
| 122 | 136 |
| 137 // Returns the current list of web databases. |
| 138 const std::set<PendingDatabaseInfo>& GetPendingDatabaseInfo(); |
| 139 |
| 123 // BrowsingDataDatabaseHelper implementation. | 140 // BrowsingDataDatabaseHelper implementation. |
| 124 virtual void StartFetching( | 141 virtual void StartFetching( |
| 125 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) | 142 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) |
| 126 OVERRIDE; | 143 OVERRIDE; |
| 127 | 144 |
| 128 private: | 145 private: |
| 129 struct PendingDatabaseInfo { | |
| 130 PendingDatabaseInfo(); | |
| 131 PendingDatabaseInfo(const GURL& origin, | |
| 132 const std::string& name, | |
| 133 const std::string& description); | |
| 134 ~PendingDatabaseInfo(); | |
| 135 | |
| 136 GURL origin; | |
| 137 std::string name; | |
| 138 std::string description; | |
| 139 }; | |
| 140 | |
| 141 virtual ~CannedBrowsingDataDatabaseHelper(); | 146 virtual ~CannedBrowsingDataDatabaseHelper(); |
| 142 | 147 |
| 143 // Converts the pending database info structs to database info structs. | 148 // Converts the pending database info structs to database info structs. |
| 144 void ConvertInfoInWebKitThread(); | 149 void ConvertInfoInWebKitThread(); |
| 145 | 150 |
| 146 // Used to protect access to pending_database_info_. | 151 // Used to protect access to pending_database_info_. |
| 147 mutable base::Lock lock_; | 152 mutable base::Lock lock_; |
| 148 | 153 |
| 149 // This may mutate on WEBKIT and UI threads. | 154 // This may mutate only on the UI thread, but it is also accessed on the |
| 150 std::list<PendingDatabaseInfo> pending_database_info_; | 155 // WEBKIT thread. |
| 156 std::set<PendingDatabaseInfo> pending_database_info_; |
| 151 | 157 |
| 152 Profile* profile_; | 158 Profile* profile_; |
| 153 | 159 |
| 154 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper); | 160 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper); |
| 155 }; | 161 }; |
| 156 | 162 |
| 157 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ | 163 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ |
| OLD | NEW |