OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/gtest_prod_util.h" | |
13 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
14 #include "chrome/common/extensions/extension_resource.h" | 13 #include "chrome/common/extensions/extension_resource.h" |
15 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
17 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
18 | 17 |
19 class Extension; | 18 class Extension; |
20 class SkBitmap; | 19 class SkBitmap; |
21 | 20 |
22 namespace gfx { | 21 namespace gfx { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 115 |
117 // When an image has finished loaded and been resized on the file thread, it | 116 // When an image has finished loaded and been resized on the file thread, it |
118 // is posted back to this method on the original thread. This method then | 117 // is posted back to this method on the original thread. This method then |
119 // calls the observer's OnImageLoaded and deletes the ImageLoadingTracker if | 118 // calls the observer's OnImageLoaded and deletes the ImageLoadingTracker if |
120 // it was the last image in the list. The |original_size| should be the size | 119 // it was the last image in the list. The |original_size| should be the size |
121 // of the image before any resizing was done. | 120 // of the image before any resizing was done. |
122 // |image| may be null if the file failed to decode. | 121 // |image| may be null if the file failed to decode. |
123 void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource, | 122 void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource, |
124 const gfx::Size& original_size, int id, bool should_cache); | 123 const gfx::Size& original_size, int id, bool should_cache); |
125 | 124 |
126 // Checks whether image is a component extension resource. Returns false | |
127 // if a given |resource| does not have a corresponding image in bundled | |
128 // resources. Otherwise fills |resource_id|. | |
129 bool IsComponentExtensionResource(const Extension* extension, | |
130 const ExtensionResource& resource, | |
131 int& resource_id) const; | |
132 | |
133 // content::NotificationObserver method. If an extension is uninstalled while | 125 // content::NotificationObserver method. If an extension is uninstalled while |
134 // we're waiting for the image we remove the entry from load_map_. | 126 // we're waiting for the image we remove the entry from load_map_. |
135 virtual void Observe(int type, | 127 virtual void Observe(int type, |
136 const content::NotificationSource& source, | 128 const content::NotificationSource& source, |
137 const content::NotificationDetails& details) OVERRIDE; | 129 const content::NotificationDetails& details) OVERRIDE; |
138 | 130 |
139 // The view that is waiting for the image to load. | 131 // The view that is waiting for the image to load. |
140 Observer* observer_; | 132 Observer* observer_; |
141 | 133 |
142 // ID to use for next image requested. This is an ever increasing integer. | 134 // ID to use for next image requested. This is an ever increasing integer. |
143 int next_id_; | 135 int next_id_; |
144 | 136 |
145 // The object responsible for loading the image on the File thread. | 137 // The object responsible for loading the image on the File thread. |
146 scoped_refptr<ImageLoader> loader_; | 138 scoped_refptr<ImageLoader> loader_; |
147 | 139 |
148 // Information for each LoadImage request is cached here. The integer | 140 // Information for each LoadImage request is cached here. The integer |
149 // identifies the id assigned to the request. | 141 // identifies the id assigned to the request. |
150 LoadMap load_map_; | 142 LoadMap load_map_; |
151 | 143 |
152 content::NotificationRegistrar registrar_; | 144 content::NotificationRegistrar registrar_; |
153 | 145 |
154 FRIEND_TEST_ALL_PREFIXES(ImageLoadingTrackerTest, | |
155 IsComponentExtensionResource); | |
156 | |
157 DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker); | 146 DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker); |
158 }; | 147 }; |
159 | 148 |
160 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ | 149 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ |
OLD | NEW |