OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 10 #include <string> |
10 #include <vector> | |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
17 #include "webkit/database/database_tracker.h" | 17 #include "webkit/database/database_tracker.h" |
18 | 18 |
19 class Profile; | 19 class Profile; |
20 | 20 |
(...skipping 29 matching lines...) Expand all Loading... |
50 int64 size; | 50 int64 size; |
51 base::Time last_modified; | 51 base::Time last_modified; |
52 }; | 52 }; |
53 | 53 |
54 explicit BrowsingDataDatabaseHelper(Profile* profile); | 54 explicit BrowsingDataDatabaseHelper(Profile* profile); |
55 | 55 |
56 // Starts the fetching process, which will notify its completion via | 56 // Starts the fetching process, which will notify its completion via |
57 // callback. | 57 // callback. |
58 // This must be called only in the UI thread. | 58 // This must be called only in the UI thread. |
59 virtual void StartFetching( | 59 virtual void StartFetching( |
60 Callback1<const std::vector<DatabaseInfo>& >::Type* callback); | 60 Callback1<const std::list<DatabaseInfo>& >::Type* callback); |
61 | 61 |
62 // Cancels the notification callback (i.e., the window that created it no | 62 // Cancels the notification callback (i.e., the window that created it no |
63 // longer exists). | 63 // longer exists). |
64 // This must be called only in the UI thread. | 64 // This must be called only in the UI thread. |
65 virtual void CancelNotification(); | 65 virtual void CancelNotification(); |
66 | 66 |
67 // Requests a single database to be deleted in the FILE thread. This must be | 67 // Requests a single database to be deleted in the FILE thread. This must be |
68 // called in the UI thread. | 68 // called in the UI thread. |
69 virtual void DeleteDatabase(const std::string& origin, | 69 virtual void DeleteDatabase(const std::string& origin, |
70 const std::string& name); | 70 const std::string& name); |
71 | 71 |
72 protected: | 72 protected: |
73 friend class base::RefCountedThreadSafe<BrowsingDataDatabaseHelper>; | 73 friend class base::RefCountedThreadSafe<BrowsingDataDatabaseHelper>; |
74 virtual ~BrowsingDataDatabaseHelper(); | 74 virtual ~BrowsingDataDatabaseHelper(); |
75 | 75 |
76 // Notifies the completion callback. This must be called in the UI thread. | 76 // Notifies the completion callback. This must be called in the UI thread. |
77 void NotifyInUIThread(); | 77 void NotifyInUIThread(); |
78 | 78 |
79 // This only mutates in the FILE thread. | 79 // This only mutates in the FILE thread. |
80 std::vector<DatabaseInfo> database_info_; | 80 std::list<DatabaseInfo> database_info_; |
81 | 81 |
82 // This only mutates on the UI thread. | 82 // This only mutates on the UI thread. |
83 scoped_ptr<Callback1<const std::vector<DatabaseInfo>& >::Type > | 83 scoped_ptr<Callback1<const std::list<DatabaseInfo>& >::Type > |
84 completion_callback_; | 84 completion_callback_; |
85 | 85 |
86 // Indicates whether or not we're currently fetching information: | 86 // Indicates whether or not we're currently fetching information: |
87 // it's true when StartFetching() is called in the UI thread, and it's reset | 87 // it's true when StartFetching() is called in the UI thread, and it's reset |
88 // after we notify the callback in the UI thread. | 88 // after we notify the callback in the UI thread. |
89 // This only mutates on the UI thread. | 89 // This only mutates on the UI thread. |
90 bool is_fetching_; | 90 bool is_fetching_; |
91 | 91 |
92 private: | 92 private: |
93 // Enumerates all databases. This must be called in the FILE thread. | 93 // Enumerates all databases. This must be called in the FILE thread. |
(...skipping 27 matching lines...) Expand all Loading... |
121 const std::string& description); | 121 const std::string& description); |
122 | 122 |
123 // Clear the list of canned databases. | 123 // Clear the list of canned databases. |
124 void Reset(); | 124 void Reset(); |
125 | 125 |
126 // True if no databases are currently stored. | 126 // True if no databases are currently stored. |
127 bool empty() const; | 127 bool empty() const; |
128 | 128 |
129 // BrowsingDataDatabaseHelper methods. | 129 // BrowsingDataDatabaseHelper methods. |
130 virtual void StartFetching( | 130 virtual void StartFetching( |
131 Callback1<const std::vector<DatabaseInfo>& >::Type* callback); | 131 Callback1<const std::list<DatabaseInfo>& >::Type* callback); |
132 virtual void CancelNotification() {} | 132 virtual void CancelNotification() {} |
133 | 133 |
134 private: | 134 private: |
135 struct PendingDatabaseInfo { | 135 struct PendingDatabaseInfo { |
136 PendingDatabaseInfo(); | 136 PendingDatabaseInfo(); |
137 PendingDatabaseInfo(const GURL& origin, | 137 PendingDatabaseInfo(const GURL& origin, |
138 const std::string& name, | 138 const std::string& name, |
139 const std::string& description); | 139 const std::string& description); |
140 ~PendingDatabaseInfo(); | 140 ~PendingDatabaseInfo(); |
141 | 141 |
142 GURL origin; | 142 GURL origin; |
143 std::string name; | 143 std::string name; |
144 std::string description; | 144 std::string description; |
145 }; | 145 }; |
146 | 146 |
147 virtual ~CannedBrowsingDataDatabaseHelper(); | 147 virtual ~CannedBrowsingDataDatabaseHelper(); |
148 | 148 |
149 // Converts the pending database info structs to database info structs. | 149 // Converts the pending database info structs to database info structs. |
150 void ConvertInfoInWebKitThread(); | 150 void ConvertInfoInWebKitThread(); |
151 | 151 |
152 // Used to protect access to pending_database_info_. | 152 // Used to protect access to pending_database_info_. |
153 mutable base::Lock lock_; | 153 mutable base::Lock lock_; |
154 | 154 |
155 // This may mutate on WEBKIT and UI threads. | 155 // This may mutate on WEBKIT and UI threads. |
156 std::vector<PendingDatabaseInfo> pending_database_info_; | 156 std::list<PendingDatabaseInfo> pending_database_info_; |
157 | 157 |
158 Profile* profile_; | 158 Profile* profile_; |
159 | 159 |
160 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper); | 160 DISALLOW_COPY_AND_ASSIGN(CannedBrowsingDataDatabaseHelper); |
161 }; | 161 }; |
162 | 162 |
163 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ | 163 #endif // CHROME_BROWSER_BROWSING_DATA_DATABASE_HELPER_H_ |
OLD | NEW |