OLD | NEW |
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 #include <stdint.h> | 5 #include <stdint.h> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 const int32_t kInitializedResultValue = 1; | 97 const int32_t kInitializedResultValue = 1; |
98 const int32_t kOverrideResultValue = 2; | 98 const int32_t kOverrideResultValue = 2; |
99 | 99 |
100 struct CallbackRunInfo { | 100 struct CallbackRunInfo { |
101 explicit CallbackRunInfo(base::ThreadChecker* thread_checker) | 101 explicit CallbackRunInfo(base::ThreadChecker* thread_checker) |
102 : run_count_(0), | 102 : run_count_(0), |
103 result_(kInitializedResultValue), | 103 result_(kInitializedResultValue), |
104 completion_task_run_count_(0), | 104 completion_task_run_count_(0), |
105 completion_task_result_(kInitializedResultValue), | 105 completion_task_result_(kInitializedResultValue), |
106 thread_checker_(thread_checker), | 106 thread_checker_(thread_checker), |
107 callback_did_run_event_(true, false) {} | 107 callback_did_run_event_( |
| 108 base::WaitableEvent::ResetPolicy::MANUAL, |
| 109 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
108 void CallbackDidRun(int32_t result) { | 110 void CallbackDidRun(int32_t result) { |
109 CHECK(thread_checker_->CalledOnValidThread()); | 111 CHECK(thread_checker_->CalledOnValidThread()); |
110 if (!run_count_) | 112 if (!run_count_) |
111 result_ = result; | 113 result_ = result; |
112 ++run_count_; | 114 ++run_count_; |
113 callback_did_run_event_.Signal(); | 115 callback_did_run_event_.Signal(); |
114 } | 116 } |
115 void CompletionTaskDidRun(int32_t result) { | 117 void CompletionTaskDidRun(int32_t result) { |
116 CHECK(thread_checker_->CalledOnValidThread()); | 118 CHECK(thread_checker_->CalledOnValidThread()); |
117 if (!completion_task_run_count_) | 119 if (!completion_task_run_count_) |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 callback_didnt_run_ = nullptr; | 333 callback_didnt_run_ = nullptr; |
332 } | 334 } |
333 | 335 |
334 private: | 336 private: |
335 explicit CallbackMockResource(PP_Instance instance) | 337 explicit CallbackMockResource(PP_Instance instance) |
336 : Resource(OBJECT_IS_PROXY, instance), | 338 : Resource(OBJECT_IS_PROXY, instance), |
337 info_did_run_(&thread_checker_), | 339 info_did_run_(&thread_checker_), |
338 info_did_run_with_completion_task_(&thread_checker_), | 340 info_did_run_with_completion_task_(&thread_checker_), |
339 info_did_abort_(&thread_checker_), | 341 info_did_abort_(&thread_checker_), |
340 info_didnt_run_(&thread_checker_), | 342 info_didnt_run_(&thread_checker_), |
341 callbacks_created_event_(true, false) {} | 343 callbacks_created_event_( |
| 344 base::WaitableEvent::ResetPolicy::MANUAL, |
| 345 base::WaitableEvent::InitialState::NOT_SIGNALED) {} |
342 void CreateCallbacks() { | 346 void CreateCallbacks() { |
343 // Bind thread_checker_ to the thread where we create the callbacks. | 347 // Bind thread_checker_ to the thread where we create the callbacks. |
344 // Later, when the callback runs, it will check that it was invoked on this | 348 // Later, when the callback runs, it will check that it was invoked on this |
345 // same thread. | 349 // same thread. |
346 CHECK(thread_checker_.CalledOnValidThread()); | 350 CHECK(thread_checker_.CalledOnValidThread()); |
347 | 351 |
348 callback_did_run_ = new TrackedCallback( | 352 callback_did_run_ = new TrackedCallback( |
349 this, PP_MakeCompletionCallback(&TestCallback, &info_did_run_)); | 353 this, PP_MakeCompletionCallback(&TestCallback, &info_did_run_)); |
350 | 354 |
351 // In order to test that the completion task can override the callback | 355 // In order to test that the completion task can override the callback |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 resource->ReleaseRef(); | 469 resource->ReleaseRef(); |
466 resource->CheckFinalState(); | 470 resource->CheckFinalState(); |
467 { | 471 { |
468 ProxyAutoLock lock; | 472 ProxyAutoLock lock; |
469 resource = nullptr; | 473 resource = nullptr; |
470 } | 474 } |
471 } | 475 } |
472 | 476 |
473 } // namespace proxy | 477 } // namespace proxy |
474 } // namespace ppapi | 478 } // namespace ppapi |
OLD | NEW |