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