Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Side by Side Diff: extensions/browser/test_image_loader.cc

Issue 1302423005: Task manager's apps and extensions should show the correct favicon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleaning up the browser test Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/test_image_loader.h ('k') | extensions/extensions.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "extensions/browser/test_image_loader.h"
6
7 #include "base/bind.h"
8 #include "extensions/browser/image_loader.h"
9 #include "extensions/common/extension.h"
10
11 namespace extensions {
12
13 TestImageLoader::TestImageLoader() : waiting_(false), image_loaded_(false) {}
14
15 TestImageLoader::~TestImageLoader() {}
16
17 // static
18 SkBitmap TestImageLoader::LoadAndGetExtensionBitmap(
19 const Extension* extension,
20 const std::string& image_path,
21 int size) {
22 TestImageLoader image_loader;
23 return image_loader.LoadAndGetBitmap(extension, image_path, size);
24 }
25
26 void TestImageLoader::OnImageLoaded(const gfx::Image& image) {
27 image_ = image;
28 image_loaded_ = true;
29 if (waiting_)
30 loader_message_loop_quit_.Run();
31 }
32
33 SkBitmap TestImageLoader::LoadAndGetBitmap(const Extension* extension,
34 const std::string& path,
35 int size) {
36 image_loaded_ = false;
37
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)));
42
43 // If |image_| still hasn't been loaded (i.e. it is being loaded
44 // asynchronously), wait for it.
45 if (!image_loaded_) {
46 waiting_ = true;
47 base::RunLoop run_loop;
48 loader_message_loop_quit_ = run_loop.QuitClosure();
49 run_loop.Run();
50 waiting_ = false;
51 }
52
53 DCHECK(image_loaded_);
54
55 return image_.IsEmpty() ? SkBitmap() : *image_.ToSkBitmap();
56 }
57
58 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/test_image_loader.h ('k') | extensions/extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698