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

Unified Diff: ui/gfx/image/image.h

Issue 1771033003: gfx::Image: Added thread checker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove UpdateShortcutWorker changes; instead just disable thread checking. Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/web_applications/web_app_win.cc ('k') | ui/gfx/image/image.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image.h
diff --git a/ui/gfx/image/image.h b/ui/gfx/image/image.h
index 01344242d939a20cb9c6f7ca682104bee1d90d69..f5feeb22c6e8e824a096c3e9fcdb46849dafcf18 100644
--- a/ui/gfx/image/image.h
+++ b/ui/gfx/image/image.h
@@ -15,6 +15,18 @@
//
// Images can be empty, in which case they have no backing representation.
// Attempting to use an empty Image will result in a crash.
+//
+// Image is *not thread-safe* for reads or writes. In Debug builds, a thread
+// checker will check that Images are not being used across multiple threads. If
+// you need to pass an image from one thread to another, you have two options:
+// 1. Ensure that you are the sole reference holder of the Image (keeping in
+// mind that if the Image has been copied that the place you copied it from
+// will hold a reference to it), and call DetachFromThread() just before
+// passing the Image to another thread.
+// 2. Get the underlying image representation (e.g., ImageSkia) out of the
+// image, ensure that it is thread-safe (ImageSkia requires special attention
+// to make it thread-safe), pass that to another thread, then create a new
+// Image object on the other side.
#ifndef UI_GFX_IMAGE_IMAGE_H_
#define UI_GFX_IMAGE_IMAGE_H_
@@ -179,6 +191,18 @@ class GFX_EXPORT Image {
void SetSourceColorSpace(CGColorSpaceRef color_space);
#endif // defined(OS_MACOSX) && !defined(OS_IOS)
+ // Turns off thread checking on this Image (and all Images sharing its backing
+ // store). This should be used to mark code that is not currently thread-safe
+ // and any usage of this method should be considered a bug and accompanied by
+ // a TODO.
+ // TODO(mgiuca): Remove this method after all uses of Image are thread-safe.
+ void DisableThreadChecking();
+
+ // Informs the thread checker that this Image is about to be moved to another
+ // thread. Should only be used when this Image is the sole reference holder of
+ // its backing store.
+ void DetachFromThread();
+
private:
// Returns the type of the default representation.
RepresentationType DefaultRepresentationType() const;
« no previous file with comments | « chrome/browser/web_applications/web_app_win.cc ('k') | ui/gfx/image/image.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698