| 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/sync/profile_sync_test_util.h" | 5 #include "chrome/browser/sync/profile_sync_test_util.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 | 9 |
| 10 using content::BrowserThread; | 10 using content::BrowserThread; |
| 11 | 11 |
| 12 ProfileSyncServiceObserverMock::ProfileSyncServiceObserverMock() {} | 12 ProfileSyncServiceObserverMock::ProfileSyncServiceObserverMock() {} |
| 13 | 13 |
| 14 ProfileSyncServiceObserverMock::~ProfileSyncServiceObserverMock() {} | 14 ProfileSyncServiceObserverMock::~ProfileSyncServiceObserverMock() {} |
| 15 | 15 |
| 16 ThreadNotificationService::ThreadNotificationService( | |
| 17 base::Thread* notification_thread) | |
| 18 : done_event_(false, false), | |
| 19 notification_thread_(notification_thread) {} | |
| 20 | |
| 21 void ThreadNotificationService::Init() { | |
| 22 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 23 notification_thread_->message_loop()->PostTask( | |
| 24 FROM_HERE, | |
| 25 base::Bind(&ThreadNotificationService::InitTask, this)); | |
| 26 done_event_.Wait(); | |
| 27 } | |
| 28 | |
| 29 void ThreadNotificationService::TearDown() { | |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 31 notification_thread_->message_loop()->PostTask( | |
| 32 FROM_HERE, | |
| 33 base::Bind(&ThreadNotificationService::TearDownTask, this)); | |
| 34 done_event_.Wait(); | |
| 35 } | |
| 36 | |
| 37 ThreadNotificationService::~ThreadNotificationService() {} | |
| 38 | |
| 39 void ThreadNotificationService::InitTask() { | |
| 40 service_.reset(content::NotificationService::Create()); | |
| 41 done_event_.Signal(); | |
| 42 } | |
| 43 | |
| 44 void ThreadNotificationService::TearDownTask() { | |
| 45 service_.reset(NULL); | |
| 46 done_event_.Signal(); | |
| 47 } | |
| 48 | |
| 49 ThreadNotifier::ThreadNotifier(base::Thread* notify_thread) | 16 ThreadNotifier::ThreadNotifier(base::Thread* notify_thread) |
| 50 : done_event_(false, false), | 17 : done_event_(false, false), |
| 51 notify_thread_(notify_thread) {} | 18 notify_thread_(notify_thread) {} |
| 52 | 19 |
| 53 void ThreadNotifier::Notify(int type, | 20 void ThreadNotifier::Notify(int type, |
| 54 const content::NotificationDetails& details) { | 21 const content::NotificationDetails& details) { |
| 55 Notify(type, content::NotificationService::AllSources(), details); | 22 Notify(type, content::NotificationService::AllSources(), details); |
| 56 } | 23 } |
| 57 | 24 |
| 58 void ThreadNotifier::Notify(int type, | 25 void ThreadNotifier::Notify(int type, |
| 59 const content::NotificationSource& source, | 26 const content::NotificationSource& source, |
| 60 const content::NotificationDetails& details) { | 27 const content::NotificationDetails& details) { |
| 61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 62 notify_thread_->message_loop()->PostTask( | 29 notify_thread_->message_loop()->PostTask( |
| 63 FROM_HERE, | 30 FROM_HERE, |
| 64 base::Bind(&ThreadNotifier::NotifyTask, this, type, source, details)); | 31 base::Bind(&ThreadNotifier::NotifyTask, this, type, source, details)); |
| 65 done_event_.Wait(); | 32 done_event_.Wait(); |
| 66 } | 33 } |
| 67 | 34 |
| 68 ThreadNotifier::~ThreadNotifier() {} | 35 ThreadNotifier::~ThreadNotifier() {} |
| 69 | 36 |
| 70 void ThreadNotifier::NotifyTask(int type, | 37 void ThreadNotifier::NotifyTask(int type, |
| 71 const content::NotificationSource& source, | 38 const content::NotificationSource& source, |
| 72 const content::NotificationDetails& details) { | 39 const content::NotificationDetails& details) { |
| 73 content::NotificationService::current()->Notify(type, source, details); | 40 content::NotificationService::current()->Notify(type, source, details); |
| 74 done_event_.Signal(); | 41 done_event_.Signal(); |
| 75 } | 42 } |
| OLD | NEW |