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

Side by Side Diff: mojo/shell/application_manager_unittest.cc

Issue 1402533003: Don't use base::MessageLoop::{Quit,QuitClosure} in mojo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "base/at_exit.h" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 public: 47 public:
48 TestServiceImpl(TestContext* context, InterfaceRequest<TestService> request) 48 TestServiceImpl(TestContext* context, InterfaceRequest<TestService> request)
49 : context_(context), binding_(this, request.Pass()) { 49 : context_(context), binding_(this, request.Pass()) {
50 ++context_->num_impls; 50 ++context_->num_impls;
51 } 51 }
52 52
53 ~TestServiceImpl() override { 53 ~TestServiceImpl() override {
54 --context_->num_impls; 54 --context_->num_impls;
55 if (!base::MessageLoop::current()->is_running()) 55 if (!base::MessageLoop::current()->is_running())
56 return; 56 return;
57 base::MessageLoop::current()->Quit(); 57 base::MessageLoop::current()->QuitWhenIdle();
58 } 58 }
59 59
60 // TestService implementation: 60 // TestService implementation:
61 void Test(const String& test_string, 61 void Test(const String& test_string,
62 const Callback<void()>& callback) override { 62 const Callback<void()>& callback) override {
63 context_->last_test_string = test_string; 63 context_->last_test_string = test_string;
64 callback.Run(); 64 callback.Run();
65 } 65 }
66 66
67 private: 67 private:
68 TestContext* context_; 68 TestContext* context_;
69 StrongBinding<TestService> binding_; 69 StrongBinding<TestService> binding_;
70 }; 70 };
71 71
72 class TestClient { 72 class TestClient {
73 public: 73 public:
74 explicit TestClient(TestServicePtr service) 74 explicit TestClient(TestServicePtr service)
75 : service_(service.Pass()), quit_after_ack_(false) {} 75 : service_(service.Pass()), quit_after_ack_(false) {}
76 76
77 void AckTest() { 77 void AckTest() {
78 if (quit_after_ack_) 78 if (quit_after_ack_)
79 base::MessageLoop::current()->Quit(); 79 base::MessageLoop::current()->QuitWhenIdle();
80 } 80 }
81 81
82 void Test(const std::string& test_string) { 82 void Test(const std::string& test_string) {
83 quit_after_ack_ = true; 83 quit_after_ack_ = true;
84 service_->Test(test_string, 84 service_->Test(test_string,
85 base::Bind(&TestClient::AckTest, base::Unretained(this))); 85 base::Bind(&TestClient::AckTest, base::Unretained(this)));
86 } 86 }
87 87
88 private: 88 private:
89 TestServicePtr service_; 89 TestServicePtr service_;
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 private: 261 private:
262 void CallB() override { 262 void CallB() override {
263 b_->B(base::Bind(&TestAImpl::Quit, base::Unretained(this))); 263 b_->B(base::Bind(&TestAImpl::Quit, base::Unretained(this)));
264 } 264 }
265 265
266 void CallCFromB() override { 266 void CallCFromB() override {
267 b_->CallC(base::Bind(&TestAImpl::Quit, base::Unretained(this))); 267 b_->CallC(base::Bind(&TestAImpl::Quit, base::Unretained(this)));
268 } 268 }
269 269
270 void Quit() { 270 void Quit() {
271 base::MessageLoop::current()->Quit(); 271 base::MessageLoop::current()->QuitWhenIdle();
272 test_context_->set_a_called_quit(); 272 test_context_->set_a_called_quit();
273 test_context_->QuitSoon(); 273 test_context_->QuitSoon();
274 } 274 }
275 275
276 scoped_ptr<ApplicationConnection> connection_; 276 scoped_ptr<ApplicationConnection> connection_;
277 TesterContext* test_context_; 277 TesterContext* test_context_;
278 TestBPtr b_; 278 TestBPtr b_;
279 StrongBinding<TestA> binding_; 279 StrongBinding<TestA> binding_;
280 }; 280 };
281 281
282 class TestBImpl : public TestB { 282 class TestBImpl : public TestB {
283 public: 283 public:
284 TestBImpl(ApplicationConnection* connection, 284 TestBImpl(ApplicationConnection* connection,
285 TesterContext* test_context, 285 TesterContext* test_context,
286 InterfaceRequest<TestB> request) 286 InterfaceRequest<TestB> request)
287 : test_context_(test_context), binding_(this, request.Pass()) { 287 : test_context_(test_context), binding_(this, request.Pass()) {
288 connection->ConnectToService(&c_); 288 connection->ConnectToService(&c_);
289 } 289 }
290 290
291 ~TestBImpl() override { 291 ~TestBImpl() override {
292 test_context_->IncrementNumBDeletes(); 292 test_context_->IncrementNumBDeletes();
293 if (base::MessageLoop::current()->is_running()) 293 if (base::MessageLoop::current()->is_running())
294 base::MessageLoop::current()->Quit(); 294 base::MessageLoop::current()->QuitWhenIdle();
295 test_context_->QuitSoon(); 295 test_context_->QuitSoon();
296 } 296 }
297 297
298 private: 298 private:
299 void B(const Callback<void()>& callback) override { 299 void B(const Callback<void()>& callback) override {
300 test_context_->IncrementNumBCalls(); 300 test_context_->IncrementNumBCalls();
301 callback.Run(); 301 callback.Run();
302 } 302 }
303 303
304 void CallC(const Callback<void()>& callback) override { 304 void CallC(const Callback<void()>& callback) override {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 void Load(const GURL& url, 344 void Load(const GURL& url,
345 InterfaceRequest<Application> application_request) override { 345 InterfaceRequest<Application> application_request) override {
346 app_.reset(new ApplicationImpl(this, application_request.Pass())); 346 app_.reset(new ApplicationImpl(this, application_request.Pass()));
347 } 347 }
348 348
349 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { 349 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
350 if (!requestor_url_.empty() && 350 if (!requestor_url_.empty() &&
351 requestor_url_ != connection->GetRemoteApplicationURL()) { 351 requestor_url_ != connection->GetRemoteApplicationURL()) {
352 context_->set_tester_called_quit(); 352 context_->set_tester_called_quit();
353 context_->QuitSoon(); 353 context_->QuitSoon();
354 base::MessageLoop::current()->Quit(); 354 base::MessageLoop::current()->QuitWhenIdle();
355 return false; 355 return false;
356 } 356 }
357 // If we're coming from A, then add B, otherwise A. 357 // If we're coming from A, then add B, otherwise A.
358 if (connection->GetRemoteApplicationURL() == kTestAURLString) 358 if (connection->GetRemoteApplicationURL() == kTestAURLString)
359 connection->AddService<TestB>(this); 359 connection->AddService<TestB>(this);
360 else 360 else
361 connection->AddService<TestA>(this); 361 connection->AddService<TestA>(this);
362 return true; 362 return true;
363 } 363 }
364 364
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 624
625 // A different identity because the domain is different. 625 // A different identity because the domain is different.
626 ConnectToService(application_manager_.get(), 626 ConnectToService(application_manager_.get(),
627 GURL("http://www.another_domain.org/abc"), &test_service); 627 GURL("http://www.another_domain.org/abc"), &test_service);
628 EXPECT_EQ(4, test_loader_->num_loads()); 628 EXPECT_EQ(4, test_loader_->num_loads());
629 } 629 }
630 630
631 } // namespace test 631 } // namespace test
632 } // namespace shell 632 } // namespace shell
633 } // namespace mojo 633 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/test_service/test_service_application.cc ('k') | mojo/shell/capability_filter_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698