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