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 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" | 5 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 #include <map> | |
9 #include <set> | |
10 #include <utility> | |
8 | 11 |
9 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
10 #include "base/bind.h" | 13 #include "base/bind.h" |
11 #include "base/file_path.h" | 14 #include "base/file_path.h" |
12 #include "base/file_util.h" | 15 #include "base/file_util.h" |
13 #include "base/logging.h" | 16 #include "base/logging.h" |
14 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
16 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
17 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "base/synchronization/lock.h" | |
18 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
19 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
20 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" | 24 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" |
21 #include "content/browser/browser_thread.h" | 25 #include "content/browser/browser_thread.h" |
22 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
27 #include "net/base/registry_controlled_domain.h" | |
23 #include "sql/meta_table.h" | 28 #include "sql/meta_table.h" |
24 #include "sql/statement.h" | 29 #include "sql/statement.h" |
25 #include "sql/transaction.h" | 30 #include "sql/transaction.h" |
26 | 31 |
27 using base::Time; | 32 using base::Time; |
28 | 33 |
29 // This class is designed to be shared between any calling threads and the | 34 // This class is designed to be shared between any calling threads and the |
30 // database thread. It batches operations and commits them on a timer. | 35 // database thread. It batches operations and commits them on a timer. |
31 // This class expects to be Load()'ed once on any thread. Loading occurs | 36 // |
32 // asynchronously on the DB thread and the caller will be notified on the IO | 37 // SQLitePersistentCookieStore::Load is called to load all cookies. It |
33 // thread. Subsequent to loading, mutations may be queued by any thread using | 38 // delegates to Backend::Load, which posts a Backend::LoadAndNotifyOnDBThread |
39 // task to the DB thread. This task calls Backend::ChainLoadCookies(), which | |
40 // repeatedly posts itself to the DB thread to load each eTLD+1's cookies in | |
41 // separate tasks. When this is complete, Backend::NotifyOnIOThread is posted | |
42 // to the IO thread, which notifies the caller of SQLitePersistentCookieStore:: | |
43 // Load that the load is complete. | |
44 // | |
45 // If a priority load request is invoked via SQLitePersistentCookieStore:: | |
46 // LoadCookiesForKey, it is delegated to Backend::LoadCookiesForKey, which posts | |
47 // Backend::LoadKeyAndNotifyOnDBThread to the DB thread. That routine loads just | |
48 // that single domain key (eTLD+1)'s cookies, and posts a Backend:: | |
49 // NotifyOnIOThread to the IO thread to notify the caller of | |
50 // SQLitePersistentCookieStore::LoadCookiesForKey that that load is complete. | |
51 // | |
52 // Subsequent to loading, mutations may be queued by any thread using | |
34 // AddCookie, UpdateCookieAccessTime, and DeleteCookie. These are flushed to | 53 // AddCookie, UpdateCookieAccessTime, and DeleteCookie. These are flushed to |
35 // disk on the DB thread every 30 seconds, 512 operations, or call to Flush(), | 54 // disk on the DB thread every 30 seconds, 512 operations, or call to Flush(), |
36 // whichever occurs first. | 55 // whichever occurs first. |
37 class SQLitePersistentCookieStore::Backend | 56 class SQLitePersistentCookieStore::Backend |
38 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> { | 57 : public base::RefCountedThreadSafe<SQLitePersistentCookieStore::Backend> { |
39 public: | 58 public: |
40 explicit Backend(const FilePath& path) | 59 explicit Backend(const FilePath& path) |
41 : path_(path), | 60 : path_(path), |
42 db_(NULL), | 61 db_(NULL), |
43 num_pending_(0), | 62 num_pending_(0), |
44 clear_local_state_on_exit_(false) { | 63 clear_local_state_on_exit_(false), |
64 initialized_(false) { | |
45 } | 65 } |
46 | 66 |
47 // Creates or load the SQLite database. | 67 // Creates or loads the SQLite database. |
48 bool Load(const LoadedCallback& loaded_callback); | 68 void Load(const LoadedCallback& loaded_callback); |
69 | |
70 // Loads cookies for the domain key (eTLD+1). | |
71 void LoadCookiesForKey(const std::string& domain, | |
72 const LoadedCallback& loaded_callback); | |
49 | 73 |
50 // Batch a cookie addition. | 74 // Batch a cookie addition. |
51 void AddCookie(const net::CookieMonster::CanonicalCookie& cc); | 75 void AddCookie(const net::CookieMonster::CanonicalCookie& cc); |
52 | 76 |
53 // Batch a cookie access time update. | 77 // Batch a cookie access time update. |
54 void UpdateCookieAccessTime(const net::CookieMonster::CanonicalCookie& cc); | 78 void UpdateCookieAccessTime(const net::CookieMonster::CanonicalCookie& cc); |
55 | 79 |
56 // Batch a cookie deletion. | 80 // Batch a cookie deletion. |
57 void DeleteCookie(const net::CookieMonster::CanonicalCookie& cc); | 81 void DeleteCookie(const net::CookieMonster::CanonicalCookie& cc); |
58 | 82 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 | 115 |
92 OperationType op() const { return op_; } | 116 OperationType op() const { return op_; } |
93 const net::CookieMonster::CanonicalCookie& cc() const { return cc_; } | 117 const net::CookieMonster::CanonicalCookie& cc() const { return cc_; } |
94 | 118 |
95 private: | 119 private: |
96 OperationType op_; | 120 OperationType op_; |
97 net::CookieMonster::CanonicalCookie cc_; | 121 net::CookieMonster::CanonicalCookie cc_; |
98 }; | 122 }; |
99 | 123 |
100 private: | 124 private: |
101 // Creates or load the SQLite database on DB thread. | 125 // Creates or loads the SQLite database on DB thread. |
102 void LoadAndNotifyOnDBThread(const LoadedCallback& loaded_callback); | 126 void LoadAndNotifyOnDBThread(const LoadedCallback& loaded_callback); |
103 // Notify the CookieMonster when loading complete. | 127 |
128 // Loads cookies for the domain key (eTLD+1) on DB thread. | |
129 void LoadKeyAndNotifyOnDBThread(const std::string& domains, | |
130 const LoadedCallback& loaded_callback); | |
131 | |
132 // Notifies the CookieMonster when loading completes for a specific domain key | |
133 // or for all domain keys. Triggers the callback and passes it all cookies | |
134 // that have been loaded from DB since last IO notification. | |
104 void NotifyOnIOThread( | 135 void NotifyOnIOThread( |
105 const LoadedCallback& loaded_callback, | 136 const LoadedCallback& loaded_callback, |
106 bool load_success, | 137 bool load_success); |
107 const std::vector<net::CookieMonster::CanonicalCookie*>& cookies); | |
108 // Initialize the data base. | 138 // Initialize the data base. |
139 | |
erikwright (departed)
2011/10/06 17:16:47
Remove this blank line.
guohui
2011/10/06 18:34:54
Done.
| |
109 bool InitializeDatabase(); | 140 bool InitializeDatabase(); |
110 // Load cookies to the data base, and read cookies. | 141 |
111 bool LoadInternal(std::vector<net::CookieMonster::CanonicalCookie*>* cookies); | 142 // Chain load cookies from DB by domain key. |
erikwright (departed)
2011/10/06 17:16:47
Update the comment:
Loads cookies for the next do
guohui
2011/10/06 18:34:54
Done.
| |
143 void ChainLoadCookies(const LoadedCallback& loaded_callback); | |
144 | |
145 // Load all cookies for a set of domains/hosts | |
146 bool LoadCookiesForDomains(const std::set<std::string>& key); | |
112 | 147 |
113 // Batch a cookie operation (add or delete) | 148 // Batch a cookie operation (add or delete) |
114 void BatchOperation(PendingOperation::OperationType op, | 149 void BatchOperation(PendingOperation::OperationType op, |
115 const net::CookieMonster::CanonicalCookie& cc); | 150 const net::CookieMonster::CanonicalCookie& cc); |
116 // Commit our pending operations to the database. | 151 // Commit our pending operations to the database. |
117 void Commit(); | 152 void Commit(); |
118 // Close() executed on the background thread. | 153 // Close() executed on the background thread. |
119 void InternalBackgroundClose(); | 154 void InternalBackgroundClose(); |
120 | 155 |
121 FilePath path_; | 156 FilePath path_; |
122 scoped_ptr<sql::Connection> db_; | 157 scoped_ptr<sql::Connection> db_; |
123 sql::MetaTable meta_table_; | 158 sql::MetaTable meta_table_; |
124 | 159 |
125 typedef std::list<PendingOperation*> PendingOperationsList; | 160 typedef std::list<PendingOperation*> PendingOperationsList; |
126 PendingOperationsList pending_; | 161 PendingOperationsList pending_; |
127 PendingOperationsList::size_type num_pending_; | 162 PendingOperationsList::size_type num_pending_; |
128 // True if the persistent store should be deleted upon destruction. | 163 // True if the persistent store should be deleted upon destruction. |
129 bool clear_local_state_on_exit_; | 164 bool clear_local_state_on_exit_; |
130 // Guard |pending_|, |num_pending_| and |clear_local_state_on_exit_|. | 165 // Guard |cookies_|, |pending_|, |num_pending_| and |
166 // |clear_local_state_on_exit_|. | |
131 base::Lock lock_; | 167 base::Lock lock_; |
132 | 168 |
169 // Temporary buffer for cookies loaded from DB. Accumulates cookies to reduce | |
170 // the number of messages sent to the IO thread. Sent back in response to | |
171 // individual load requests for domain keys or when all loading completes. | |
172 std::vector<net::CookieMonster::CanonicalCookie*> cookies_; | |
173 | |
174 // Map of domain keys(eTLD+1) to domains/hosts that are to be loaded from DB. | |
175 std::map<std::string, std::set<std::string>> keys_to_load_; | |
176 | |
177 // Indicates if DB has been initialized. | |
178 bool initialized_; | |
179 | |
133 DISALLOW_COPY_AND_ASSIGN(Backend); | 180 DISALLOW_COPY_AND_ASSIGN(Backend); |
134 }; | 181 }; |
135 | 182 |
136 // Version number of the database. In version 4, we migrated the time epoch. | 183 // Version number of the database. In version 4, we migrated the time epoch. |
137 // If you open the DB with an older version on Mac or Linux, the times will | 184 // If you open the DB with an older version on Mac or Linux, the times will |
138 // look wonky, but the file will likely be usable. On Windows version 3 and 4 | 185 // look wonky, but the file will likely be usable. On Windows version 3 and 4 |
139 // are the same. | 186 // are the same. |
140 // | 187 // |
141 // Version 3 updated the database to include the last access time, so we can | 188 // Version 3 updated the database to include the last access time, so we can |
142 // expire them in decreasing order of use when we've reached the maximum | 189 // expire them in decreasing order of use when we've reached the maximum |
(...skipping 17 matching lines...) Expand all Loading... | |
160 "secure INTEGER NOT NULL," | 207 "secure INTEGER NOT NULL," |
161 "httponly INTEGER NOT NULL," | 208 "httponly INTEGER NOT NULL," |
162 "last_access_utc INTEGER NOT NULL)")) | 209 "last_access_utc INTEGER NOT NULL)")) |
163 return false; | 210 return false; |
164 } | 211 } |
165 | 212 |
166 // Try to create the index every time. Older versions did not have this index, | 213 // Try to create the index every time. Older versions did not have this index, |
167 // so we want those people to get it. Ignore errors, since it may exist. | 214 // so we want those people to get it. Ignore errors, since it may exist. |
168 db->Execute("CREATE INDEX IF NOT EXISTS cookie_times ON cookies" | 215 db->Execute("CREATE INDEX IF NOT EXISTS cookie_times ON cookies" |
169 " (creation_utc)"); | 216 " (creation_utc)"); |
217 | |
218 db->Execute("CREATE INDEX IF NOT EXISTS domain ON cookies(host_key)"); | |
219 | |
170 return true; | 220 return true; |
171 } | 221 } |
172 | 222 |
173 } // namespace | 223 } // namespace |
174 | 224 |
175 bool SQLitePersistentCookieStore::Backend::Load( | 225 void SQLitePersistentCookieStore::Backend::Load( |
176 const LoadedCallback& loaded_callback) { | 226 const LoadedCallback& loaded_callback) { |
177 // This function should be called only once per instance. | 227 // This function should be called only once per instance. |
178 DCHECK(!db_.get()); | 228 DCHECK(!db_.get()); |
179 BrowserThread::PostTask( | 229 BrowserThread::PostTask( |
180 BrowserThread::DB, FROM_HERE, | 230 BrowserThread::DB, FROM_HERE, |
181 base::Bind(&Backend::LoadAndNotifyOnDBThread, base::Unretained(this), | 231 base::Bind(&Backend::LoadAndNotifyOnDBThread, this, loaded_callback)); |
182 loaded_callback)); | 232 } |
183 return true; | 233 |
234 void SQLitePersistentCookieStore::Backend::LoadCookiesForKey( | |
235 const std::string& key, | |
236 const LoadedCallback& loaded_callback) { | |
237 BrowserThread::PostTask( | |
238 BrowserThread::DB, FROM_HERE, | |
239 base::Bind(&Backend::LoadKeyAndNotifyOnDBThread, this, | |
240 key, | |
241 loaded_callback)); | |
184 } | 242 } |
185 | 243 |
186 void SQLitePersistentCookieStore::Backend::LoadAndNotifyOnDBThread( | 244 void SQLitePersistentCookieStore::Backend::LoadAndNotifyOnDBThread( |
187 const LoadedCallback& loaded_callback) { | 245 const LoadedCallback& loaded_callback) { |
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
189 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | |
190 | 247 |
191 bool load_success = LoadInternal(&cookies); | 248 if (!InitializeDatabase()) { |
249 BrowserThread::PostTask( | |
250 BrowserThread::IO, FROM_HERE, | |
251 base::Bind(&SQLitePersistentCookieStore::Backend::NotifyOnIOThread, | |
252 this, loaded_callback, false)); | |
253 } else { | |
254 ChainLoadCookies(loaded_callback); | |
255 } | |
256 } | |
192 | 257 |
193 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 258 void SQLitePersistentCookieStore::Backend::LoadKeyAndNotifyOnDBThread( |
194 &SQLitePersistentCookieStore::Backend::NotifyOnIOThread, | 259 const std::string& key, |
195 base::Unretained(this), loaded_callback, load_success, cookies)); | 260 const LoadedCallback& loaded_callback) { |
261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
262 | |
263 bool success = false; | |
264 if (InitializeDatabase()) { | |
265 std::map<std::string, std::set<std::string> >::iterator | |
266 it = keys_to_load_.find(key); | |
267 if (it != keys_to_load_.end()) { | |
268 success = LoadCookiesForDomains(it->second); | |
269 keys_to_load_.erase(it); | |
270 } else { | |
271 success = true; | |
272 } | |
273 } | |
274 | |
275 BrowserThread::PostTask( | |
276 BrowserThread::IO, FROM_HERE, | |
277 base::Bind(&SQLitePersistentCookieStore::Backend::NotifyOnIOThread, | |
278 this, loaded_callback, success)); | |
196 } | 279 } |
197 | 280 |
198 void SQLitePersistentCookieStore::Backend::NotifyOnIOThread( | 281 void SQLitePersistentCookieStore::Backend::NotifyOnIOThread( |
199 const LoadedCallback& loaded_callback, | 282 const LoadedCallback& loaded_callback, |
200 bool load_success, | 283 bool load_success) { |
201 const std::vector<net::CookieMonster::CanonicalCookie*>& cookies) { | |
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
285 | |
286 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | |
287 { | |
288 base::AutoLock locked(lock_); | |
289 cookies = cookies_; | |
290 cookies_.clear(); | |
291 } | |
292 | |
203 loaded_callback.Run(cookies); | 293 loaded_callback.Run(cookies); |
204 } | 294 } |
205 | 295 |
206 bool SQLitePersistentCookieStore::Backend::InitializeDatabase() { | 296 bool SQLitePersistentCookieStore::Backend::InitializeDatabase() { |
297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
298 | |
299 if (initialized_) { | |
300 return true; | |
301 } | |
302 | |
207 const FilePath dir = path_.DirName(); | 303 const FilePath dir = path_.DirName(); |
208 if (!file_util::PathExists(dir) && !file_util::CreateDirectory(dir)) { | 304 if (!file_util::PathExists(dir) && !file_util::CreateDirectory(dir)) { |
209 return false; | 305 return false; |
210 } | 306 } |
211 | 307 |
212 db_.reset(new sql::Connection); | 308 db_.reset(new sql::Connection); |
213 if (!db_->Open(path_)) { | 309 if (!db_->Open(path_)) { |
214 NOTREACHED() << "Unable to open cookie DB."; | 310 NOTREACHED() << "Unable to open cookie DB."; |
215 db_.reset(); | 311 db_.reset(); |
216 return false; | 312 return false; |
217 } | 313 } |
218 | 314 |
219 db_->set_error_delegate(GetErrorHandlerForCookieDb()); | 315 db_->set_error_delegate(GetErrorHandlerForCookieDb()); |
220 | 316 |
221 if (!EnsureDatabaseVersion() || !InitTable(db_.get())) { | 317 if (!EnsureDatabaseVersion() || !InitTable(db_.get())) { |
222 NOTREACHED() << "Unable to open cookie DB."; | 318 NOTREACHED() << "Unable to open cookie DB."; |
223 db_.reset(); | 319 db_.reset(); |
224 return false; | 320 return false; |
225 } | 321 } |
226 | 322 |
227 db_->Preload(); | 323 db_->Preload(); |
228 return true; | |
229 } | |
230 | 324 |
231 bool SQLitePersistentCookieStore::Backend::LoadInternal( | 325 // Retrieve all the domains |
232 std::vector<net::CookieMonster::CanonicalCookie*>* cookies) { | 326 sql::Statement smt(db_->GetUniqueStatement( |
233 if (!InitializeDatabase()) { | 327 "SELECT DISTINCT host_key FROM cookies")); |
234 return false; | |
235 } | |
236 | 328 |
237 // Slurp all the cookies into the out-vector. | |
238 sql::Statement smt(db_->GetUniqueStatement( | |
239 "SELECT creation_utc, host_key, name, value, path, expires_utc, secure, " | |
240 "httponly, last_access_utc FROM cookies")); | |
241 if (!smt) { | 329 if (!smt) { |
242 NOTREACHED() << "select statement prep failed"; | 330 NOTREACHED() << "select statement prep failed"; |
243 db_.reset(); | 331 db_.reset(); |
244 return false; | 332 return false; |
245 } | 333 } |
246 | 334 |
335 // Build a map of domain keys (always eTLD+1) to domains. | |
247 while (smt.Step()) { | 336 while (smt.Step()) { |
248 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( | 337 std::string domain = smt.ColumnString(0); |
249 new net::CookieMonster::CanonicalCookie( | 338 std::string key = |
250 // The "source" URL is not used with persisted cookies. | 339 net::RegistryControlledDomainService::GetDomainAndRegistry(domain); |
251 GURL(), // Source | 340 |
252 smt.ColumnString(2), // name | 341 std::map<std::string, std::set<std::string> >::iterator it = |
253 smt.ColumnString(3), // value | 342 keys_to_load_.find(key); |
254 smt.ColumnString(1), // domain | 343 if (it == keys_to_load_.end()) |
255 smt.ColumnString(4), // path | 344 it = keys_to_load_.insert(std::make_pair |
256 std::string(), // TODO(abarth): Persist mac_key | 345 (key, std::set<std::string>())).first; |
257 std::string(), // TODO(abarth): Persist mac_algorithm | 346 it->second.insert(domain); |
258 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc | |
259 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc | |
260 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc | |
261 smt.ColumnInt(6) != 0, // secure | |
262 smt.ColumnInt(7) != 0, // httponly | |
263 true)); // has_expires | |
264 DLOG_IF(WARNING, | |
265 cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; | |
266 cookies->push_back(cc.release()); | |
267 } | 347 } |
268 | 348 |
349 initialized_ = true; | |
269 return true; | 350 return true; |
270 } | 351 } |
271 | 352 |
353 void SQLitePersistentCookieStore::Backend::ChainLoadCookies( | |
354 const LoadedCallback& loaded_callback) { | |
355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
356 | |
357 bool load_success = true; | |
358 | |
359 if (keys_to_load_.size() > 0) { | |
360 // Load cookies for the first domain key. | |
361 std::map<std::string, std::set<std::string> >::iterator | |
362 it = keys_to_load_.begin(); | |
363 load_success = LoadCookiesForDomains(it->second); | |
364 keys_to_load_.erase(it); | |
365 } | |
366 | |
367 // If load is successful and there are more domain keys to be loaded, | |
368 // then post a DB task to continue chain-load; | |
369 // Otherwise notify on IO thread. | |
370 if (load_success && keys_to_load_.size() > 0) { | |
371 BrowserThread::PostTask( | |
372 BrowserThread::DB, FROM_HERE, | |
373 base::Bind(&Backend::ChainLoadCookies, this, loaded_callback)); | |
374 } else { | |
375 BrowserThread::PostTask( | |
376 BrowserThread::IO, FROM_HERE, | |
377 base::Bind(&SQLitePersistentCookieStore::Backend::NotifyOnIOThread, | |
378 this, loaded_callback, load_success)); | |
379 } | |
380 } | |
381 | |
382 bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains( | |
383 const std::set<std::string>& domains) { | |
384 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
385 | |
386 sql::Statement smt(db_->GetCachedStatement(SQL_FROM_HERE, | |
387 "SELECT creation_utc, host_key, name, value, path, expires_utc, secure, " | |
388 "httponly, last_access_utc FROM cookies WHERE host_key = ?")); | |
389 if (!smt) { | |
390 NOTREACHED() << "select statement prep failed"; | |
391 db_.reset(); | |
392 return false; | |
393 } | |
394 | |
395 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | |
396 std::set<std::string>::const_iterator it = domains.begin(); | |
397 for (; it != domains.end(); ++it) { | |
398 smt.BindString(0, *it); | |
399 while (smt.Step()) { | |
400 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( | |
401 new net::CookieMonster::CanonicalCookie( | |
402 // The "source" URL is not used with persisted cookies. | |
403 GURL(), // Source | |
404 smt.ColumnString(2), // name | |
405 smt.ColumnString(3), // value | |
406 smt.ColumnString(1), // domain | |
407 smt.ColumnString(4), // path | |
408 std::string(), // TODO(abarth): Persist mac_key | |
409 std::string(), // TODO(abarth): Persist mac_algorithm | |
410 Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc | |
411 Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc | |
412 Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc | |
413 smt.ColumnInt(6) != 0, // secure | |
414 smt.ColumnInt(7) != 0, // httponly | |
415 true)); // has_expires | |
416 DLOG_IF(WARNING, | |
417 cc->CreationDate() > Time::Now()) << L"CreationDate too recent"; | |
418 cookies.push_back(cc.release()); | |
419 } | |
420 smt.Reset(); | |
421 } | |
422 { | |
423 base::AutoLock locked(lock_); | |
424 cookies_.insert(cookies_.end(), cookies.begin(), cookies.end()); | |
425 } | |
426 return true; | |
427 } | |
428 | |
272 bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() { | 429 bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() { |
273 // Version check. | 430 // Version check. |
274 if (!meta_table_.Init( | 431 if (!meta_table_.Init( |
275 db_.get(), kCurrentVersionNumber, kCompatibleVersionNumber)) { | 432 db_.get(), kCurrentVersionNumber, kCompatibleVersionNumber)) { |
276 return false; | 433 return false; |
277 } | 434 } |
278 | 435 |
279 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { | 436 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { |
280 LOG(WARNING) << "Cookie database is too new."; | 437 LOG(WARNING) << "Cookie database is too new."; |
281 return false; | 438 return false; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 | 684 |
528 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { | 685 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { |
529 if (backend_.get()) { | 686 if (backend_.get()) { |
530 backend_->Close(); | 687 backend_->Close(); |
531 // Release our reference, it will probably still have a reference if the | 688 // Release our reference, it will probably still have a reference if the |
532 // background thread has not run Close() yet. | 689 // background thread has not run Close() yet. |
533 backend_ = NULL; | 690 backend_ = NULL; |
534 } | 691 } |
535 } | 692 } |
536 | 693 |
537 bool SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { | 694 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { |
538 return backend_->Load(loaded_callback); | 695 backend_->Load(loaded_callback); |
696 } | |
697 | |
698 void SQLitePersistentCookieStore::LoadCookiesForKey( | |
699 const std::string& key, | |
700 const LoadedCallback& loaded_callback) { | |
701 backend_->LoadCookiesForKey(key, loaded_callback); | |
539 } | 702 } |
540 | 703 |
541 void SQLitePersistentCookieStore::AddCookie( | 704 void SQLitePersistentCookieStore::AddCookie( |
542 const net::CookieMonster::CanonicalCookie& cc) { | 705 const net::CookieMonster::CanonicalCookie& cc) { |
543 if (backend_.get()) | 706 if (backend_.get()) |
544 backend_->AddCookie(cc); | 707 backend_->AddCookie(cc); |
545 } | 708 } |
546 | 709 |
547 void SQLitePersistentCookieStore::UpdateCookieAccessTime( | 710 void SQLitePersistentCookieStore::UpdateCookieAccessTime( |
548 const net::CookieMonster::CanonicalCookie& cc) { | 711 const net::CookieMonster::CanonicalCookie& cc) { |
(...skipping 12 matching lines...) Expand all Loading... | |
561 if (backend_.get()) | 724 if (backend_.get()) |
562 backend_->SetClearLocalStateOnExit(clear_local_state); | 725 backend_->SetClearLocalStateOnExit(clear_local_state); |
563 } | 726 } |
564 | 727 |
565 void SQLitePersistentCookieStore::Flush(Task* completion_task) { | 728 void SQLitePersistentCookieStore::Flush(Task* completion_task) { |
566 if (backend_.get()) | 729 if (backend_.get()) |
567 backend_->Flush(completion_task); | 730 backend_->Flush(completion_task); |
568 else if (completion_task) | 731 else if (completion_task) |
569 MessageLoop::current()->PostTask(FROM_HERE, completion_task); | 732 MessageLoop::current()->PostTask(FROM_HERE, completion_task); |
570 } | 733 } |
OLD | NEW |