| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/base/extension_load_waiter_one_shot.h" | 5 #include "chrome/test/base/extension_load_waiter_one_shot.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/common/extensions/extension_constants.h" | 9 #include "chrome/common/extensions/extension_constants.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
| 12 #include "extensions/browser/extension_host.h" | 12 #include "extensions/browser/extension_host.h" |
| 13 | 13 |
| 14 ExtensionLoadWaiterOneShot::ExtensionLoadWaiterOneShot() : extension_id_(NULL), | 14 ExtensionLoadWaiterOneShot::ExtensionLoadWaiterOneShot() : extension_id_(NULL), |
| 15 browser_context_(NULL) { | 15 browser_context_(NULL) { |
| 16 } | 16 } |
| 17 | 17 |
| 18 ExtensionLoadWaiterOneShot::~ExtensionLoadWaiterOneShot() { | 18 ExtensionLoadWaiterOneShot::~ExtensionLoadWaiterOneShot() { |
| 19 } | 19 } |
| 20 | 20 |
| 21 void ExtensionLoadWaiterOneShot::WaitForExtension(const char* extension_id, | 21 void ExtensionLoadWaiterOneShot::WaitForExtension(const char* extension_id, |
| 22 const base::Closure& load_cb) { | 22 const base::Closure& load_cb) { |
| 23 CHECK(!extension_id_) << | 23 CHECK(!extension_id_) << |
| 24 "ExtensionLoadWaiterOneShot should only be used once."; | 24 "ExtensionLoadWaiterOneShot should only be used once."; |
| 25 extension_id_ = extension_id; | 25 extension_id_ = extension_id; |
| 26 load_looper_ = new content::MessageLoopRunner(); | 26 load_looper_ = new content::MessageLoopRunner(); |
| 27 registrar_.Add(this, | 27 registrar_.Add(this, |
| 28 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | 28 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, |
| 29 content::NotificationService::AllSources()); | 29 content::NotificationService::AllSources()); |
| 30 load_cb.Run(); | 30 load_cb.Run(); |
| 31 load_looper_->Run(); | 31 load_looper_->Run(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void ExtensionLoadWaiterOneShot::Observe(int type, | 34 void ExtensionLoadWaiterOneShot::Observe(int type, |
| 35 const content::NotificationSource& source, | 35 const content::NotificationSource& source, |
| 36 const content::NotificationDetails& details) { | 36 const content::NotificationDetails& details) { |
| 37 switch (type) { | 37 switch (type) { |
| 38 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: { | 38 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD: { |
| 39 extensions::ExtensionHost* host = | 39 extensions::ExtensionHost* host = |
| 40 content::Details<extensions::ExtensionHost>(details).ptr(); | 40 content::Details<extensions::ExtensionHost>(details).ptr(); |
| 41 if (host->extension_id() == extension_id_) { | 41 if (host->extension_id() == extension_id_) { |
| 42 browser_context_ = host->browser_context(); | 42 browser_context_ = host->browser_context(); |
| 43 CHECK(browser_context_); | 43 CHECK(browser_context_); |
| 44 registrar_.Remove( | 44 registrar_.Remove( |
| 45 this, | 45 this, extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD, |
| 46 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, | |
| 47 content::NotificationService::AllSources()); | 46 content::NotificationService::AllSources()); |
| 48 load_looper_->Quit(); | 47 load_looper_->Quit(); |
| 49 } | 48 } |
| 50 break; | 49 break; |
| 51 } | 50 } |
| 52 } | 51 } |
| 53 } | 52 } |
| OLD | NEW |