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

Side by Side Diff: mojo/edk/system/core_test_base.cc

Issue 1412283002: Convert mojo::system::Dispatcher to use our new refcounting stuff (instead of base's). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: no change Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « mojo/edk/system/core.cc ('k') | mojo/edk/system/data_pipe_consumer_dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "mojo/edk/system/core_test_base.h" 5 #include "mojo/edk/system/core_test_base.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h"
11 #include "mojo/edk/system/configuration.h" 10 #include "mojo/edk/system/configuration.h"
12 #include "mojo/edk/system/core.h" 11 #include "mojo/edk/system/core.h"
13 #include "mojo/edk/system/dispatcher.h" 12 #include "mojo/edk/system/dispatcher.h"
14 #include "mojo/edk/system/memory.h" 13 #include "mojo/edk/system/memory.h"
14 #include "mojo/edk/system/ref_ptr.h"
15 #include "mojo/public/cpp/system/macros.h" 15 #include "mojo/public/cpp/system/macros.h"
16 16
17 namespace mojo { 17 namespace mojo {
18 namespace system { 18 namespace system {
19 namespace test { 19 namespace test {
20 20
21 namespace { 21 namespace {
22 22
23 // MockDispatcher -------------------------------------------------------------- 23 // MockDispatcher --------------------------------------------------------------
24 24
25 class MockDispatcher : public Dispatcher { 25 class MockDispatcher : public Dispatcher {
26 public: 26 public:
27 static scoped_refptr<MockDispatcher> Create( 27 static RefPtr<MockDispatcher> Create(CoreTestBase::MockHandleInfo* info) {
28 CoreTestBase::MockHandleInfo* info) { 28 return AdoptRef(new MockDispatcher(info));
29 return make_scoped_refptr(new MockDispatcher(info));
30 } 29 }
31 30
32 // |Dispatcher| private methods: 31 // |Dispatcher| private methods:
33 Type GetType() const override { return Type::UNKNOWN; } 32 Type GetType() const override { return Type::UNKNOWN; }
34 33
35 private: 34 private:
36 explicit MockDispatcher(CoreTestBase::MockHandleInfo* info) : info_(info) { 35 explicit MockDispatcher(CoreTestBase::MockHandleInfo* info) : info_(info) {
37 CHECK(info_); 36 CHECK(info_);
38 info_->IncrementCtorCallCount(); 37 info_->IncrementCtorCallCount();
39 } 38 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 mutex().AssertHeld(); 148 mutex().AssertHeld();
150 if (signals_state) 149 if (signals_state)
151 *signals_state = HandleSignalsState(); 150 *signals_state = HandleSignalsState();
152 } 151 }
153 152
154 void CancelAllAwakablesNoLock() override { 153 void CancelAllAwakablesNoLock() override {
155 info_->IncrementCancelAllAwakablesCallCount(); 154 info_->IncrementCancelAllAwakablesCallCount();
156 mutex().AssertHeld(); 155 mutex().AssertHeld();
157 } 156 }
158 157
159 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() 158 RefPtr<Dispatcher> CreateEquivalentDispatcherAndCloseImplNoLock() override {
160 override {
161 return Create(info_); 159 return Create(info_);
162 } 160 }
163 161
164 CoreTestBase::MockHandleInfo* const info_; 162 CoreTestBase::MockHandleInfo* const info_;
165 163
166 MOJO_DISALLOW_COPY_AND_ASSIGN(MockDispatcher); 164 MOJO_DISALLOW_COPY_AND_ASSIGN(MockDispatcher);
167 }; 165 };
168 166
169 } // namespace 167 } // namespace
170 168
171 // CoreTestBase ---------------------------------------------------------------- 169 // CoreTestBase ----------------------------------------------------------------
172 170
173 CoreTestBase::CoreTestBase() { 171 CoreTestBase::CoreTestBase() {
174 } 172 }
175 173
176 CoreTestBase::~CoreTestBase() { 174 CoreTestBase::~CoreTestBase() {
177 } 175 }
178 176
179 void CoreTestBase::SetUp() { 177 void CoreTestBase::SetUp() {
180 core_ = new Core(&platform_support_); 178 core_ = new Core(&platform_support_);
181 } 179 }
182 180
183 void CoreTestBase::TearDown() { 181 void CoreTestBase::TearDown() {
184 delete core_; 182 delete core_;
185 core_ = nullptr; 183 core_ = nullptr;
186 } 184 }
187 185
188 MojoHandle CoreTestBase::CreateMockHandle(CoreTestBase::MockHandleInfo* info) { 186 MojoHandle CoreTestBase::CreateMockHandle(CoreTestBase::MockHandleInfo* info) {
189 CHECK(core_); 187 CHECK(core_);
190 scoped_refptr<MockDispatcher> dispatcher = MockDispatcher::Create(info); 188 auto dispatcher = MockDispatcher::Create(info);
191 return core_->AddDispatcher(dispatcher); 189 MojoHandle rv = core_->AddDispatcher(dispatcher.get());
190 CHECK_NE(rv, MOJO_HANDLE_INVALID);
191 return rv;
192 } 192 }
193 193
194 // CoreTestBase_MockHandleInfo ------------------------------------------------- 194 // CoreTestBase_MockHandleInfo -------------------------------------------------
195 195
196 CoreTestBase_MockHandleInfo::CoreTestBase_MockHandleInfo() 196 CoreTestBase_MockHandleInfo::CoreTestBase_MockHandleInfo()
197 : ctor_call_count_(0), 197 : ctor_call_count_(0),
198 dtor_call_count_(0), 198 dtor_call_count_(0),
199 close_call_count_(0), 199 close_call_count_(0),
200 write_message_call_count_(0), 200 write_message_call_count_(0),
201 read_message_call_count_(0), 201 read_message_call_count_(0),
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 375 }
376 376
377 void CoreTestBase_MockHandleInfo::AwakableWasAdded(Awakable* awakable) { 377 void CoreTestBase_MockHandleInfo::AwakableWasAdded(Awakable* awakable) {
378 MutexLocker locker(&mutex_); 378 MutexLocker locker(&mutex_);
379 added_awakables_.push_back(awakable); 379 added_awakables_.push_back(awakable);
380 } 380 }
381 381
382 } // namespace test 382 } // namespace test
383 } // namespace system 383 } // namespace system
384 } // namespace mojo 384 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/core.cc ('k') | mojo/edk/system/data_pipe_consumer_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698