| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 58 BrowserThread::PostTask( | 58 BrowserThread::PostTask( |
| 59 BrowserThread::DB, | 59 BrowserThread::DB, |
| 60 FROM_HERE, | 60 FROM_HERE, |
| 61 base::Bind(&DBThreadObserverHelper::AddObserverTask, | 61 base::Bind(&DBThreadObserverHelper::AddObserverTask, |
| 62 this, | 62 this, |
| 63 make_scoped_refptr(password_store))); | 63 make_scoped_refptr(password_store))); |
| 64 done_event_.Wait(); | 64 done_event_.Wait(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 virtual ~DBThreadObserverHelper() { | |
| 68 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
| 69 registrar_.RemoveAll(); | |
| 70 } | |
| 71 | |
| 72 content::NotificationObserverMock& observer() { | 67 content::NotificationObserverMock& observer() { |
| 73 return observer_; | 68 return observer_; |
| 74 } | 69 } |
| 75 | 70 |
| 76 protected: | 71 protected: |
| 77 friend class base::RefCountedThreadSafe<DBThreadObserverHelper>; | 72 friend struct BrowserThread::DeleteOnThread<BrowserThread::DB>; |
| 73 friend class base::DeleteHelper<DBThreadObserverHelper>; |
| 74 |
| 75 virtual ~DBThreadObserverHelper() { |
| 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 77 registrar_.RemoveAll(); |
| 78 } |
| 78 | 79 |
| 79 void AddObserverTask(PasswordStore* password_store) { | 80 void AddObserverTask(PasswordStore* password_store) { |
| 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 81 registrar_.Add(&observer_, | 82 registrar_.Add(&observer_, |
| 82 chrome::NOTIFICATION_LOGINS_CHANGED, | 83 chrome::NOTIFICATION_LOGINS_CHANGED, |
| 83 content::Source<PasswordStore>(password_store)); | 84 content::Source<PasswordStore>(password_store)); |
| 84 done_event_.Signal(); | 85 done_event_.Signal(); |
| 85 } | 86 } |
| 86 | 87 |
| 87 WaitableEvent done_event_; | 88 WaitableEvent done_event_; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 // Deleting the login should trigger a notification. | 265 // Deleting the login should trigger a notification. |
| 265 store->RemoveLogin(*form); | 266 store->RemoveLogin(*form); |
| 266 | 267 |
| 267 // Wait for PasswordStore to send the notification. | 268 // Wait for PasswordStore to send the notification. |
| 268 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 269 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 269 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 270 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
| 270 done.Wait(); | 271 done.Wait(); |
| 271 | 272 |
| 272 store->ShutdownOnUIThread(); | 273 store->ShutdownOnUIThread(); |
| 273 } | 274 } |
| OLD | NEW |