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

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

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 | « ui/gfx/image/image.h ('k') | ui/gfx/image/image_family.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/image/image.cc
diff --git a/ui/gfx/image/image.cc b/ui/gfx/image/image.cc
index b2984fb0f3d844254aa8ff409fa8cd3780f42d9c..4a0f26dfc7780e5c6434d48f31603a16129a89e3 100644
--- a/ui/gfx/image/image.cc
+++ b/ui/gfx/image/image.cc
@@ -11,6 +11,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
+#include "base/threading/thread_checker.h"
#include "build/build_config.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/geometry/size.h"
@@ -357,23 +358,46 @@ class ImageStorage : public base::RefCounted<ImageStorage> {
}
Image::RepresentationType default_representation_type() {
+ CheckCalledOnValidThread();
return default_representation_type_;
}
- Image::RepresentationMap& representations() { return representations_; }
+ Image::RepresentationMap& representations() {
+ CheckCalledOnValidThread();
+ return representations_;
+ }
#if defined(OS_MACOSX) && !defined(OS_IOS)
void set_default_representation_color_space(CGColorSpaceRef color_space) {
+ CheckCalledOnValidThread();
default_representation_color_space_ = color_space;
}
CGColorSpaceRef default_representation_color_space() {
+ CheckCalledOnValidThread();
return default_representation_color_space_;
}
#endif // defined(OS_MACOSX) && !defined(OS_IOS)
+ void DisableThreadChecking() {
+ thread_checking_disabled_ = true;
+ }
+
+ void DetachFromThread() {
+ thread_checker_.DetachFromThread();
+ }
+
+ // DCHECKs that the current thread matches the valid thread in
+ // |thread_checker_|.
+ void CheckCalledOnValidThread() const {
+ if (!thread_checking_disabled_)
+ DCHECK(thread_checker_.CalledOnValidThread());
+ }
+
private:
friend class base::RefCounted<ImageStorage>;
- ~ImageStorage() {}
+ ~ImageStorage() {
+ CheckCalledOnValidThread();
+ }
// The type of image that was passed to the constructor. This key will always
// exist in the |representations_| map.
@@ -391,6 +415,12 @@ class ImageStorage : public base::RefCounted<ImageStorage> {
// more for any converted representations.
Image::RepresentationMap representations_;
+ bool thread_checking_disabled_ = false;
+
+ // Used to verify that Images are not used from different threads at the same
+ // time, in Debug builds.
+ base::ThreadChecker thread_checker_;
+
DISALLOW_COPY_AND_ASSIGN(ImageStorage);
};
@@ -740,6 +770,14 @@ void Image::SetSourceColorSpace(CGColorSpaceRef color_space) {
}
#endif // defined(OS_MACOSX) && !defined(OS_IOS)
+void Image::DisableThreadChecking() {
+ storage_->DisableThreadChecking();
+}
+
+void Image::DetachFromThread() {
+ storage_->DetachFromThread();
+}
+
Image::RepresentationType Image::DefaultRepresentationType() const {
CHECK(storage_.get());
return storage_->default_representation_type();
« no previous file with comments | « ui/gfx/image/image.h ('k') | ui/gfx/image/image_family.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698