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

Side by Side Diff: chrome/browser/extensions/image_loading_tracker.h

Issue 10375021: Move Extension into extensions namespace (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Take 6 Created 8 years, 7 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
OLDNEW
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/gtest_prod_util.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "chrome/common/extensions/extension_resource.h" 14 #include "chrome/common/extensions/extension_resource.h"
15 #include "content/public/browser/notification_observer.h" 15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h" 16 #include "content/public/browser/notification_registrar.h"
17 #include "ui/gfx/size.h" 17 #include "ui/gfx/size.h"
18 18
19 class SkBitmap;
20
21 namespace extensions {
19 class Extension; 22 class Extension;
20 class SkBitmap; 23 }
21 24
22 namespace gfx { 25 namespace gfx {
23 class Image; 26 class Image;
24 } 27 }
25 28
26 // The views need to load their icons asynchronously but might be deleted before 29 // The views need to load their icons asynchronously but might be deleted before
27 // the images have loaded. This class encapsulates a loader class that stays 30 // the images have loaded. This class encapsulates a loader class that stays
28 // alive while the request is in progress (manages its own lifetime) and keeps 31 // alive while the request is in progress (manages its own lifetime) and keeps
29 // track of whether the view still cares about the icon loading. 32 // track of whether the view still cares about the icon loading.
30 // 33 //
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 gfx::Size max_size; 73 gfx::Size max_size;
71 }; 74 };
72 75
73 explicit ImageLoadingTracker(Observer* observer); 76 explicit ImageLoadingTracker(Observer* observer);
74 virtual ~ImageLoadingTracker(); 77 virtual ~ImageLoadingTracker();
75 78
76 // Specify image resource to load. If the loaded image is larger than 79 // Specify image resource to load. If the loaded image is larger than
77 // |max_size| it will be resized to those dimensions. IMPORTANT NOTE: this 80 // |max_size| it will be resized to those dimensions. IMPORTANT NOTE: this
78 // function may call back your observer synchronously (ie before it returns) 81 // function may call back your observer synchronously (ie before it returns)
79 // if the image was found in the cache. 82 // if the image was found in the cache.
80 void LoadImage(const Extension* extension, 83 void LoadImage(const extensions::Extension* extension,
81 const ExtensionResource& resource, 84 const ExtensionResource& resource,
82 const gfx::Size& max_size, 85 const gfx::Size& max_size,
83 CacheParam cache); 86 CacheParam cache);
84 87
85 // Same as LoadImage() above except it loads multiple images from the same 88 // Same as LoadImage() above except it loads multiple images from the same
86 // extension. This is used to load multiple resolutions of the same image 89 // extension. This is used to load multiple resolutions of the same image
87 // type. 90 // type.
88 void LoadImages(const Extension* extension, 91 void LoadImages(const extensions::Extension* extension,
89 const std::vector<ImageInfo>& info_list, 92 const std::vector<ImageInfo>& info_list,
90 CacheParam cache); 93 CacheParam cache);
91 94
92 // Returns the ID used for the next image that is loaded. That is, the return 95 // Returns the ID used for the next image that is loaded. That is, the return
93 // value from this method corresponds to the int that is passed to 96 // value from this method corresponds to the int that is passed to
94 // OnImageLoaded() the next time LoadImage() is invoked. 97 // OnImageLoaded() the next time LoadImage() is invoked.
95 int next_id() const { return next_id_; } 98 int next_id() const { return next_id_; }
96 99
97 private: 100 private:
98 // Information for pending image load operation for one or more images. 101 // Information for pending image load operation for one or more images.
99 struct PendingLoadInfo { 102 struct PendingLoadInfo {
100 PendingLoadInfo(); 103 PendingLoadInfo();
101 ~PendingLoadInfo(); 104 ~PendingLoadInfo();
102 105
103 const Extension* extension; 106 const extensions::Extension* extension;
104 // This is cached separate from |extension| in case the extension in 107 // This is cached separate from |extension| in case the extension in
105 // unloaded. 108 // unloaded.
106 std::string extension_id; 109 std::string extension_id;
107 CacheParam cache; 110 CacheParam cache;
108 size_t pending_count; 111 size_t pending_count;
109 std::vector<SkBitmap> bitmaps; 112 std::vector<SkBitmap> bitmaps;
110 }; 113 };
111 114
112 // Maps an integer identifying a load request to a PendingLoadInfo. 115 // Maps an integer identifying a load request to a PendingLoadInfo.
113 typedef std::map<int, PendingLoadInfo> LoadMap; 116 typedef std::map<int, PendingLoadInfo> LoadMap;
114 117
115 class ImageLoader; 118 class ImageLoader;
116 119
117 // When an image has finished loaded and been resized on the file thread, it 120 // 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 121 // is posted back to this method on the original thread. This method then
119 // calls the observer's OnImageLoaded and deletes the ImageLoadingTracker if 122 // 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 123 // it was the last image in the list. The |original_size| should be the size
121 // of the image before any resizing was done. 124 // of the image before any resizing was done.
122 // |image| may be null if the file failed to decode. 125 // |image| may be null if the file failed to decode.
123 void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource, 126 void OnImageLoaded(SkBitmap* image, const ExtensionResource& resource,
124 const gfx::Size& original_size, int id, bool should_cache); 127 const gfx::Size& original_size, int id, bool should_cache);
125 128
126 // Checks whether image is a component extension resource. Returns false 129 // Checks whether image is a component extension resource. Returns false
127 // if a given |resource| does not have a corresponding image in bundled 130 // if a given |resource| does not have a corresponding image in bundled
128 // resources. Otherwise fills |resource_id|. 131 // resources. Otherwise fills |resource_id|.
129 bool IsComponentExtensionResource(const Extension* extension, 132 bool IsComponentExtensionResource(const extensions::Extension* extension,
130 const ExtensionResource& resource, 133 const ExtensionResource& resource,
131 int& resource_id) const; 134 int& resource_id) const;
132 135
133 // content::NotificationObserver method. If an extension is uninstalled while 136 // content::NotificationObserver method. If an extension is uninstalled while
134 // we're waiting for the image we remove the entry from load_map_. 137 // we're waiting for the image we remove the entry from load_map_.
135 virtual void Observe(int type, 138 virtual void Observe(int type,
136 const content::NotificationSource& source, 139 const content::NotificationSource& source,
137 const content::NotificationDetails& details) OVERRIDE; 140 const content::NotificationDetails& details) OVERRIDE;
138 141
139 // The view that is waiting for the image to load. 142 // The view that is waiting for the image to load.
(...skipping 11 matching lines...) Expand all
151 154
152 content::NotificationRegistrar registrar_; 155 content::NotificationRegistrar registrar_;
153 156
154 FRIEND_TEST_ALL_PREFIXES(ImageLoadingTrackerTest, 157 FRIEND_TEST_ALL_PREFIXES(ImageLoadingTrackerTest,
155 IsComponentExtensionResource); 158 IsComponentExtensionResource);
156 159
157 DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker); 160 DISALLOW_COPY_AND_ASSIGN(ImageLoadingTracker);
158 }; 161 };
159 162
160 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_ 163 #endif // CHROME_BROWSER_EXTENSIONS_IMAGE_LOADING_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698