1 // Copyright 2015 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 "extensions/browser/test_image_loader.h"
8 #include "extensions/browser/image_loader.h"
9 #include "extensions/common/extension.h"
11 namespace extensions
{
13 TestImageLoader::TestImageLoader() : waiting_(false), image_loaded_(false) {}
15 TestImageLoader::~TestImageLoader() {}
18 SkBitmap
TestImageLoader::LoadAndGetExtensionBitmap(
19 const Extension
* extension
,
20 const std::string
& image_path
,
22 TestImageLoader image_loader
;
23 return image_loader
.LoadAndGetBitmap(extension
, image_path
, size
);
26 void TestImageLoader::OnImageLoaded(const gfx::Image
& image
) {
30 loader_message_loop_quit_
.Run();
33 SkBitmap
TestImageLoader::LoadAndGetBitmap(const Extension
* extension
,
34 const std::string
& path
,
36 image_loaded_
= false;
38 ImageLoader image_loader
;
39 image_loader
.LoadImageAsync(
40 extension
, extension
->GetResource(path
), gfx::Size(size
, size
),
41 base::Bind(&TestImageLoader::OnImageLoaded
, base::Unretained(this)));
43 // If |image_| still hasn't been loaded (i.e. it is being loaded
44 // asynchronously), wait for it.
47 base::RunLoop run_loop
;
48 loader_message_loop_quit_
= run_loop
.QuitClosure();
53 DCHECK(image_loaded_
);
55 return image_
.IsEmpty() ? SkBitmap() : *image_
.ToSkBitmap();
58 } // namespace extensions