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.
5 #include "chrome/test/base/extension_load_waiter_one_shot.h"
7 #include "base/callback.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/common/extensions/extension_constants.h"
10 #include "content/public/browser/browser_context.h"
11 #include "content/public/browser/notification_service.h"
12 #include "extensions/browser/extension_host.h"
14 ExtensionLoadWaiterOneShot::ExtensionLoadWaiterOneShot() : extension_id_(NULL
),
15 browser_context_(NULL
) {
18 ExtensionLoadWaiterOneShot::~ExtensionLoadWaiterOneShot() {
21 void ExtensionLoadWaiterOneShot::WaitForExtension(const char* extension_id
,
22 const base::Closure
& load_cb
) {
23 CHECK(!extension_id_
) <<
24 "ExtensionLoadWaiterOneShot should only be used once.";
25 extension_id_
= extension_id
;
26 load_looper_
= new content::MessageLoopRunner();
28 extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD
,
29 content::NotificationService::AllSources());
34 void ExtensionLoadWaiterOneShot::Observe(int type
,
35 const content::NotificationSource
& source
,
36 const content::NotificationDetails
& details
) {
38 case extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD
: {
39 extensions::ExtensionHost
* host
=
40 content::Details
<extensions::ExtensionHost
>(details
).ptr();
41 if (host
->extension_id() == extension_id_
) {
42 browser_context_
= host
->browser_context();
43 CHECK(browser_context_
);
45 this, extensions::NOTIFICATION_EXTENSION_HOST_DID_STOP_FIRST_LOAD
,
46 content::NotificationService::AllSources());