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

Side by Side Diff: trunk/src/mojo/service_manager/service_manager_unittest.cc

Issue 287003004: Revert 270867 "Mojo: Internalize ServiceConnector<>" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 #include "mojo/public/cpp/bindings/allocation_scope.h" 6 #include "mojo/public/cpp/bindings/allocation_scope.h"
7 #include "mojo/public/cpp/environment/environment.h" 7 #include "mojo/public/cpp/environment/environment.h"
8 #include "mojo/public/cpp/shell/application.h" 8 #include "mojo/public/cpp/shell/application.h"
9 #include "mojo/public/interfaces/shell/shell.mojom.h" 9 #include "mojo/public/interfaces/shell/shell.mojom.h"
10 #include "mojo/service_manager/service_loader.h" 10 #include "mojo/service_manager/service_loader.h"
11 #include "mojo/service_manager/service_manager.h" 11 #include "mojo/service_manager/service_manager.h"
12 #include "mojo/service_manager/test.mojom.h" 12 #include "mojo/service_manager/test.mojom.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 namespace { 16 namespace {
17 17
18 const char kTestURLString[] = "test:testService"; 18 const char kTestURLString[] = "test:testService";
19 19
20 struct TestContext { 20 struct TestContext {
21 TestContext() : num_impls(0), num_loader_deletes(0) {} 21 TestContext() : num_impls(0), num_loader_deletes(0) {}
22 std::string last_test_string; 22 std::string last_test_string;
23 int num_impls; 23 int num_impls;
24 int num_loader_deletes; 24 int num_loader_deletes;
25 }; 25 };
26 26
27 class TestServiceImpl : public InterfaceImpl<TestService> { 27 class TestServiceImpl :
28 public ServiceConnection<TestService, TestServiceImpl, TestContext> {
28 public: 29 public:
29 explicit TestServiceImpl(TestContext* context) : context_(context) { 30 virtual ~TestServiceImpl() {
30 ++context_->num_impls; 31 if (context())
32 --context()->num_impls;
31 } 33 }
32 34
33 virtual ~TestServiceImpl() { 35 void Initialize() {
34 --context_->num_impls; 36 if (context())
35 } 37 ++context()->num_impls;
36
37 // InterfaceImpl<TestService> implementation.
38 virtual void OnConnectionError() OVERRIDE {
39 } 38 }
40 39
41 // TestService implementation: 40 // TestService implementation:
42 virtual void Test(const mojo::String& test_string) OVERRIDE { 41 virtual void Test(const mojo::String& test_string) OVERRIDE {
43 context_->last_test_string = test_string.To<std::string>(); 42 context()->last_test_string = test_string.To<std::string>();
44 client()->AckTest(); 43 client()->AckTest();
45 } 44 }
46
47 private:
48 TestContext* context_;
49 }; 45 };
50 46
51 class TestClientImpl : public TestClient { 47 class TestClientImpl : public TestClient {
52 public: 48 public:
53 explicit TestClientImpl(TestServicePtr service) 49 explicit TestClientImpl(TestServicePtr service)
54 : service_(service.Pass()), 50 : service_(service.Pass()),
55 quit_after_ack_(false) { 51 quit_after_ack_(false) {
56 service_->SetClient(this); 52 service_->SetClient(this);
57 } 53 }
58 54
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 91 }
96 92
97 int num_loads() const { return num_loads_; } 93 int num_loads() const { return num_loads_; }
98 94
99 private: 95 private:
100 virtual void LoadService(ServiceManager* manager, 96 virtual void LoadService(ServiceManager* manager,
101 const GURL& url, 97 const GURL& url,
102 ScopedMessagePipeHandle shell_handle) OVERRIDE { 98 ScopedMessagePipeHandle shell_handle) OVERRIDE {
103 ++num_loads_; 99 ++num_loads_;
104 test_app_.reset(new Application(shell_handle.Pass())); 100 test_app_.reset(new Application(shell_handle.Pass()));
105 test_app_->AddService<TestServiceImpl>(context_); 101 test_app_->AddServiceConnector(
102 new ServiceConnector<TestServiceImpl, TestContext>(context_));
106 } 103 }
107 104
108 virtual void OnServiceError(ServiceManager* manager, 105 virtual void OnServiceError(ServiceManager* manager,
109 const GURL& url) OVERRIDE { 106 const GURL& url) OVERRIDE {
110 if (quit_after_error_) { 107 if (quit_after_error_) {
111 base::MessageLoop::current()->PostTask(FROM_HERE, 108 base::MessageLoop::current()->PostTask(FROM_HERE,
112 base::MessageLoop::QuitClosure()); 109 base::MessageLoop::QuitClosure());
113 } 110 }
114 } 111 }
115 112
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 271
275 std::string url("test:test3"); 272 std::string url("test:test3");
276 MessagePipe pipe1; 273 MessagePipe pipe1;
277 sm.Connect(GURL(url), pipe1.handle0.Pass()); 274 sm.Connect(GURL(url), pipe1.handle0.Pass());
278 EXPECT_EQ(1, interceptor.call_count()); 275 EXPECT_EQ(1, interceptor.call_count());
279 EXPECT_EQ(url, interceptor.url_spec()); 276 EXPECT_EQ(url, interceptor.url_spec());
280 EXPECT_EQ(1, default_loader->num_loads()); 277 EXPECT_EQ(1, default_loader->num_loads());
281 } 278 }
282 279
283 } // namespace mojo 280 } // namespace mojo
OLDNEW
« no previous file with comments | « trunk/src/mojo/public/cpp/shell/service.h ('k') | trunk/src/mojo/services/dbus_echo/dbus_echo_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698