OLD | NEW |
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 "components/copresence/rpc/rpc_handler.h" | 5 #include "components/copresence/rpc/rpc_handler.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 message_proto->mutable_published_message()->set_payload(message_string); | 33 message_proto->mutable_published_message()->set_payload(message_string); |
34 for (const std::string& subscription_id : subscription_ids) { | 34 for (const std::string& subscription_id : subscription_ids) { |
35 message_proto->add_subscription_id(subscription_id); | 35 message_proto->add_subscription_id(subscription_id); |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 // TODO(ckehoe): Make DirectiveHandler an interface. | 39 // TODO(ckehoe): Make DirectiveHandler an interface. |
40 class FakeDirectiveHandler : public DirectiveHandler { | 40 class FakeDirectiveHandler : public DirectiveHandler { |
41 public: | 41 public: |
42 FakeDirectiveHandler() {} | 42 FakeDirectiveHandler() {} |
43 virtual ~FakeDirectiveHandler() {} | 43 ~FakeDirectiveHandler() override {} |
44 | 44 |
45 const std::vector<Directive>& added_directives() const { | 45 const std::vector<Directive>& added_directives() const { |
46 return added_directives_; | 46 return added_directives_; |
47 } | 47 } |
48 | 48 |
49 virtual void Initialize( | 49 void Initialize( |
50 const AudioRecorder::DecodeSamplesCallback& decode_cb, | 50 const AudioRecorder::DecodeSamplesCallback& decode_cb, |
51 const AudioDirectiveHandler::EncodeTokenCallback& encode_cb) override {} | 51 const AudioDirectiveHandler::EncodeTokenCallback& encode_cb) override {} |
52 | 52 |
53 virtual void AddDirective(const Directive& directive) override { | 53 void AddDirective(const Directive& directive) override { |
54 added_directives_.push_back(directive); | 54 added_directives_.push_back(directive); |
55 } | 55 } |
56 | 56 |
57 virtual void RemoveDirectives(const std::string& op_id) override { | 57 void RemoveDirectives(const std::string& op_id) override { |
58 // TODO(ckehoe): Add a parallel implementation when prod has one. | 58 // TODO(ckehoe): Add a parallel implementation when prod has one. |
59 } | 59 } |
60 | 60 |
61 private: | 61 private: |
62 std::vector<Directive> added_directives_; | 62 std::vector<Directive> added_directives_; |
63 | 63 |
64 DISALLOW_COPY_AND_ASSIGN(FakeDirectiveHandler); | 64 DISALLOW_COPY_AND_ASSIGN(FakeDirectiveHandler); |
65 }; | 65 }; |
66 | 66 |
67 } // namespace | 67 } // namespace |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 const std::string& response) { | 130 const std::string& response) { |
131 rpc_handler_.ReportResponseHandler( | 131 rpc_handler_.ReportResponseHandler( |
132 base::Bind(&RpcHandlerTest::CaptureStatus, base::Unretained(this)), | 132 base::Bind(&RpcHandlerTest::CaptureStatus, base::Unretained(this)), |
133 NULL, | 133 NULL, |
134 status_code, | 134 status_code, |
135 response); | 135 response); |
136 } | 136 } |
137 | 137 |
138 // CopresenceDelegate implementation | 138 // CopresenceDelegate implementation |
139 | 139 |
140 virtual void HandleMessages( | 140 void HandleMessages(const std::string& app_id, |
141 const std::string& app_id, | 141 const std::string& subscription_id, |
142 const std::string& subscription_id, | 142 const std::vector<Message>& messages) override { |
143 const std::vector<Message>& messages) override { | |
144 // app_id is unused for now, pending a server fix. | 143 // app_id is unused for now, pending a server fix. |
145 messages_by_subscription_[subscription_id] = messages; | 144 messages_by_subscription_[subscription_id] = messages; |
146 } | 145 } |
147 | 146 |
148 virtual net::URLRequestContextGetter* GetRequestContext() const override { | 147 net::URLRequestContextGetter* GetRequestContext() const override { |
149 return NULL; | 148 return NULL; |
150 } | 149 } |
151 | 150 |
152 virtual const std::string GetPlatformVersionString() const override { | 151 const std::string GetPlatformVersionString() const override { |
153 return kChromeVersion; | 152 return kChromeVersion; |
154 } | 153 } |
155 | 154 |
156 virtual const std::string GetAPIKey() const override { | 155 const std::string GetAPIKey() const override { return api_key_; } |
157 return api_key_; | |
158 } | |
159 | 156 |
160 virtual WhispernetClient* GetWhispernetClient() override { | 157 WhispernetClient* GetWhispernetClient() override { return NULL; } |
161 return NULL; | |
162 } | |
163 | 158 |
164 protected: | 159 protected: |
165 // For rpc_handler_.invalid_audio_token_cache_ | 160 // For rpc_handler_.invalid_audio_token_cache_ |
166 base::MessageLoop message_loop_; | 161 base::MessageLoop message_loop_; |
167 | 162 |
168 RpcHandler rpc_handler_; | 163 RpcHandler rpc_handler_; |
169 CopresenceStatus status_; | 164 CopresenceStatus status_; |
170 std::string api_key_; | 165 std::string api_key_; |
171 | 166 |
172 std::string rpc_name_; | 167 std::string rpc_name_; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 messages_by_subscription_["Subscription 2"][1].payload()); | 268 messages_by_subscription_["Subscription 2"][1].payload()); |
274 | 269 |
275 ASSERT_EQ(2U, directive_handler->added_directives().size()); | 270 ASSERT_EQ(2U, directive_handler->added_directives().size()); |
276 EXPECT_EQ("Subscription 1", | 271 EXPECT_EQ("Subscription 1", |
277 directive_handler->added_directives()[0].subscription_id()); | 272 directive_handler->added_directives()[0].subscription_id()); |
278 EXPECT_EQ("Subscription 2", | 273 EXPECT_EQ("Subscription 2", |
279 directive_handler->added_directives()[1].subscription_id()); | 274 directive_handler->added_directives()[1].subscription_id()); |
280 } | 275 } |
281 | 276 |
282 } // namespace copresence | 277 } // namespace copresence |
OLD | NEW |