| 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();
|
|
|