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); | 138 |
108 // Initialize the data base. | 139 // Initialize the data base. |
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 // Loads cookies for the next domain key from the DB, then either reschedules |
| 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); |
112 | 149 |
113 // Batch a cookie operation (add or delete) | 150 // Batch a cookie operation (add or delete) |
114 void BatchOperation(PendingOperation::OperationType op, | 151 void BatchOperation(PendingOperation::OperationType op, |
115 const net::CookieMonster::CanonicalCookie& cc); | 152 const net::CookieMonster::CanonicalCookie& cc); |
116 // Commit our pending operations to the database. | 153 // Commit our pending operations to the database. |
117 void Commit(); | 154 void Commit(); |
118 // Close() executed on the background thread. | 155 // Close() executed on the background thread. |
119 void InternalBackgroundClose(); | 156 void InternalBackgroundClose(); |
120 | 157 |
121 FilePath path_; | 158 FilePath path_; |
122 scoped_ptr<sql::Connection> db_; | 159 scoped_ptr<sql::Connection> db_; |
123 sql::MetaTable meta_table_; | 160 sql::MetaTable meta_table_; |
124 | 161 |
125 typedef std::list<PendingOperation*> PendingOperationsList; | 162 typedef std::list<PendingOperation*> PendingOperationsList; |
126 PendingOperationsList pending_; | 163 PendingOperationsList pending_; |
127 PendingOperationsList::size_type num_pending_; | 164 PendingOperationsList::size_type num_pending_; |
128 // True if the persistent store should be deleted upon destruction. | 165 // True if the persistent store should be deleted upon destruction. |
129 bool clear_local_state_on_exit_; | 166 bool clear_local_state_on_exit_; |
130 // Guard |pending_|, |num_pending_| and |clear_local_state_on_exit_|. | 167 // Guard |cookies_|, |pending_|, |num_pending_| and |
| 168 // |clear_local_state_on_exit_|. |
131 base::Lock lock_; | 169 base::Lock lock_; |
132 | 170 |
| 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 |
133 DISALLOW_COPY_AND_ASSIGN(Backend); | 182 DISALLOW_COPY_AND_ASSIGN(Backend); |
134 }; | 183 }; |
135 | 184 |
136 // Version number of the database. In version 4, we migrated the time epoch. | 185 // 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 | 186 // 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 | 187 // look wonky, but the file will likely be usable. On Windows version 3 and 4 |
139 // are the same. | 188 // are the same. |
140 // | 189 // |
141 // Version 3 updated the database to include the last access time, so we can | 190 // 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 | 191 // 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," | 209 "secure INTEGER NOT NULL," |
161 "httponly INTEGER NOT NULL," | 210 "httponly INTEGER NOT NULL," |
162 "last_access_utc INTEGER NOT NULL)")) | 211 "last_access_utc INTEGER NOT NULL)")) |
163 return false; | 212 return false; |
164 } | 213 } |
165 | 214 |
166 // Try to create the index every time. Older versions did not have this index, | 215 // 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. | 216 // 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" | 217 db->Execute("CREATE INDEX IF NOT EXISTS cookie_times ON cookies" |
169 " (creation_utc)"); | 218 " (creation_utc)"); |
| 219 |
| 220 db->Execute("CREATE INDEX IF NOT EXISTS domain ON cookies(host_key)"); |
| 221 |
170 return true; | 222 return true; |
171 } | 223 } |
172 | 224 |
173 } // namespace | 225 } // namespace |
174 | 226 |
175 bool SQLitePersistentCookieStore::Backend::Load( | 227 void SQLitePersistentCookieStore::Backend::Load( |
176 const LoadedCallback& loaded_callback) { | 228 const LoadedCallback& loaded_callback) { |
177 // This function should be called only once per instance. | 229 // This function should be called only once per instance. |
178 DCHECK(!db_.get()); | 230 DCHECK(!db_.get()); |
179 BrowserThread::PostTask( | 231 BrowserThread::PostTask( |
180 BrowserThread::DB, FROM_HERE, | 232 BrowserThread::DB, FROM_HERE, |
181 base::Bind(&Backend::LoadAndNotifyOnDBThread, base::Unretained(this), | 233 base::Bind(&Backend::LoadAndNotifyOnDBThread, this, loaded_callback)); |
182 loaded_callback)); | 234 } |
183 return true; | 235 |
| 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)); |
184 } | 244 } |
185 | 245 |
186 void SQLitePersistentCookieStore::Backend::LoadAndNotifyOnDBThread( | 246 void SQLitePersistentCookieStore::Backend::LoadAndNotifyOnDBThread( |
187 const LoadedCallback& loaded_callback) { | 247 const LoadedCallback& loaded_callback) { |
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
189 std::vector<net::CookieMonster::CanonicalCookie*> cookies; | |
190 | 249 |
191 bool load_success = LoadInternal(&cookies); | 250 if (!InitializeDatabase()) { |
| 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 } |
192 | 259 |
193 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | 260 void SQLitePersistentCookieStore::Backend::LoadKeyAndNotifyOnDBThread( |
194 &SQLitePersistentCookieStore::Backend::NotifyOnIOThread, | 261 const std::string& key, |
195 base::Unretained(this), loaded_callback, load_success, cookies)); | 262 const LoadedCallback& loaded_callback) { |
| 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)); |
196 } | 281 } |
197 | 282 |
198 void SQLitePersistentCookieStore::Backend::NotifyOnIOThread( | 283 void SQLitePersistentCookieStore::Backend::NotifyOnIOThread( |
199 const LoadedCallback& loaded_callback, | 284 const LoadedCallback& loaded_callback, |
200 bool load_success, | 285 bool load_success) { |
201 const std::vector<net::CookieMonster::CanonicalCookie*>& cookies) { | |
202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 286 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 |
203 loaded_callback.Run(cookies); | 294 loaded_callback.Run(cookies); |
204 } | 295 } |
205 | 296 |
206 bool SQLitePersistentCookieStore::Backend::InitializeDatabase() { | 297 bool SQLitePersistentCookieStore::Backend::InitializeDatabase() { |
| 298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 299 |
| 300 if (initialized_) { |
| 301 return true; |
| 302 } |
| 303 |
207 const FilePath dir = path_.DirName(); | 304 const FilePath dir = path_.DirName(); |
208 if (!file_util::PathExists(dir) && !file_util::CreateDirectory(dir)) { | 305 if (!file_util::PathExists(dir) && !file_util::CreateDirectory(dir)) { |
209 return false; | 306 return false; |
210 } | 307 } |
211 | 308 |
212 db_.reset(new sql::Connection); | 309 db_.reset(new sql::Connection); |
213 if (!db_->Open(path_)) { | 310 if (!db_->Open(path_)) { |
214 NOTREACHED() << "Unable to open cookie DB."; | 311 NOTREACHED() << "Unable to open cookie DB."; |
215 db_.reset(); | 312 db_.reset(); |
216 return false; | 313 return false; |
217 } | 314 } |
218 | 315 |
219 db_->set_error_delegate(GetErrorHandlerForCookieDb()); | 316 db_->set_error_delegate(GetErrorHandlerForCookieDb()); |
220 | 317 |
221 if (!EnsureDatabaseVersion() || !InitTable(db_.get())) { | 318 if (!EnsureDatabaseVersion() || !InitTable(db_.get())) { |
222 NOTREACHED() << "Unable to open cookie DB."; | 319 NOTREACHED() << "Unable to open cookie DB."; |
223 db_.reset(); | 320 db_.reset(); |
224 return false; | 321 return false; |
225 } | 322 } |
226 | 323 |
227 db_->Preload(); | 324 db_->Preload(); |
228 return true; | |
229 } | |
230 | 325 |
231 bool SQLitePersistentCookieStore::Backend::LoadInternal( | 326 // Retrieve all the domains |
232 std::vector<net::CookieMonster::CanonicalCookie*>* cookies) { | 327 sql::Statement smt(db_->GetUniqueStatement( |
233 if (!InitializeDatabase()) { | 328 "SELECT DISTINCT host_key FROM cookies")); |
234 return false; | |
235 } | |
236 | 329 |
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) { | 330 if (!smt) { |
242 NOTREACHED() << "select statement prep failed"; | 331 NOTREACHED() << "select statement prep failed"; |
243 db_.reset(); | 332 db_.reset(); |
244 return false; | 333 return false; |
245 } | 334 } |
246 | 335 |
| 336 // Build a map of domain keys (always eTLD+1) to domains. |
247 while (smt.Step()) { | 337 while (smt.Step()) { |
248 scoped_ptr<net::CookieMonster::CanonicalCookie> cc( | 338 std::string domain = smt.ColumnString(0); |
249 new net::CookieMonster::CanonicalCookie( | 339 std::string key = |
250 // The "source" URL is not used with persisted cookies. | 340 net::RegistryControlledDomainService::GetDomainAndRegistry(domain); |
251 GURL(), // Source | 341 |
252 smt.ColumnString(2), // name | 342 std::map<std::string, std::set<std::string> >::iterator it = |
253 smt.ColumnString(3), // value | 343 keys_to_load_.find(key); |
254 smt.ColumnString(1), // domain | 344 if (it == keys_to_load_.end()) |
255 smt.ColumnString(4), // path | 345 it = keys_to_load_.insert(std::make_pair |
256 std::string(), // TODO(abarth): Persist mac_key | 346 (key, std::set<std::string>())).first; |
257 std::string(), // TODO(abarth): Persist mac_algorithm | 347 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 } | 348 } |
268 | 349 |
| 350 initialized_ = true; |
269 return true; | 351 return true; |
270 } | 352 } |
271 | 353 |
| 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 |
272 bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() { | 430 bool SQLitePersistentCookieStore::Backend::EnsureDatabaseVersion() { |
273 // Version check. | 431 // Version check. |
274 if (!meta_table_.Init( | 432 if (!meta_table_.Init( |
275 db_.get(), kCurrentVersionNumber, kCompatibleVersionNumber)) { | 433 db_.get(), kCurrentVersionNumber, kCompatibleVersionNumber)) { |
276 return false; | 434 return false; |
277 } | 435 } |
278 | 436 |
279 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { | 437 if (meta_table_.GetCompatibleVersionNumber() > kCurrentVersionNumber) { |
280 LOG(WARNING) << "Cookie database is too new."; | 438 LOG(WARNING) << "Cookie database is too new."; |
281 return false; | 439 return false; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 | 685 |
528 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { | 686 SQLitePersistentCookieStore::~SQLitePersistentCookieStore() { |
529 if (backend_.get()) { | 687 if (backend_.get()) { |
530 backend_->Close(); | 688 backend_->Close(); |
531 // Release our reference, it will probably still have a reference if the | 689 // Release our reference, it will probably still have a reference if the |
532 // background thread has not run Close() yet. | 690 // background thread has not run Close() yet. |
533 backend_ = NULL; | 691 backend_ = NULL; |
534 } | 692 } |
535 } | 693 } |
536 | 694 |
537 bool SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { | 695 void SQLitePersistentCookieStore::Load(const LoadedCallback& loaded_callback) { |
538 return backend_->Load(loaded_callback); | 696 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); |
539 } | 703 } |
540 | 704 |
541 void SQLitePersistentCookieStore::AddCookie( | 705 void SQLitePersistentCookieStore::AddCookie( |
542 const net::CookieMonster::CanonicalCookie& cc) { | 706 const net::CookieMonster::CanonicalCookie& cc) { |
543 if (backend_.get()) | 707 if (backend_.get()) |
544 backend_->AddCookie(cc); | 708 backend_->AddCookie(cc); |
545 } | 709 } |
546 | 710 |
547 void SQLitePersistentCookieStore::UpdateCookieAccessTime( | 711 void SQLitePersistentCookieStore::UpdateCookieAccessTime( |
548 const net::CookieMonster::CanonicalCookie& cc) { | 712 const net::CookieMonster::CanonicalCookie& cc) { |
(...skipping 12 matching lines...) Expand all Loading... |
561 if (backend_.get()) | 725 if (backend_.get()) |
562 backend_->SetClearLocalStateOnExit(clear_local_state); | 726 backend_->SetClearLocalStateOnExit(clear_local_state); |
563 } | 727 } |
564 | 728 |
565 void SQLitePersistentCookieStore::Flush(Task* completion_task) { | 729 void SQLitePersistentCookieStore::Flush(Task* completion_task) { |
566 if (backend_.get()) | 730 if (backend_.get()) |
567 backend_->Flush(completion_task); | 731 backend_->Flush(completion_task); |
568 else if (completion_task) | 732 else if (completion_task) |
569 MessageLoop::current()->PostTask(FROM_HERE, completion_task); | 733 MessageLoop::current()->PostTask(FROM_HERE, completion_task); |
570 } | 734 } |
OLD | NEW |