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 18 matching lines...) Expand all Loading... | |
61 virtual void DeleteDatabase(const std::string& origin, | 61 virtual void DeleteDatabase(const std::string& origin, |
62 const std::string& name); | 62 const std::string& name); |
63 | 63 |
64 protected: | 64 protected: |
65 friend class base::RefCountedThreadSafe<BrowsingDataDatabaseHelper>; | 65 friend class base::RefCountedThreadSafe<BrowsingDataDatabaseHelper>; |
66 virtual ~BrowsingDataDatabaseHelper(); | 66 virtual ~BrowsingDataDatabaseHelper(); |
67 | 67 |
68 // Notifies the completion callback. This must be called in the UI thread. | 68 // Notifies the completion callback. This must be called in the UI thread. |
69 void NotifyInUIThread(); | 69 void NotifyInUIThread(); |
70 | 70 |
71 // This only mutates in the FILE thread. | 71 // Access to |database_info_| is triggered indirectly via the UI thread and |
72 // guarded by |is_fetching_|. This means |database_info_| is only accessed | |
73 // while |is_fetching_| is true. The flag |is_fetching_| is only accessed on | |
74 // the UI thread. | |
75 // In the context of this class |database_info_| is only accessed on the FILE | |
76 // thread. | |
72 std::list<DatabaseInfo> database_info_; | 77 std::list<DatabaseInfo> database_info_; |
73 | 78 |
74 // This only mutates on the UI thread. | 79 // This only mutates on the UI thread. |
75 base::Callback<void(const std::list<DatabaseInfo>&)> completion_callback_; | 80 base::Callback<void(const std::list<DatabaseInfo>&)> completion_callback_; |
76 | 81 |
77 // Indicates whether or not we're currently fetching information: | 82 // Indicates whether or not we're currently fetching information: |
78 // it's true when StartFetching() is called in the UI thread, and it's reset | 83 // it's true when StartFetching() is called in the UI thread, and it's reset |
79 // after we notify the callback in the UI thread. | 84 // after we notify the callback in the UI thread. |
80 // This only mutates on the UI thread. | 85 // This only mutates on the UI thread. |
81 bool is_fetching_; | 86 bool is_fetching_; |
82 | 87 |
83 private: | 88 private: |
84 // Enumerates all databases. This must be called in the FILE thread. | 89 // Enumerates all databases. This must be called in the FILE thread. |
85 void FetchDatabaseInfoOnFileThread(); | 90 void FetchDatabaseInfoOnFileThread(); |
86 | 91 |
87 // Delete a single database file. This must be called in the FILE thread. | 92 // Delete a single database file. This must be called in the FILE thread. |
88 void DeleteDatabaseOnFileThread(const std::string& origin, | 93 void DeleteDatabaseOnFileThread(const std::string& origin, |
89 const std::string& name); | 94 const std::string& name); |
90 | 95 |
91 scoped_refptr<webkit_database::DatabaseTracker> tracker_; | 96 scoped_refptr<webkit_database::DatabaseTracker> tracker_; |
92 | 97 |
93 DISALLOW_COPY_AND_ASSIGN(BrowsingDataDatabaseHelper); | 98 DISALLOW_COPY_AND_ASSIGN(BrowsingDataDatabaseHelper); |
94 }; | 99 }; |
95 | 100 |
96 // This class is a thin wrapper around BrowsingDataDatabaseHelper that does not | 101 // This class is a thin wrapper around BrowsingDataDatabaseHelper that does not |
97 // fetch its information from the database tracker, but gets them passed as | 102 // fetch its information from the database tracker, but gets them passed as |
98 // a parameter during construction. | 103 // a parameter during construction. |
99 class CannedBrowsingDataDatabaseHelper : public BrowsingDataDatabaseHelper { | 104 class CannedBrowsingDataDatabaseHelper : public BrowsingDataDatabaseHelper { |
100 public: | 105 public: |
106 struct PendingDatabaseInfo { | |
107 PendingDatabaseInfo(const GURL& origin, | |
108 const std::string& name, | |
109 const std::string& description); | |
110 ~PendingDatabaseInfo(); | |
111 | |
112 // The operator is needed to store |PendingDatabaseInfo| objects in a set. | |
113 bool operator<(const PendingDatabaseInfo& other) const; | |
114 | |
115 GURL origin; | |
116 std::string name; | |
117 std::string description; | |
118 }; | |
119 | |
101 explicit CannedBrowsingDataDatabaseHelper(Profile* profile); | 120 explicit CannedBrowsingDataDatabaseHelper(Profile* profile); |
102 | 121 |
103 // Return a copy of the database helper. Only one consumer can use the | 122 // 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 | 123 // 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. | 124 // everytime we instantiate a cookies tree model for it. |
106 CannedBrowsingDataDatabaseHelper* Clone(); | 125 CannedBrowsingDataDatabaseHelper* Clone(); |
107 | 126 |
108 // Add a database to the set of canned databases that is returned by this | 127 // Add a database to the set of canned databases that is returned by this |
109 // helper. | 128 // helper. |
110 void AddDatabase(const GURL& origin, | 129 void AddDatabase(const GURL& origin, |
111 const std::string& name, | 130 const std::string& name, |
112 const std::string& description); | 131 const std::string& description); |
113 | 132 |
114 // Clear the list of canned databases. | 133 // Clear the list of canned databases. |
115 void Reset(); | 134 void Reset(); |
116 | 135 |
117 // True if no databases are currently stored. | 136 // True if no databases are currently stored. |
118 bool empty() const; | 137 bool empty() const; |
119 | 138 |
120 // Returns the number of currently stored databases. | 139 // Returns the number of currently stored databases. |
121 size_t GetDatabaseCount() const; | 140 size_t GetDatabaseCount() const; |
122 | 141 |
142 // Returns the current list of web databases. | |
143 const std::set<PendingDatabaseInfo>& GetPendingDatabaseInfo(); | |
144 | |
123 // BrowsingDataDatabaseHelper implementation. | 145 // BrowsingDataDatabaseHelper implementation. |
124 virtual void StartFetching( | 146 virtual void StartFetching( |
125 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) | 147 const base::Callback<void(const std::list<DatabaseInfo>&)>& callback) |
126 OVERRIDE; | 148 OVERRIDE; |
127 | 149 |
128 private: | 150 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(); | 151 virtual ~CannedBrowsingDataDatabaseHelper(); |
142 | 152 |
143 // Converts the pending database info structs to database info structs. | 153 // Converts the pending database info structs to database info structs. |
144 void ConvertInfoInWebKitThread(); | 154 void ConvertInfoInWebKitThread(); |
145 | 155 |
146 // Used to protect access to pending_database_info_. | 156 // Used to protect access to pending_database_info_. |
147 mutable base::Lock lock_; | 157 mutable base::Lock lock_; |
148 | 158 |
149 // This may mutate on WEBKIT and UI threads. | 159 // Access to |pending_database_info_| is protected by |lock_| since it may |
150 std::list<PendingDatabaseInfo> pending_database_info_; | 160 // mutate on the UI or the WEBKIT thread. |
Bernhard Bauer
2012/05/14 17:14:07
Nit: "it may be accessed"
markusheintz_
2012/05/14 18:18:06
Done.
| |
161 std::set<PendingDatabaseInfo> pending_database_info_; | |
151 | 162 |
152 Profile* profile_; | 163 Profile* profile_; |
153 | 164 |
154 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper); | 165 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper); |
155 }; | 166 }; |
156 | 167 |
157 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ | 168 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ |
OLD | NEW |