Commit 636d3672 authored by Himanshu Jaju's avatar Himanshu Jaju Committed by Commit Bot

Rename Tachyon to InstantMessaging as per internal request.

Bug: 1082305
Change-Id: I0018ce068d2820befccf5e69c833725940690bfb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2273141
Commit-Queue: Himanshu Jaju <himanshujaju@chromium.org>
Reviewed-by: default avatarChristian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarAlex Chau <alexchau@chromium.org>
Reviewed-by: default avatarAlex Gough <ajgo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#784018}
parent af8aa5fd
......@@ -3292,6 +3292,15 @@ static_library("browser") {
"nearby_sharing/fast_initiation_manager.h",
"nearby_sharing/file_attachment.cc",
"nearby_sharing/file_attachment.h",
"nearby_sharing/instantmessaging/constants.h",
"nearby_sharing/instantmessaging/receive_messages_express.cc",
"nearby_sharing/instantmessaging/receive_messages_express.h",
"nearby_sharing/instantmessaging/send_message_express.cc",
"nearby_sharing/instantmessaging/send_message_express.h",
"nearby_sharing/instantmessaging/stream_parser.cc",
"nearby_sharing/instantmessaging/stream_parser.h",
"nearby_sharing/instantmessaging/token_fetcher.cc",
"nearby_sharing/instantmessaging/token_fetcher.h",
"nearby_sharing/nearby_connection.h",
"nearby_sharing/nearby_connections_manager.h",
"nearby_sharing/nearby_connections_manager_impl.cc",
......@@ -3309,15 +3318,6 @@ static_library("browser") {
"nearby_sharing/share_target.cc",
"nearby_sharing/share_target.h",
"nearby_sharing/share_target_discovered_callback.h",
"nearby_sharing/tachyon/constants.h",
"nearby_sharing/tachyon/receive_messages_express.cc",
"nearby_sharing/tachyon/receive_messages_express.h",
"nearby_sharing/tachyon/send_message_express.cc",
"nearby_sharing/tachyon/send_message_express.h",
"nearby_sharing/tachyon/stream_parser.cc",
"nearby_sharing/tachyon/stream_parser.h",
"nearby_sharing/tachyon/token_fetcher.cc",
"nearby_sharing/tachyon/token_fetcher.h",
"nearby_sharing/text_attachment.cc",
"nearby_sharing/text_attachment.h",
"nearby_sharing/transfer_metadata.cc",
......@@ -3715,10 +3715,10 @@ static_library("browser") {
"//chrome/app/vector_icons",
"//chrome/browser/media/kaleidoscope/mojom",
"//chrome/browser/nearby_sharing/certificates",
"//chrome/browser/nearby_sharing/instantmessaging/proto",
"//chrome/browser/nearby_sharing/logging",
"//chrome/browser/nearby_sharing/proto",
"//chrome/browser/nearby_sharing/scheduling",
"//chrome/browser/nearby_sharing/tachyon/proto",
"//chrome/browser/policy:path_parser",
"//chrome/browser/profile_resetter:profile_reset_report_proto",
"//chrome/browser/resource_coordinator:intervention_policy_database_proto",
......
......@@ -2,26 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_TACHYON_CONSTANTS_H_
#define CHROME_BROWSER_NEARBY_SHARING_TACHYON_CONSTANTS_H_
#ifndef CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_CONSTANTS_H_
#define CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_CONSTANTS_H_
#if defined(NDEBUG)
const char kTachyonReceiveMessageAPI[] =
const char kInstantMessagingReceiveMessageAPI[] =
"https://tachyon-playground-autopush-grpc.sandbox.googleapis.com/v1/"
"messages:receiveExpress";
const char kTachyonSendMessageAPI[] =
const char kInstantMessagingSendMessageAPI[] =
"https://tachyon-playground-autopush-grpc.sandbox.googleapis.com/v1/"
"message:sendExpress";
#else
const char kTachyonReceiveMessageAPI[] =
const char kInstantMessagingReceiveMessageAPI[] =
"https://instantmessaging-pa.googleapis.com/v1/messages:receiveExpress";
const char kTachyonSendMessageAPI[] =
const char kInstantMessagingSendMessageAPI[] =
"https://instantmessaging-pa.googleapis.com/v1/message:sendExpress";
#endif // defined(NDEBUG)
// Template for optional OAuth2 authorization HTTP header.
const char kAuthorizationHeaderFormat[] = "Authorization: Bearer %s";
#endif // CHROME_BROWSER_NEARBY_SHARING_TACHYON_CONSTANTS_H_
#endif // CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_CONSTANTS_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/tachyon/fake_token_fetcher.h"
#include "chrome/browser/nearby_sharing/instantmessaging/fake_token_fetcher.h"
FakeTokenFetcher::FakeTokenFetcher()
: TokenFetcher(/*identity_manager=*/nullptr) {}
......
......@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_TACHYON_FAKE_TOKEN_FETCHER_H_
#define CHROME_BROWSER_NEARBY_SHARING_TACHYON_FAKE_TOKEN_FETCHER_H_
#ifndef CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_FAKE_TOKEN_FETCHER_H_
#define CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_FAKE_TOKEN_FETCHER_H_
#include <string>
#include "chrome/browser/nearby_sharing/tachyon/token_fetcher.h"
#include "chrome/browser/nearby_sharing/instantmessaging/token_fetcher.h"
class FakeTokenFetcher : public TokenFetcher {
public:
......@@ -22,4 +22,4 @@ class FakeTokenFetcher : public TokenFetcher {
std::string token_;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_TACHYON_FAKE_TOKEN_FETCHER_H_
#endif // CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_FAKE_TOKEN_FETCHER_H_
......@@ -12,5 +12,5 @@ group("proto_lite") {
}
proto_library("proto") {
sources = [ "tachyon.proto" ]
sources = [ "instantmessaging.proto" ]
}
......@@ -2,13 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Brought from:
// google3/google/internal/communications/instantmessaging/v1/tachyon.proto At
// CL 316140872
// Brought at CL 316140872
syntax = "proto3";
package chrome_browser_nearby_sharing_tachyon;
package chrome_browser_nearby_sharing_instantmessaging;
// Required in Chrome.
option optimize_for = LITE_RUNTIME;
......
......@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/tachyon/receive_messages_express.h"
#include "chrome/browser/nearby_sharing/instantmessaging/receive_messages_express.h"
#include "base/bind.h"
#include "base/callback.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/nearby_sharing/tachyon/constants.h"
#include "chrome/browser/nearby_sharing/tachyon/proto/tachyon.pb.h"
#include "chrome/browser/nearby_sharing/tachyon/token_fetcher.h"
#include "chrome/browser/nearby_sharing/instantmessaging/constants.h"
#include "chrome/browser/nearby_sharing/instantmessaging/proto/instantmessaging.pb.h"
#include "chrome/browser/nearby_sharing/instantmessaging/token_fetcher.h"
#include "net/base/load_flags.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
......@@ -65,8 +65,8 @@ ReceiveMessagesExpress::~ReceiveMessagesExpress() {
}
void ReceiveMessagesExpress::StartReceivingMessages(
const chrome_browser_nearby_sharing_tachyon::ReceiveMessagesExpressRequest&
request,
const chrome_browser_nearby_sharing_instantmessaging::
ReceiveMessagesExpressRequest& request,
base::RepeatingCallback<void(const std::string& message)> listener,
SuccessCallback callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -86,8 +86,8 @@ void ReceiveMessagesExpress::StartReceivingMessages(
}
void ReceiveMessagesExpress::DoStartReceivingMessages(
const chrome_browser_nearby_sharing_tachyon::ReceiveMessagesExpressRequest&
request,
const chrome_browser_nearby_sharing_instantmessaging::
ReceiveMessagesExpressRequest& request,
const std::string& oauth_token) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (oauth_token.empty()) {
......@@ -96,7 +96,7 @@ void ReceiveMessagesExpress::DoStartReceivingMessages(
}
auto resource_request = std::make_unique<network::ResourceRequest>();
resource_request->url = GURL(kTachyonReceiveMessageAPI);
resource_request->url = GURL(kInstantMessagingReceiveMessageAPI);
resource_request->load_flags =
net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE;
resource_request->credentials_mode = network::mojom::CredentialsMode::kOmit;
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_TACHYON_RECEIVE_MESSAGES_EXPRESS_H_
#define CHROME_BROWSER_NEARBY_SHARING_TACHYON_RECEIVE_MESSAGES_EXPRESS_H_
#ifndef CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_RECEIVE_MESSAGES_EXPRESS_H_
#define CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_RECEIVE_MESSAGES_EXPRESS_H_
#include <cstdint>
......@@ -11,12 +11,12 @@
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/sequence_checker.h"
#include "chrome/browser/nearby_sharing/tachyon/stream_parser.h"
#include "chrome/browser/nearby_sharing/instantmessaging/stream_parser.h"
#include "services/network/public/cpp/simple_url_loader_stream_consumer.h"
namespace chrome_browser_nearby_sharing_tachyon {
namespace chrome_browser_nearby_sharing_instantmessaging {
class ReceiveMessagesExpressRequest;
} // namespace chrome_browser_nearby_sharing_tachyon
} // namespace chrome_browser_nearby_sharing_instantmessaging
namespace network {
class SharedURLLoaderFactory;
......@@ -25,7 +25,7 @@ class SimpleURLLoader;
class TokenFetcher;
// Receives streaming messages from Tachyon Express API over HTTP. Responsible
// Receives streaming messages from Instant Messaging API over HTTP. Responsible
// for parsing incoming bytes into valid ReceivesMessagesExpressResponse
// messages.
class ReceiveMessagesExpress : public network::SimpleURLLoaderStreamConsumer {
......@@ -38,23 +38,24 @@ class ReceiveMessagesExpress : public network::SimpleURLLoaderStreamConsumer {
~ReceiveMessagesExpress() override;
// Registers with Tachyon to start receiving messages. Each individual message
// is passed to |listener|. Subsequent calls to this method replaces the
// registered listener.
// Registers with InstantMessaging to start receiving messages. Each
// individual message is passed to |listener|. Subsequent calls to this method
// replaces the registered listener.
void StartReceivingMessages(
const chrome_browser_nearby_sharing_tachyon::
const chrome_browser_nearby_sharing_instantmessaging::
ReceiveMessagesExpressRequest& request,
base::RepeatingCallback<void(const std::string& message)> listener,
SuccessCallback callback);
// Stops the incoming stream of messages from Tachyon and unregisters the
// listener.
// Stops the incoming stream of messages from InstantMessaging and unregisters
// the listener.
void StopReceivingMessages();
private:
void DoStartReceivingMessages(const chrome_browser_nearby_sharing_tachyon::
ReceiveMessagesExpressRequest& request,
const std::string& oauth_token);
void DoStartReceivingMessages(
const chrome_browser_nearby_sharing_instantmessaging::
ReceiveMessagesExpressRequest& request,
const std::string& oauth_token);
// network::SimpleURLLoaderStreamConsumer:
void OnDataReceived(base::StringPiece string_piece,
......@@ -73,4 +74,4 @@ class ReceiveMessagesExpress : public network::SimpleURLLoaderStreamConsumer {
base::WeakPtrFactory<ReceiveMessagesExpress> weak_ptr_factory_{this};
};
#endif // CHROME_BROWSER_NEARBY_SHARING_TACHYON_RECEIVE_MESSAGES_EXPRESS_H_
#endif // CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_RECEIVE_MESSAGES_EXPRESS_H_
......@@ -2,35 +2,37 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/tachyon/receive_messages_express.h"
#include "chrome/browser/nearby_sharing/instantmessaging/receive_messages_express.h"
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/test/task_environment.h"
#include "chrome/browser/nearby_sharing/tachyon/constants.h"
#include "chrome/browser/nearby_sharing/tachyon/fake_token_fetcher.h"
#include "chrome/browser/nearby_sharing/tachyon/proto/tachyon.pb.h"
#include "chrome/browser/nearby_sharing/instantmessaging/constants.h"
#include "chrome/browser/nearby_sharing/instantmessaging/fake_token_fetcher.h"
#include "chrome/browser/nearby_sharing/instantmessaging/proto/instantmessaging.pb.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
chrome_browser_nearby_sharing_tachyon::ReceiveMessagesExpressRequest
chrome_browser_nearby_sharing_instantmessaging::ReceiveMessagesExpressRequest
CreateRequest() {
return chrome_browser_nearby_sharing_tachyon::ReceiveMessagesExpressRequest();
return chrome_browser_nearby_sharing_instantmessaging::
ReceiveMessagesExpressRequest();
}
chrome_browser_nearby_sharing_tachyon::ReceiveMessagesResponse
chrome_browser_nearby_sharing_instantmessaging::ReceiveMessagesResponse
CreateReceiveMessagesResponse(const std::string& msg) {
chrome_browser_nearby_sharing_tachyon::ReceiveMessagesResponse response;
chrome_browser_nearby_sharing_instantmessaging::ReceiveMessagesResponse
response;
response.mutable_inbox_message()->set_message(msg);
return response;
}
chrome_browser_nearby_sharing_tachyon::StreamBody BuildResponseProto(
chrome_browser_nearby_sharing_instantmessaging::StreamBody BuildResponseProto(
const std::vector<std::string>& messages) {
chrome_browser_nearby_sharing_tachyon::StreamBody stream_body;
chrome_browser_nearby_sharing_instantmessaging::StreamBody stream_body;
for (const auto& msg : messages) {
stream_body.add_messages(
CreateReceiveMessagesResponse(msg).SerializeAsString());
......@@ -106,13 +108,14 @@ TEST_F(ReceiveMessagesExpressTest, HttpResponseError) {
EXPECT_FALSE(success);
run_loop.Quit();
}));
ASSERT_TRUE(GetTestUrlLoaderFactory().IsPending(kTachyonReceiveMessageAPI));
ASSERT_TRUE(
GetTestUrlLoaderFactory().IsPending(kInstantMessagingReceiveMessageAPI));
std::string response = BuildResponseProto({"message"}).SerializeAsString();
// Calls OnComplete(false) in ReceiveMessagesExpress. OnDataReceived() is not
// called.
GetTestUrlLoaderFactory().AddResponse(kTachyonReceiveMessageAPI, response,
net::HTTP_FORBIDDEN);
GetTestUrlLoaderFactory().AddResponse(kInstantMessagingReceiveMessageAPI,
response, net::HTTP_FORBIDDEN);
run_loop.Run();
EXPECT_EQ(0, NumMessagesReceived());
......@@ -130,14 +133,15 @@ TEST_F(ReceiveMessagesExpressTest, SuccessfulResponse) {
run_loop.Quit();
}));
ASSERT_EQ(1, GetTestUrlLoaderFactory().NumPending());
ASSERT_TRUE(GetTestUrlLoaderFactory().IsPending(kTachyonReceiveMessageAPI));
ASSERT_TRUE(
GetTestUrlLoaderFactory().IsPending(kInstantMessagingReceiveMessageAPI));
std::vector<std::string> messages = {"quick brown", "fox"};
std::string response = BuildResponseProto(messages).SerializeAsString();
// Calls OnDataReceived() in ReceiveMessagesExpress.
GetTestUrlLoaderFactory().AddResponse(kTachyonReceiveMessageAPI, response,
net::HTTP_OK);
GetTestUrlLoaderFactory().AddResponse(kInstantMessagingReceiveMessageAPI,
response, net::HTTP_OK);
ASSERT_EQ(0, GetTestUrlLoaderFactory().NumPending());
run_loop.Run();
......@@ -157,7 +161,8 @@ TEST_F(ReceiveMessagesExpressTest, SuccessfulPartialResponse) {
run_loop.Quit();
}));
ASSERT_EQ(1, GetTestUrlLoaderFactory().NumPending());
ASSERT_TRUE(GetTestUrlLoaderFactory().IsPending(kTachyonReceiveMessageAPI));
ASSERT_TRUE(
GetTestUrlLoaderFactory().IsPending(kInstantMessagingReceiveMessageAPI));
std::vector<std::string> messages = {"quick brown", "fox"};
std::string response = BuildResponseProto(messages).SerializeAsString();
......@@ -167,8 +172,8 @@ TEST_F(ReceiveMessagesExpressTest, SuccessfulPartialResponse) {
response += partial_response.substr(0, 10);
// Calls OnDataReceived() in ReceiveMessagesExpress.
GetTestUrlLoaderFactory().AddResponse(kTachyonReceiveMessageAPI, response,
net::HTTP_OK);
GetTestUrlLoaderFactory().AddResponse(kInstantMessagingReceiveMessageAPI,
response, net::HTTP_OK);
ASSERT_EQ(0, GetTestUrlLoaderFactory().NumPending());
run_loop.Run();
......
......@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/tachyon/send_message_express.h"
#include "chrome/browser/nearby_sharing/instantmessaging/send_message_express.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/nearby_sharing/tachyon/constants.h"
#include "chrome/browser/nearby_sharing/tachyon/proto/tachyon.pb.h"
#include "chrome/browser/nearby_sharing/tachyon/token_fetcher.h"
#include "chrome/browser/nearby_sharing/instantmessaging/constants.h"
#include "chrome/browser/nearby_sharing/instantmessaging/proto/instantmessaging.pb.h"
#include "chrome/browser/nearby_sharing/instantmessaging/token_fetcher.h"
#include "net/base/load_flags.h"
#include "services/network/public/cpp/cors/cors.h"
#include "services/network/public/cpp/resource_request.h"
......@@ -73,8 +73,8 @@ SendMessageExpress::SendMessageExpress(
SendMessageExpress::~SendMessageExpress() = default;
void SendMessageExpress::SendMessage(
const chrome_browser_nearby_sharing_tachyon::SendMessageExpressRequest&
request,
const chrome_browser_nearby_sharing_instantmessaging::
SendMessageExpressRequest& request,
SuccessCallback callback) {
token_fetcher_->GetAccessToken(base::BindOnce(
&SendMessageExpress::DoSendMessage, weak_ptr_factory_.GetWeakPtr(),
......@@ -82,8 +82,8 @@ void SendMessageExpress::SendMessage(
}
void SendMessageExpress::DoSendMessage(
const chrome_browser_nearby_sharing_tachyon::SendMessageExpressRequest&
request,
const chrome_browser_nearby_sharing_instantmessaging::
SendMessageExpressRequest& request,
SuccessCallback callback,
const std::string& oauth_token) {
if (oauth_token.empty()) {
......@@ -94,7 +94,7 @@ void SendMessageExpress::DoSendMessage(
std::string message_id = request.header().requester_id().id();
auto resource_request = std::make_unique<network::ResourceRequest>();
resource_request->url = GURL(kTachyonSendMessageAPI);
resource_request->url = GURL(kInstantMessagingSendMessageAPI);
resource_request->load_flags =
net::LOAD_BYPASS_CACHE | net::LOAD_DISABLE_CACHE;
resource_request->credentials_mode = network::mojom::CredentialsMode::kOmit;
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_TACHYON_SEND_MESSAGE_EXPRESS_H_
#define CHROME_BROWSER_NEARBY_SHARING_TACHYON_SEND_MESSAGE_EXPRESS_H_
#ifndef CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_SEND_MESSAGE_EXPRESS_H_
#define CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_SEND_MESSAGE_EXPRESS_H_
#include <map>
#include <memory>
......@@ -13,9 +13,9 @@
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
namespace chrome_browser_nearby_sharing_tachyon {
namespace chrome_browser_nearby_sharing_instantmessaging {
class SendMessageExpressRequest;
} // namespace chrome_browser_nearby_sharing_tachyon
} // namespace chrome_browser_nearby_sharing_instantmessaging
namespace network {
class SharedURLLoaderFactory;
......@@ -24,7 +24,7 @@ class SimpleURLLoader;
class TokenFetcher;
// Sends messages using the Tachyon Express API over HTTP.
// Sends messages using the Instant Messaging API over HTTP.
class SendMessageExpress {
public:
using SuccessCallback = base::OnceCallback<void(bool success)>;
......@@ -34,17 +34,15 @@ class SendMessageExpress {
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory);
~SendMessageExpress();
void SendMessage(
const chrome_browser_nearby_sharing_tachyon::SendMessageExpressRequest&
request,
SuccessCallback callback);
void SendMessage(const chrome_browser_nearby_sharing_instantmessaging::
SendMessageExpressRequest& request,
SuccessCallback callback);
private:
void DoSendMessage(
const chrome_browser_nearby_sharing_tachyon::SendMessageExpressRequest&
request,
SuccessCallback callback,
const std::string& oauth_token);
void DoSendMessage(const chrome_browser_nearby_sharing_instantmessaging::
SendMessageExpressRequest& request,
SuccessCallback callback,
const std::string& oauth_token);
void OnSendMessageResponse(
const std::string& message_id,
std::unique_ptr<network::SimpleURLLoader> url_loader,
......@@ -56,4 +54,4 @@ class SendMessageExpress {
base::WeakPtrFactory<SendMessageExpress> weak_ptr_factory_{this};
};
#endif // CHROME_BROWSER_NEARBY_SHARING_TACHYON_SEND_MESSAGE_EXPRESS_H_
#endif // CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_SEND_MESSAGE_EXPRESS_H_
......@@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/tachyon/send_message_express.h"
#include "chrome/browser/nearby_sharing/instantmessaging/send_message_express.h"
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
#include "base/test/task_environment.h"
#include "chrome/browser/nearby_sharing/tachyon/constants.h"
#include "chrome/browser/nearby_sharing/tachyon/fake_token_fetcher.h"
#include "chrome/browser/nearby_sharing/tachyon/proto/tachyon.pb.h"
#include "chrome/browser/nearby_sharing/instantmessaging/constants.h"
#include "chrome/browser/nearby_sharing/instantmessaging/fake_token_fetcher.h"
#include "chrome/browser/nearby_sharing/instantmessaging/proto/instantmessaging.pb.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
......@@ -17,9 +17,10 @@
namespace {
chrome_browser_nearby_sharing_tachyon::SendMessageExpressRequest
chrome_browser_nearby_sharing_instantmessaging::SendMessageExpressRequest
CreateRequest() {
return chrome_browser_nearby_sharing_tachyon::SendMessageExpressRequest();
return chrome_browser_nearby_sharing_instantmessaging::
SendMessageExpressRequest();
}
} // namespace
......@@ -70,9 +71,10 @@ TEST_F(SendMessageExpressTest, HttpResponseError) {
EXPECT_FALSE(success);
run_loop.Quit();
}));
ASSERT_TRUE(GetTestUrlLoaderFactory().IsPending(kTachyonSendMessageAPI));
GetTestUrlLoaderFactory().AddResponse(kTachyonSendMessageAPI, "response",
net::HTTP_FORBIDDEN);
ASSERT_TRUE(
GetTestUrlLoaderFactory().IsPending(kInstantMessagingSendMessageAPI));
GetTestUrlLoaderFactory().AddResponse(kInstantMessagingSendMessageAPI,
"response", net::HTTP_FORBIDDEN);
run_loop.Run();
}
......@@ -84,8 +86,9 @@ TEST_F(SendMessageExpressTest, EmptyResponse) {
EXPECT_FALSE(success);
run_loop.Quit();
}));
ASSERT_TRUE(GetTestUrlLoaderFactory().IsPending(kTachyonSendMessageAPI));
GetTestUrlLoaderFactory().AddResponse(kTachyonSendMessageAPI, "",
ASSERT_TRUE(
GetTestUrlLoaderFactory().IsPending(kInstantMessagingSendMessageAPI));
GetTestUrlLoaderFactory().AddResponse(kInstantMessagingSendMessageAPI, "",
net::HTTP_OK);
run_loop.Run();
}
......@@ -98,8 +101,9 @@ TEST_F(SendMessageExpressTest, SuccessfulResponse) {
EXPECT_TRUE(success);
run_loop.Quit();
}));
ASSERT_TRUE(GetTestUrlLoaderFactory().IsPending(kTachyonSendMessageAPI));
GetTestUrlLoaderFactory().AddResponse(kTachyonSendMessageAPI, "response",
net::HTTP_OK);
ASSERT_TRUE(
GetTestUrlLoaderFactory().IsPending(kInstantMessagingSendMessageAPI));
GetTestUrlLoaderFactory().AddResponse(kInstantMessagingSendMessageAPI,
"response", net::HTTP_OK);
run_loop.Run();
}
......@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/tachyon/stream_parser.h"
#include "chrome/browser/nearby_sharing/instantmessaging/stream_parser.h"
#include "chrome/browser/nearby_sharing/tachyon/proto/tachyon.pb.h"
#include "chrome/browser/nearby_sharing/instantmessaging/proto/instantmessaging.pb.h"
StreamParser::StreamParser(
base::RepeatingCallback<void(const std::string& message)> listener)
......@@ -15,7 +15,7 @@ void StreamParser::Append(base::StringPiece data) {
size_t size = data.as_string().size();
data_.append(data.as_string().data(), size);
base::Optional<chrome_browser_nearby_sharing_tachyon::StreamBody>
base::Optional<chrome_browser_nearby_sharing_instantmessaging::StreamBody>
stream_body = GetNextMessage();
while (stream_body) {
DelegateMessage(stream_body.value());
......@@ -23,7 +23,7 @@ void StreamParser::Append(base::StringPiece data) {
}
}
base::Optional<chrome_browser_nearby_sharing_tachyon::StreamBody>
base::Optional<chrome_browser_nearby_sharing_instantmessaging::StreamBody>
StreamParser::GetNextMessage() {
// The incoming stream may not be a valid StreamBody proto as it might be
// split into various OnDataReceived calls. The easy way is to append all
......@@ -40,7 +40,7 @@ StreamParser::GetNextMessage() {
// There's a good chance that the entire message is a valid proto since the
// individual messages sent by WebRTC are small, so check that first to
// speed up parsing.
chrome_browser_nearby_sharing_tachyon::StreamBody stream_body;
chrome_browser_nearby_sharing_instantmessaging::StreamBody stream_body;
if (stream_body.ParseFromString(data_)) {
data_.clear();
return stream_body;
......@@ -63,15 +63,17 @@ StreamParser::GetNextMessage() {
}
void StreamParser::DelegateMessage(
const chrome_browser_nearby_sharing_tachyon::StreamBody& stream_body) {
const chrome_browser_nearby_sharing_instantmessaging::StreamBody&
stream_body) {
// Security Note - The ReceiveMessagesResponse proto is coming from a trusted
// Google server and hence can be parsed on the browser process. The message
// contained within the proto is untrusted and should be parsed within a
// sandbox process.
for (int i = 0; i < stream_body.messages_size(); i++) {
chrome_browser_nearby_sharing_tachyon::ReceiveMessagesResponse response;
chrome_browser_nearby_sharing_instantmessaging::ReceiveMessagesResponse
response;
response.ParseFromString(stream_body.messages(i));
if (response.body_case() != chrome_browser_nearby_sharing_tachyon::
if (response.body_case() != chrome_browser_nearby_sharing_instantmessaging::
ReceiveMessagesResponse::kInboxMessage)
continue;
listener_.Run(response.inbox_message().message());
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_TACHYON_STREAM_PARSER_H_
#define CHROME_BROWSER_NEARBY_SHARING_TACHYON_STREAM_PARSER_H_
#ifndef CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_STREAM_PARSER_H_
#define CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_STREAM_PARSER_H_
#include <string>
......@@ -11,9 +11,9 @@
#include "base/optional.h"
#include "base/strings/string_piece.h"
namespace chrome_browser_nearby_sharing_tachyon {
namespace chrome_browser_nearby_sharing_instantmessaging {
class StreamBody;
} // namespace chrome_browser_nearby_sharing_tachyon
} // namespace chrome_browser_nearby_sharing_instantmessaging
// Parses incoming stream of data into valid proto objects and delegates them to
// the registered callback.
......@@ -26,13 +26,14 @@ class StreamParser {
void Append(base::StringPiece data);
private:
base::Optional<chrome_browser_nearby_sharing_tachyon::StreamBody>
base::Optional<chrome_browser_nearby_sharing_instantmessaging::StreamBody>
GetNextMessage();
void DelegateMessage(
const chrome_browser_nearby_sharing_tachyon::StreamBody& stream_body);
const chrome_browser_nearby_sharing_instantmessaging::StreamBody&
stream_body);
base::RepeatingCallback<void(const std::string& message)> listener_;
std::string data_;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_TACHYON_STREAM_PARSER_H_
#endif // CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_STREAM_PARSER_H_
......@@ -2,27 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/tachyon/stream_parser.h"
#include "chrome/browser/nearby_sharing/instantmessaging/stream_parser.h"
#include <string>
#include <vector>
#include "base/bind.h"
#include "chrome/browser/nearby_sharing/tachyon/proto/tachyon.pb.h"
#include "chrome/browser/nearby_sharing/instantmessaging/proto/instantmessaging.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
chrome_browser_nearby_sharing_tachyon::ReceiveMessagesResponse
chrome_browser_nearby_sharing_instantmessaging::ReceiveMessagesResponse
CreateReceiveMessagesResponse(const std::string& msg) {
chrome_browser_nearby_sharing_tachyon::ReceiveMessagesResponse response;
chrome_browser_nearby_sharing_instantmessaging::ReceiveMessagesResponse
response;
response.mutable_inbox_message()->set_message(msg);
return response;
}
chrome_browser_nearby_sharing_tachyon::StreamBody BuildProto(
chrome_browser_nearby_sharing_instantmessaging::StreamBody BuildProto(
const std::vector<std::string>& messages) {
chrome_browser_nearby_sharing_tachyon::StreamBody stream_body;
chrome_browser_nearby_sharing_instantmessaging::StreamBody stream_body;
for (const auto& msg : messages) {
stream_body.add_messages(
CreateReceiveMessagesResponse(msg).SerializeAsString());
......@@ -57,7 +58,7 @@ class StreamParserTest : public testing::Test {
// The entire message is sent in one response body.
TEST_F(StreamParserTest, SingleEntireMessageAtOnce) {
std::vector<std::string> messages = {"random 42"};
chrome_browser_nearby_sharing_tachyon::StreamBody stream_body =
chrome_browser_nearby_sharing_instantmessaging::StreamBody stream_body =
BuildProto(messages);
GetStreamParser().Append(stream_body.SerializeAsString());
......@@ -69,7 +70,7 @@ TEST_F(StreamParserTest, SingleEntireMessageAtOnce) {
TEST_F(StreamParserTest, MultipleEntireMessagesAtOnce) {
std::vector<std::string> messages = {"random 42", "more random 98",
"himanshujaju 25"};
chrome_browser_nearby_sharing_tachyon::StreamBody stream_body =
chrome_browser_nearby_sharing_instantmessaging::StreamBody stream_body =
BuildProto(messages);
GetStreamParser().Append(stream_body.SerializeAsString());
......@@ -80,7 +81,7 @@ TEST_F(StreamParserTest, MultipleEntireMessagesAtOnce) {
// A single message is sent over multiple response bodies.
TEST_F(StreamParserTest, SingleMessageSplit) {
std::vector<std::string> messages = {"random 42 and random 92"};
chrome_browser_nearby_sharing_tachyon::StreamBody stream_body =
chrome_browser_nearby_sharing_instantmessaging::StreamBody stream_body =
BuildProto(messages);
std::string serialized_msg = stream_body.SerializeAsString();
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/nearby_sharing/tachyon/token_fetcher.h"
#include "chrome/browser/nearby_sharing/instantmessaging/token_fetcher.h"
#include "google_apis/gaia/gaia_constants.h"
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NEARBY_SHARING_TACHYON_TOKEN_FETCHER_H_
#define CHROME_BROWSER_NEARBY_SHARING_TACHYON_TOKEN_FETCHER_H_
#ifndef CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_TOKEN_FETCHER_H_
#define CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_TOKEN_FETCHER_H_
#include <memory>
#include <string>
......@@ -14,8 +14,8 @@
#include "components/signin/public/identity_manager/identity_manager.h"
#include "google_apis/gaia/google_service_auth_error.h"
// TokenFetcher is used for fetching oauth tokens for interacting with Tachyon
// servers to send and receive messages.
// TokenFetcher is used for fetching oauth tokens for interacting with
// InstantMessaging servers to send and receive messages.
class TokenFetcher {
public:
explicit TokenFetcher(signin::IdentityManager* identity_manager);
......@@ -38,4 +38,4 @@ class TokenFetcher {
base::WeakPtrFactory<TokenFetcher> weak_ptr_factory_{this};
};
#endif // CHROME_BROWSER_NEARBY_SHARING_TACHYON_TOKEN_FETCHER_H_
#endif // CHROME_BROWSER_NEARBY_SHARING_INSTANTMESSAGING_TOKEN_FETCHER_H_
......@@ -3625,13 +3625,13 @@ test("unit_tests") {
"../browser/nearby_sharing/fake_nearby_connections_manager.cc",
"../browser/nearby_sharing/fake_nearby_connections_manager.h",
"../browser/nearby_sharing/fast_initiation_manager_unittest.cc",
"../browser/nearby_sharing/instantmessaging/fake_token_fetcher.cc",
"../browser/nearby_sharing/instantmessaging/fake_token_fetcher.h",
"../browser/nearby_sharing/instantmessaging/receive_messages_express_unittest.cc",
"../browser/nearby_sharing/instantmessaging/send_message_express_unittest.cc",
"../browser/nearby_sharing/instantmessaging/stream_parser_unittest.cc",
"../browser/nearby_sharing/nearby_process_manager_unittest.cc",
"../browser/nearby_sharing/nearby_sharing_service_impl_unittest.cc",
"../browser/nearby_sharing/tachyon/fake_token_fetcher.cc",
"../browser/nearby_sharing/tachyon/fake_token_fetcher.h",
"../browser/nearby_sharing/tachyon/receive_messages_express_unittest.cc",
"../browser/nearby_sharing/tachyon/send_message_express_unittest.cc",
"../browser/nearby_sharing/tachyon/stream_parser_unittest.cc",
"../browser/profiles/profile_avatar_icon_util_unittest.cc",
"../browser/profiles/profile_destroyer_unittest.cc",
"../browser/safe_browsing/generated_safe_browsing_pref_unittest.cc",
......
......@@ -243,7 +243,7 @@ Refer to README.md for content description and update process.
<item id="quic_chromium_packet_writer" hash_code="20153177" type="0" content_hash_code="29657765" os_list="linux,windows" file_path="net/quic/quic_chromium_packet_writer.cc"/>
<item id="ranker_url_fetcher" hash_code="95682324" type="0" content_hash_code="45958626" os_list="linux,windows" file_path="components/assist_ranker/ranker_url_fetcher.cc"/>
<item id="rappor_report" hash_code="44606780" type="0" content_hash_code="111287826" os_list="linux,windows" file_path="components/rappor/log_uploader.cc"/>
<item id="receive_messages_express" hash_code="29506140" type="0" content_hash_code="38581365" os_list="linux,windows" file_path="chrome/browser/nearby_sharing/tachyon/receive_messages_express.cc"/>
<item id="receive_messages_express" hash_code="29506140" type="0" content_hash_code="38581365" os_list="linux,windows" file_path="chrome/browser/nearby_sharing/instantmessaging/receive_messages_express.cc"/>
<item id="refresh_token_annotation_request" hash_code="7433837" type="1" second_id="29188932" deprecated="2018-01-17" content_hash_code="137103383" file_path=""/>
<item id="remote_copy_message_handler" hash_code="80255301" type="0" content_hash_code="117673331" os_list="linux,windows" file_path="chrome/browser/sharing/shared_clipboard/remote_copy_message_handler.cc"/>
<item id="remote_suggestions_provider" hash_code="49544361" type="0" content_hash_code="126329742" os_list="linux,windows" file_path="components/ntp_snippets/remote/cached_image_fetcher.cc"/>
......@@ -273,7 +273,7 @@ Refer to README.md for content description and update process.
<item id="sdch_dictionary_fetch" hash_code="47152935" type="0" deprecated="2017-09-16" content_hash_code="16764294" file_path=""/>
<item id="search_suggest_service" hash_code="57785193" type="0" content_hash_code="132247652" os_list="linux,windows" file_path="chrome/browser/search/search_suggest/search_suggest_loader_impl.cc"/>
<item id="security_key_socket" hash_code="31074955" type="0" content_hash_code="13741232" os_list="linux,windows" file_path="remoting/host/security_key/security_key_socket.cc"/>
<item id="send_message_express" hash_code="23527666" type="0" content_hash_code="96850228" os_list="linux,windows" file_path="chrome/browser/nearby_sharing/tachyon/send_message_express.cc"/>
<item id="send_message_express" hash_code="23527666" type="0" content_hash_code="96850228" os_list="linux,windows" file_path="chrome/browser/nearby_sharing/instantmessaging/send_message_express.cc"/>
<item id="service_worker_navigation_preload" hash_code="129872904" type="0" content_hash_code="79473248" os_list="linux,windows" file_path="content/browser/service_worker/service_worker_fetch_dispatcher.cc"/>
<item id="service_worker_update_checker" hash_code="130931413" type="0" content_hash_code="46608086" os_list="linux,windows" file_path="content/browser/service_worker/service_worker_single_script_update_checker.cc"/>
<item id="services_http_server_error_response" hash_code="59302801" type="0" content_hash_code="127774041" os_list="linux,windows" file_path="services/network/public/cpp/server/http_server.cc"/>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment