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