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

Side by Side Diff: extensions/browser/extension_test_registry_observer.cc

Issue 334083002: Add a test helper class for ExtensionRegistry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ben's comments Created 6 years, 6 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
OLDNEW
(Empty)
1 // Copyright 2014 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 "extensions/browser/extension_test_registry_observer.h"
6
7 #include "base/run_loop.h"
8 #include "extensions/browser/extension_registry.h"
9
10 namespace extensions {
11
12 class ExtensionTestRegistryObserver::Waiter {
13 public:
14 Waiter() : waiting_(false), observed_(false) {}
15
16 void Wait() {
17 if (observed_)
18 return;
19
20 waiting_ = true;
21 runner_->Run();
22 }
23
24 void OnObserved() {
25 observed_ = true;
26 if (waiting_) {
27 waiting_ = false;
28 runner_->Quit();
29 }
30 }
31
32 private:
33 bool waiting_;
34 bool observed_;
35 scoped_refptr<content::MessageLoopRunner> runner_;
not at google - send to devlin 2014/06/16 21:42:08 Doesn't look like this is ever initialized? And wh
limasdf 2014/06/17 17:20:55 Exactly. Happy to remove |waiting_|.
36
37 DISALLOW_COPY_AND_ASSIGN(Waiter);
38 };
39
40 ExtensionTestRegistryObserver::ExtensionTestRegistryObserver(
41 ExtensionRegistry* registry)
42 : installed_waiter_(new Waiter()),
43 uninstalled_waiter_(new Waiter()),
44 extension_registry_observer_(this) {
45 extension_registry_observer_.Add(registry);
46 }
47
48 ExtensionTestRegistryObserver::~ExtensionTestRegistryObserver() {
49 }
50
51 void ExtensionTestRegistryObserver::WaitForAnyExtensionUninstalled() {
52 uninstalled_waiter_->Wait();
53 }
54
55 void ExtensionTestRegistryObserver::WaitForAnyExtensionWillBeInstalled() {
56 installed_waiter_->Wait();
57 }
58
59 void ExtensionTestRegistryObserver::OnExtensionWillBeInstalled(
60 content::BrowserContext* browser_context,
61 const Extension* extension,
62 bool is_update,
63 bool from_ephemeral,
64 const std::string& old_name) {
65 installed_waiter_->OnObserved();
66 }
67
68 void ExtensionTestRegistryObserver::OnExtensionUninstalled(
69 content::BrowserContext* browser_context,
70 const Extension* extension) {
71 uninstalled_waiter_->OnObserved();
72 }
73
74 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698