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
10ProfileSyncServiceObserverMock::ProfileSyncServiceObserverMock() {}
11
12ProfileSyncServiceObserverMock::~ProfileSyncServiceObserverMock() {}
13
14ThreadNotificationService::ThreadNotificationService(
15    base::Thread* notification_thread)
16    : done_event_(false, false),
17      notification_thread_(notification_thread) {}
18
19void 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
27void 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
36ThreadNotificationService::~ThreadNotificationService() {}
37
38void ThreadNotificationService::InitTask() {
39  service_.reset(new NotificationService());
40  done_event_.Signal();
41}
42
43void ThreadNotificationService::TearDownTask() {
44  service_.reset(NULL);
45  done_event_.Signal();
46}
47
48ThreadNotifier::ThreadNotifier(base::Thread* notify_thread)
49    : done_event_(false, false),
50      notify_thread_(notify_thread) {}
51
52void ThreadNotifier::Notify(NotificationType type,
53                            const NotificationDetails& details) {
54  Notify(type, NotificationService::AllSources(), details);
55}
56
57void 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
71ThreadNotifier::~ThreadNotifier() {}
72
73void 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