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

Side by Side Diff: chrome/common/extensions/extension_action.h

Issue 10823142: Fix a race condition when an IconAnimation is still running at browser shutdown. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits. Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/extension_action.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ 5 #ifndef CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_
6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ 6 #define CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id); 228 void PaintBadge(gfx::Canvas* canvas, const gfx::Rect& bounds, int tab_id);
229 229
230 // Gets a weak reference to the icon animation for a tab, if any. The 230 // Gets a weak reference to the icon animation for a tab, if any. The
231 // reference will only have a value while the animation is running. 231 // reference will only have a value while the animation is running.
232 base::WeakPtr<IconAnimation> GetIconAnimation(int tab_id) const; 232 base::WeakPtr<IconAnimation> GetIconAnimation(int tab_id) const;
233 233
234 // Runs an animation on a tab. 234 // Runs an animation on a tab.
235 void RunIconAnimation(int tab_id); 235 void RunIconAnimation(int tab_id);
236 236
237 private: 237 private:
238 class IconAnimationWrapper;
239
240 // Finds the icon animation wrapper for a tab, if any. If the animation for
241 // this tab has recently completed, also removes up any other dead wrappers
242 // from the map.
243 IconAnimationWrapper* GetIconAnimationWrapper(int tab_id) const;
244
238 // If the icon animation is running on tab |tab_id|, applies it to 245 // If the icon animation is running on tab |tab_id|, applies it to
239 // |orig| and returns the result. Otherwise, just returns |orig|. 246 // |orig| and returns the result. Otherwise, just returns |orig|.
240 gfx::Image ApplyIconAnimation(int tab_id, const gfx::Image& orig) const; 247 gfx::Image ApplyIconAnimation(int tab_id, const gfx::Image& orig) const;
241 248
242 template <class T> 249 template <class T>
243 struct ValueTraits { 250 struct ValueTraits {
244 static T CreateEmpty() { 251 static T CreateEmpty() {
245 return T(); 252 return T();
246 } 253 }
247 }; 254 };
(...skipping 24 matching lines...) Expand all
272 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key). 279 // kDefaultTabId), or tab-specific state (stored with the tab_id as the key).
273 std::map<int, GURL> popup_url_; 280 std::map<int, GURL> popup_url_;
274 std::map<int, std::string> title_; 281 std::map<int, std::string> title_;
275 std::map<int, gfx::Image> icon_; 282 std::map<int, gfx::Image> icon_;
276 std::map<int, int> icon_index_; // index into icon_paths_ 283 std::map<int, int> icon_index_; // index into icon_paths_
277 std::map<int, std::string> badge_text_; 284 std::map<int, std::string> badge_text_;
278 std::map<int, SkColor> badge_background_color_; 285 std::map<int, SkColor> badge_background_color_;
279 std::map<int, SkColor> badge_text_color_; 286 std::map<int, SkColor> badge_text_color_;
280 std::map<int, bool> visible_; 287 std::map<int, bool> visible_;
281 288
282 class IconAnimationWrapper; 289 // IconAnimationWrappers own themselves so that even if the Extension and
283 std::map<int, linked_ptr<IconAnimationWrapper> > icon_animation_; 290 // ExtensionAction are destroyed on a non-UI thread, the animation will still
291 // only be touched from the UI thread. When an animation finishes, it deletes
292 // itself, which causes the WeakPtr in this map to become NULL.
293 // GetIconAnimationWrapper() removes NULLs to prevent the map from growing
294 // without bound.
295 mutable std::map<int, base::WeakPtr<IconAnimationWrapper> > icon_animation_;
284 296
285 std::string default_icon_path_; 297 std::string default_icon_path_;
286 298
287 // The id for the ExtensionAction, for example: "RssPageAction". This is 299 // The id for the ExtensionAction, for example: "RssPageAction". This is
288 // needed for compat with an older version of the page actions API. 300 // needed for compat with an older version of the page actions API.
289 std::string id_; 301 std::string id_;
290 302
291 // A list of paths to icons this action might show. This is needed to support 303 // A list of paths to icons this action might show. This is needed to support
292 // the legacy setIcon({iconIndex:...} method of the page actions API. 304 // the legacy setIcon({iconIndex:...} method of the page actions API.
293 std::vector<std::string> icon_paths_; 305 std::vector<std::string> icon_paths_;
294 306
295 // Saves the arguments from CacheIcon() calls. 307 // Saves the arguments from CacheIcon() calls.
296 std::map<std::string, gfx::Image> path_to_icon_cache_; 308 std::map<std::string, gfx::Image> path_to_icon_cache_;
297 309
298 DISALLOW_COPY_AND_ASSIGN(ExtensionAction); 310 DISALLOW_COPY_AND_ASSIGN(ExtensionAction);
299 }; 311 };
300 312
301 template<> 313 template<>
302 struct ExtensionAction::ValueTraits<int> { 314 struct ExtensionAction::ValueTraits<int> {
303 static int CreateEmpty() { 315 static int CreateEmpty() {
304 return -1; 316 return -1;
305 } 317 }
306 }; 318 };
307 319
308 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_ 320 #endif // CHROME_COMMON_EXTENSIONS_EXTENSION_ACTION_H_
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension.cc ('k') | chrome/common/extensions/extension_action.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698