Chromium Code Reviews| Index: cc/test/test_context_support.cc |
| diff --git a/cc/test/test_context_support.cc b/cc/test/test_context_support.cc |
| index 7a47780e4d56369ffc6519477a2c33ff643616f3..126bcfbacd92682cf808f3e21a031126328998f6 100644 |
| --- a/cc/test/test_context_support.cc |
| +++ b/cc/test/test_context_support.cc |
| @@ -9,13 +9,35 @@ |
| #include "base/bind.h" |
| #include "base/location.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| namespace cc { |
| +namespace { |
| + |
| +class ScopedVisibilityImpl : public gpu::ContextSupport::ScopedVisibility { |
| + public: |
| + explicit ScopedVisibilityImpl(gpu::ContextSupport* context_support) |
| + : initial_context_support_(context_support) {} |
| + ~ScopedVisibilityImpl() { DCHECK(!initial_context_support_); } |
| + |
| + void Release(gpu::ContextSupport* context_support) { |
| + DCHECK_EQ(initial_context_support_, context_support); |
| + initial_context_support_ = nullptr; |
| + } |
| + |
| + private: |
| + // |initial_context_support_| is just stored/used for sanity-checking Release. |
|
danakj
2016/08/19 18:29:55
Comment not quite true now
ericrk
2016/08/19 18:49:57
Done.
|
| + const gpu::ContextSupport* initial_context_support_; |
| +}; |
| + |
| +} // namespace |
| TestContextSupport::TestContextSupport() |
| - : out_of_order_callbacks_(false), weak_ptr_factory_(this) {} |
| + : out_of_order_callbacks_(false), |
| + visible_clients_(0), |
|
danakj
2016/08/19 18:29:55
can you do this in the header? (mayeb move out_of_
ericrk
2016/08/19 18:49:57
Done.
|
| + weak_ptr_factory_(this) {} |
| TestContextSupport::~TestContextSupport() {} |
| @@ -91,18 +113,21 @@ uint64_t TestContextSupport::ShareGroupTracingGUID() const { |
| void TestContextSupport::SetErrorMessageCallback( |
| const base::Callback<void(const char*, int32_t)>& callback) {} |
| -void TestContextSupport::SetClientVisible(int client_id, bool is_visible) { |
| - if (is_visible) { |
| - visible_clients_.insert(client_id); |
| - } else { |
| - auto found = visible_clients_.find(client_id); |
| - if (found != visible_clients_.end()) |
| - visible_clients_.erase(found); |
| - } |
| +std::unique_ptr<gpu::ContextSupport::ScopedVisibility> |
| +TestContextSupport::ClientBecameVisible() { |
| + ++visible_clients_; |
| + return base::MakeUnique<ScopedVisibilityImpl>(this); |
| +} |
| + |
| +void TestContextSupport::ClientBecameNotVisible( |
| + std::unique_ptr<ScopedVisibility> visibility) { |
| + DCHECK_GT(visible_clients_, 0u); |
| + --visible_clients_; |
| + static_cast<ScopedVisibilityImpl*>(visibility.get())->Release(this); |
| } |
| bool TestContextSupport::AnyClientsVisible() const { |
| - return !visible_clients_.empty(); |
| + return visible_clients_ > 0; |
| } |
| } // namespace cc |