Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: chrome/test/thread_observer_helper.h

Issue 7474025: Move more files from chrome/test to chrome/test/base, part #2 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/testing_profile.cc ('k') | content/browser/appcache/appcache_ui_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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 #ifndef CHROME_TEST_THREAD_OBSERVER_HELPER_H__
6 #define CHROME_TEST_THREAD_OBSERVER_HELPER_H__
7 #pragma once
8
9 #include "base/memory/ref_counted.h"
10 #include "base/synchronization/waitable_event.h"
11 #include "content/browser/browser_thread.h"
12 #include "content/common/notification_observer_mock.h"
13 #include "content/common/notification_registrar.h"
14
15 // Helper class to add and remove observers on a non-UI thread from
16 // the UI thread.
17 template <class T, typename Traits>
18 class ThreadObserverHelper : public base::RefCountedThreadSafe<T, Traits> {
19 public:
20 explicit ThreadObserverHelper(BrowserThread::ID id)
21 : id_(id), done_event_(false, false) {}
22
23 void Init() {
24 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
25 BrowserThread::PostTask(
26 id_,
27 FROM_HERE,
28 NewRunnableMethod(this, &ThreadObserverHelper::RegisterObserversTask));
29 done_event_.Wait();
30 }
31
32 virtual ~ThreadObserverHelper() {
33 DCHECK(BrowserThread::CurrentlyOn(id_));
34 registrar_.RemoveAll();
35 }
36
37 NotificationObserverMock* observer() {
38 return &observer_;
39 }
40
41 protected:
42 friend class base::RefCountedThreadSafe<T>;
43
44 virtual void RegisterObservers() = 0;
45
46 NotificationRegistrar registrar_;
47 NotificationObserverMock observer_;
48
49 private:
50 void RegisterObserversTask() {
51 DCHECK(BrowserThread::CurrentlyOn(id_));
52 RegisterObservers();
53 done_event_.Signal();
54 }
55
56 BrowserThread::ID id_;
57 base::WaitableEvent done_event_;
58 };
59
60 class DBThreadObserverHelper;
61 typedef ThreadObserverHelper<
62 DBThreadObserverHelper,
63 BrowserThread::DeleteOnDBThread> DBThreadObserverHelperBase;
64
65 class DBThreadObserverHelper : public DBThreadObserverHelperBase {
66 public:
67 DBThreadObserverHelper() : DBThreadObserverHelperBase(BrowserThread::DB) {}
68 };
69
70 #endif // CHROME_TEST_THREAD_OBSERVER_HELPER_H__
OLDNEW
« no previous file with comments | « chrome/test/testing_profile.cc ('k') | content/browser/appcache/appcache_ui_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698