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

Side by Side Diff: mojo/public/cpp/bindings/tests/handle_passing_unittest.cc

Issue 2326913003: Privatize StrongBinding lifetime management (Closed)
Patch Set: rebase Created 4 years, 3 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 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 <stdint.h> 5 #include <stdint.h>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "mojo/public/cpp/bindings/binding.h" 10 #include "mojo/public/cpp/bindings/binding.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 private: 50 private:
51 static int do_something_count_; 51 static int do_something_count_;
52 Binding<ImportedInterface> binding_; 52 Binding<ImportedInterface> binding_;
53 base::Closure closure_; 53 base::Closure closure_;
54 }; 54 };
55 int ImportedInterfaceImpl::do_something_count_ = 0; 55 int ImportedInterfaceImpl::do_something_count_ = 0;
56 56
57 class SampleNamedObjectImpl : public sample::NamedObject { 57 class SampleNamedObjectImpl : public sample::NamedObject {
58 public: 58 public:
59 explicit SampleNamedObjectImpl(InterfaceRequest<sample::NamedObject> request) 59 SampleNamedObjectImpl() {}
60 : binding_(this, std::move(request)) {} 60
61 void SetName(const std::string& name) override { name_ = name; } 61 void SetName(const std::string& name) override { name_ = name; }
62 62
63 void GetName(const GetNameCallback& callback) override { 63 void GetName(const GetNameCallback& callback) override {
64 callback.Run(name_); 64 callback.Run(name_);
65 } 65 }
66 66
67 private: 67 private:
68 std::string name_; 68 std::string name_;
69 StrongBinding<sample::NamedObject> binding_;
70 }; 69 };
71 70
72 class SampleFactoryImpl : public sample::Factory { 71 class SampleFactoryImpl : public sample::Factory {
73 public: 72 public:
74 explicit SampleFactoryImpl(InterfaceRequest<sample::Factory> request) 73 explicit SampleFactoryImpl(InterfaceRequest<sample::Factory> request)
75 : binding_(this, std::move(request)) {} 74 : binding_(this, std::move(request)) {}
76 75
77 void DoStuff(sample::RequestPtr request, 76 void DoStuff(sample::RequestPtr request,
78 ScopedMessagePipeHandle pipe, 77 ScopedMessagePipeHandle pipe,
79 const DoStuffCallback& callback) override { 78 const DoStuffCallback& callback) override {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 MOJO_RESULT_OK, 125 MOJO_RESULT_OK,
127 ReadDataRaw( 126 ReadDataRaw(
128 pipe.get(), data, &data_size, MOJO_READ_DATA_FLAG_ALL_OR_NONE)); 127 pipe.get(), data, &data_size, MOJO_READ_DATA_FLAG_ALL_OR_NONE));
129 128
130 callback.Run(data); 129 callback.Run(data);
131 } 130 }
132 131
133 void CreateNamedObject( 132 void CreateNamedObject(
134 InterfaceRequest<sample::NamedObject> object_request) override { 133 InterfaceRequest<sample::NamedObject> object_request) override {
135 EXPECT_TRUE(object_request.is_pending()); 134 EXPECT_TRUE(object_request.is_pending());
136 new SampleNamedObjectImpl(std::move(object_request)); 135 MakeStrongBinding(base::MakeUnique<SampleNamedObjectImpl>(),
136 std::move(object_request));
137 } 137 }
138 138
139 // These aren't called or implemented, but exist here to test that the 139 // These aren't called or implemented, but exist here to test that the
140 // methods are generated with the correct argument types for imported 140 // methods are generated with the correct argument types for imported
141 // interfaces. 141 // interfaces.
142 void RequestImportedInterface( 142 void RequestImportedInterface(
143 InterfaceRequest<imported::ImportedInterface> imported, 143 InterfaceRequest<imported::ImportedInterface> imported,
144 const RequestImportedInterfaceCallback& callback) override {} 144 const RequestImportedInterfaceCallback& callback) override {}
145 void TakeImportedInterface( 145 void TakeImportedInterface(
146 imported::ImportedInterfacePtr imported, 146 imported::ImportedInterfacePtr imported,
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 run_loop.Run(); 349 run_loop.Run();
350 run_loop2.Run(); 350 run_loop2.Run();
351 351
352 EXPECT_EQ(std::string("object1"), name1); 352 EXPECT_EQ(std::string("object1"), name1);
353 EXPECT_EQ(std::string("object2"), name2); 353 EXPECT_EQ(std::string("object2"), name2);
354 } 354 }
355 355
356 } // namespace 356 } // namespace
357 } // namespace test 357 } // namespace test
358 } // namespace mojo 358 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/tests/e2e_perftest.cc ('k') | mojo/public/cpp/bindings/tests/interface_ptr_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698