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 "chrome/test/base/extension_load_waiter.h" | |
| 6 | |
| 7 #include "chrome/browser/chrome_notification_types.h" | |
| 8 #include "chrome/common/extensions/extension_constants.h" | |
| 9 #include "content/public/browser/browser_context.h" | |
| 10 #include "content/public/browser/notification_service.h" | |
| 11 #include "extensions/browser/extension_host.h" | |
| 12 | |
| 13 ExtensionLoadWaiter::ExtensionLoadWaiter() | |
| 14 : load_looper_(NULL), extension_id_(""), browser_context_(NULL) { | |
|
Peter Lundblad
2014/06/11 16:45:05
No need to initialize scoped_refptr with NULL, set
Peter Lundblad
2014/06/11 16:45:05
No need to initialize scoped_refptr with NULL, set
Peter Lundblad
2014/06/11 16:45:06
No need to initialize scoped_refptr with NULL, set
David Tseng
2014/06/11 17:52:54
Done.
| |
| 15 } | |
| 16 | |
| 17 ExtensionLoadWaiter::~ExtensionLoadWaiter() { | |
| 18 } | |
| 19 | |
| 20 void ExtensionLoadWaiter::WaitFor(const char* extension_id) { | |
| 21 Reset(); | |
|
Peter Lundblad
2014/06/11 16:45:05
Suggestion: make this so that you can only wait on
Peter Lundblad
2014/06/11 16:45:06
Suggestion: make this so that you can only wait on
Peter Lundblad
2014/06/11 16:45:06
Suggestion: make this so that you can only wait on
David Tseng
2014/06/11 17:52:54
Done.
| |
| 22 extension_id_ = extension_id; | |
| 23 load_looper_ = new content::MessageLoopRunner(); | |
| 24 registrar_.Add(this, | |
| 25 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | |
| 26 content::NotificationService::AllSources()); | |
| 27 load_looper_->Run(); | |
| 28 } | |
| 29 | |
| 30 void ExtensionLoadWaiter::Observe(int type, | |
| 31 const content::NotificationSource& source, | |
| 32 const content::NotificationDetails& details) { | |
| 33 switch (type) { | |
| 34 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | |
| 35 extensions::ExtensionHost* host = | |
| 36 content::Details<extensions::ExtensionHost>(details).ptr(); | |
| 37 if (host->extension_id() == extension_id_) { | |
| 38 browser_context_ = host->browser_context(); | |
| 39 registrar_.Remove(this, | |
| 40 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | |
| 41 content::NotificationService::AllSources()); | |
| 42 load_looper_->Quit(); | |
| 43 } | |
| 44 break; | |
| 45 } | |
| 46 } | |
| 47 } | |
| 48 void ExtensionLoadWaiter::Reset() { | |
|
dmazzoni
2014/06/10 16:06:16
Nit: blank line before
David Tseng
2014/06/10 20:14:25
Done.
Peter Lundblad
2014/06/11 16:45:05
nit: add blank line.
Peter Lundblad
2014/06/11 16:45:06
nit: add blank line.
Peter Lundblad
2014/06/11 16:45:06
nit: add blank line.
David Tseng
2014/06/11 17:52:54
Already done.
| |
| 49 extension_id_ = ""; | |
| 50 load_looper_ = NULL; | |
| 51 browser_context_ = NULL; | |
| 52 } | |
| OLD | NEW |