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_origin_bound_cert_store.h" | 5 #include "chrome/browser/net/sqlite_origin_bound_cert_store.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" |
10 #include "base/file_path.h" | 11 #include "base/file_path.h" |
11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
16 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" |
17 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" | 18 #include "chrome/browser/diagnostics/sqlite_diagnostics.h" |
18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
19 #include "sql/meta_table.h" | 20 #include "sql/meta_table.h" |
(...skipping 20 matching lines...) Expand all Loading... |
40 | 41 |
41 // Batch an origin bound cert addition. | 42 // Batch an origin bound cert addition. |
42 void AddOriginBoundCert( | 43 void AddOriginBoundCert( |
43 const net::DefaultOriginBoundCertStore::OriginBoundCert& cert); | 44 const net::DefaultOriginBoundCertStore::OriginBoundCert& cert); |
44 | 45 |
45 // Batch an origin bound cert deletion. | 46 // Batch an origin bound cert deletion. |
46 void DeleteOriginBoundCert( | 47 void DeleteOriginBoundCert( |
47 const net::DefaultOriginBoundCertStore::OriginBoundCert& cert); | 48 const net::DefaultOriginBoundCertStore::OriginBoundCert& cert); |
48 | 49 |
49 // Commit pending operations as soon as possible. | 50 // Commit pending operations as soon as possible. |
50 void Flush(Task* completion_task); | 51 void Flush(const base::Closure& completion_task); |
51 | 52 |
52 // Commit any pending operations and close the database. This must be called | 53 // Commit any pending operations and close the database. This must be called |
53 // before the object is destructed. | 54 // before the object is destructed. |
54 void Close(); | 55 void Close(); |
55 | 56 |
56 void SetClearLocalStateOnExit(bool clear_local_state); | 57 void SetClearLocalStateOnExit(bool clear_local_state); |
57 | 58 |
58 private: | 59 private: |
59 friend class base::RefCountedThreadSafe<SQLiteOriginBoundCertStore::Backend>; | 60 friend class base::RefCountedThreadSafe<SQLiteOriginBoundCertStore::Backend>; |
60 | 61 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 break; | 316 break; |
316 | 317 |
317 default: | 318 default: |
318 NOTREACHED(); | 319 NOTREACHED(); |
319 break; | 320 break; |
320 } | 321 } |
321 } | 322 } |
322 transaction.Commit(); | 323 transaction.Commit(); |
323 } | 324 } |
324 | 325 |
325 void SQLiteOriginBoundCertStore::Backend::Flush(Task* completion_task) { | 326 void SQLiteOriginBoundCertStore::Backend::Flush( |
| 327 const base::Closure& completion_task) { |
326 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::DB)); | 328 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::DB)); |
327 BrowserThread::PostTask( | 329 BrowserThread::PostTask( |
328 BrowserThread::DB, FROM_HERE, NewRunnableMethod(this, &Backend::Commit)); | 330 BrowserThread::DB, FROM_HERE, base::Bind(&Backend::Commit, this)); |
329 if (completion_task) { | 331 if (!completion_task.is_null()) { |
330 // We want the completion task to run immediately after Commit() returns. | 332 // We want the completion task to run immediately after Commit() returns. |
331 // Posting it from here means there is less chance of another task getting | 333 // Posting it from here means there is less chance of another task getting |
332 // onto the message queue first, than if we posted it from Commit() itself. | 334 // onto the message queue first, than if we posted it from Commit() itself. |
333 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, completion_task); | 335 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, completion_task); |
334 } | 336 } |
335 } | 337 } |
336 | 338 |
337 // Fire off a close message to the background thread. We could still have a | 339 // Fire off a close message to the background thread. We could still have a |
338 // pending commit timer that will be holding a reference on us, but if/when | 340 // pending commit timer that will be holding a reference on us, but if/when |
339 // this fires we will already have been cleaned up and it will be ignored. | 341 // this fires we will already have been cleaned up and it will be ignored. |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 if (backend_.get()) | 393 if (backend_.get()) |
392 backend_->DeleteOriginBoundCert(cert); | 394 backend_->DeleteOriginBoundCert(cert); |
393 } | 395 } |
394 | 396 |
395 void SQLiteOriginBoundCertStore::SetClearLocalStateOnExit( | 397 void SQLiteOriginBoundCertStore::SetClearLocalStateOnExit( |
396 bool clear_local_state) { | 398 bool clear_local_state) { |
397 if (backend_.get()) | 399 if (backend_.get()) |
398 backend_->SetClearLocalStateOnExit(clear_local_state); | 400 backend_->SetClearLocalStateOnExit(clear_local_state); |
399 } | 401 } |
400 | 402 |
401 void SQLiteOriginBoundCertStore::Flush(Task* completion_task) { | 403 void SQLiteOriginBoundCertStore::Flush(const base::Closure& completion_task) { |
402 if (backend_.get()) | 404 if (backend_.get()) |
403 backend_->Flush(completion_task); | 405 backend_->Flush(completion_task); |
404 else if (completion_task) | 406 else if (!completion_task.is_null()) |
405 MessageLoop::current()->PostTask(FROM_HERE, completion_task); | 407 MessageLoop::current()->PostTask(FROM_HERE, completion_task); |
406 } | 408 } |
OLD | NEW |