Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/test_extension_registry_observer.h" | |
| 6 | |
| 7 #include "base/run_loop.h" | |
| 8 #include "extensions/browser/extension_registry.h" | |
| 9 | |
| 10 namespace extensions { | |
| 11 | |
| 12 class TestExtensionRegistryObserver::Waiter { | |
| 13 public: | |
| 14 Waiter() : observed_(false), runner_(NULL), extension_id_(std::string()) {} | |
| 15 | |
| 16 void Wait(const std::string& id) { | |
| 17 if (observed_ && extension_id_ == id) | |
| 18 return; | |
| 19 | |
| 20 extension_id_ = id; | |
| 21 runner_ = new content::MessageLoopRunner(); | |
| 22 runner_->Run(); | |
| 23 } | |
| 24 | |
| 25 void OnObserved(const std::string& id) { | |
| 26 observed_ = true; | |
| 27 extension_id_ = id; | |
| 28 | |
| 29 if (runner_) { | |
| 30 runner_->Quit(); | |
| 31 runner_ = NULL; | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 private: | |
| 36 bool observed_; | |
| 37 scoped_refptr<content::MessageLoopRunner> runner_; | |
| 38 | |
| 39 std::string extension_id_; | |
| 40 | |
| 41 DISALLOW_COPY_AND_ASSIGN(Waiter); | |
| 42 }; | |
| 43 | |
| 44 TestExtensionRegistryObserver::TestExtensionRegistryObserver( | |
| 45 ExtensionRegistry* registry) | |
| 46 : will_be_installed_waiter_(new Waiter()), | |
|
Yoyo Zhou
2014/06/17 18:15:37
Do we need to instantiate all these if they're not
Yoyo Zhou
2014/06/17 21:48:06
Ah, I see what you mean.
Right now there is a fla
limasdf
2014/06/19 18:06:28
Done.
| |
| 47 uninstalled_waiter_(new Waiter()), | |
| 48 loaded_waiter_(new Waiter()), | |
| 49 unloaded_waiter_(new Waiter()), | |
| 50 extension_registry_observer_(this) { | |
| 51 extension_registry_observer_.Add(registry); | |
| 52 } | |
| 53 | |
| 54 TestExtensionRegistryObserver::~TestExtensionRegistryObserver() { | |
| 55 } | |
| 56 | |
| 57 void TestExtensionRegistryObserver::WaitForExtensionUninstalled( | |
| 58 const std::string& extension_id) { | |
| 59 uninstalled_waiter_->Wait(extension_id); | |
| 60 } | |
| 61 | |
| 62 void TestExtensionRegistryObserver::WaitForExtensionWillBeInstalled( | |
| 63 const std::string& extension_id) { | |
| 64 will_be_installed_waiter_->Wait(extension_id); | |
| 65 } | |
| 66 | |
| 67 void TestExtensionRegistryObserver::WaitForExtensionLoaded( | |
| 68 const std::string& extension_id) { | |
| 69 loaded_waiter_->Wait(extension_id); | |
| 70 } | |
| 71 | |
| 72 void TestExtensionRegistryObserver::WaitForExtensionUnloaded( | |
| 73 const std::string& extension_id) { | |
| 74 unloaded_waiter_->Wait(extension_id); | |
| 75 } | |
| 76 | |
| 77 void TestExtensionRegistryObserver::OnExtensionWillBeInstalled( | |
| 78 content::BrowserContext* browser_context, | |
| 79 const Extension* extension, | |
| 80 bool is_update, | |
| 81 bool from_ephemeral, | |
| 82 const std::string& old_name) { | |
| 83 will_be_installed_waiter_->OnObserved(extension->id()); | |
| 84 } | |
| 85 | |
| 86 void TestExtensionRegistryObserver::OnExtensionUninstalled( | |
| 87 content::BrowserContext* browser_context, | |
| 88 const Extension* extension) { | |
| 89 uninstalled_waiter_->OnObserved(extension->id()); | |
| 90 } | |
| 91 | |
| 92 void TestExtensionRegistryObserver::OnExtensionLoaded( | |
| 93 content::BrowserContext* browser_context, | |
| 94 const Extension* extension) { | |
| 95 loaded_waiter_->OnObserved(extension->id()); | |
| 96 } | |
| 97 | |
| 98 void TestExtensionRegistryObserver::OnExtensionUnloaded( | |
| 99 content::BrowserContext* browser_context, | |
| 100 const Extension* extension, | |
| 101 UnloadedExtensionInfo::Reason reason) { | |
| 102 unloaded_waiter_->OnObserved(extension->id()); | |
| 103 } | |
| 104 | |
| 105 } // namespace extensions | |
| OLD | NEW |