summaryrefslogtreecommitdiff
path: root/chromium/services
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2019-03-18 14:18:40 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2019-03-18 14:38:27 +0000
commit0078283f3cf586ae8a0d0df501a08e7440636b43 (patch)
tree9e227bbc71af5611b00176d23bf4f474c09bf54c /chromium/services
parenteaf1da4d961fbbda9455f9af3b23d1af777f43fa (diff)
downloadqtwebengine-chromium-0078283f3cf586ae8a0d0df501a08e7440636b43.tar.gz
BASELINE: Update Chromium to 73.0.3683.83
Change-Id: Ie2948cebb1e9204f293fdf63c36d6215a5f5b507 Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/services')
-rw-r--r--chromium/services/media_session/media_controller.cc23
-rw-r--r--chromium/services/media_session/media_controller.h6
-rw-r--r--chromium/services/media_session/media_controller_unittest.cc92
-rw-r--r--chromium/services/media_session/public/cpp/media_metadata.cc5
-rw-r--r--chromium/services/media_session/public/cpp/media_metadata.h3
-rw-r--r--chromium/services/media_session/public/mojom/media_controller.mojom21
-rw-r--r--chromium/services/network/mdns_responder.cc80
-rw-r--r--chromium/services/network/mdns_responder_unittest.cc69
-rw-r--r--chromium/services/network/network_service.cc21
-rw-r--r--chromium/services/network/network_service.h2
-rw-r--r--chromium/services/network/public/mojom/network_service.mojom15
-rw-r--r--chromium/services/tracing/public/cpp/traced_process_impl.cc6
-rw-r--r--chromium/services/tracing/public/cpp/traced_process_impl.h3
13 files changed, 211 insertions, 135 deletions
diff --git a/chromium/services/media_session/media_controller.cc b/chromium/services/media_session/media_controller.cc
index 4d48b5992f4..19afe2c0dc1 100644
--- a/chromium/services/media_session/media_controller.cc
+++ b/chromium/services/media_session/media_controller.cc
@@ -49,13 +49,11 @@ void MediaController::ToggleSuspendResume() {
}
}
-void MediaController::AddObserver(mojom::MediaSessionObserverPtr observer) {
+void MediaController::AddObserver(mojom::MediaControllerObserverPtr observer) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- // Flush the new observer with the state. We always flush the metadata as that
- // is optional so null is a valid value whereas the session info is required.
- if (!session_info_.is_null())
- observer->MediaSessionInfoChanged(session_info_.Clone());
+ // Flush the new observer with the current state.
+ observer->MediaSessionInfoChanged(session_info_.Clone());
observer->MediaSessionMetadataChanged(session_metadata_);
observer->MediaSessionActionsChanged(session_actions_);
@@ -65,7 +63,7 @@ void MediaController::AddObserver(mojom::MediaSessionObserverPtr observer) {
void MediaController::MediaSessionInfoChanged(mojom::MediaSessionInfoPtr info) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- observers_.ForAllPtrs([&info](mojom::MediaSessionObserver* observer) {
+ observers_.ForAllPtrs([&info](mojom::MediaControllerObserver* observer) {
observer->MediaSessionInfoChanged(info.Clone());
});
@@ -76,7 +74,7 @@ void MediaController::MediaSessionMetadataChanged(
const base::Optional<MediaMetadata>& metadata) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- observers_.ForAllPtrs([&metadata](mojom::MediaSessionObserver* observer) {
+ observers_.ForAllPtrs([&metadata](mojom::MediaControllerObserver* observer) {
observer->MediaSessionMetadataChanged(metadata);
});
@@ -87,7 +85,7 @@ void MediaController::MediaSessionActionsChanged(
const std::vector<mojom::MediaSessionAction>& actions) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- observers_.ForAllPtrs([&actions](mojom::MediaSessionObserver* observer) {
+ observers_.ForAllPtrs([&actions](mojom::MediaControllerObserver* observer) {
observer->MediaSessionActionsChanged(actions);
});
@@ -131,6 +129,15 @@ bool MediaController::SetMediaSession(mojom::MediaSession* session) {
mojom::MediaSessionObserverPtr observer;
session_binding_.Bind(mojo::MakeRequest(&observer));
session->AddObserver(std::move(observer));
+ } else {
+ // If we are no longer bound to a session we should flush the observers
+ // with empty data.
+ observers_.ForAllPtrs([](mojom::MediaControllerObserver* observer) {
+ observer->MediaSessionInfoChanged(nullptr);
+ observer->MediaSessionMetadataChanged(base::nullopt);
+ observer->MediaSessionActionsChanged(
+ std::vector<mojom::MediaSessionAction>());
+ });
}
}
diff --git a/chromium/services/media_session/media_controller.h b/chromium/services/media_session/media_controller.h
index 0cf05d70631..7cb0b0ec745 100644
--- a/chromium/services/media_session/media_controller.h
+++ b/chromium/services/media_session/media_controller.h
@@ -33,7 +33,7 @@ class MediaController : public mojom::MediaController,
void Resume() override;
void Stop() override;
void ToggleSuspendResume() override;
- void AddObserver(mojom::MediaSessionObserverPtr observer) override;
+ void AddObserver(mojom::MediaControllerObserverPtr observer) override;
void PreviousTrack() override;
void NextTrack() override;
void Seek(base::TimeDelta seek_time) override;
@@ -70,8 +70,8 @@ class MediaController : public mojom::MediaController,
// the underlying MediaSession.
mojom::MediaSession* session_ = nullptr;
- // Observers that are observing |session_|.
- mojo::InterfacePtrSet<mojom::MediaSessionObserver> observers_;
+ // Observers that are observing |this|.
+ mojo::InterfacePtrSet<mojom::MediaControllerObserver> observers_;
// Binding for |this| to act as an observer to |session_|.
mojo::Binding<mojom::MediaSessionObserver> session_binding_{this};
diff --git a/chromium/services/media_session/media_controller_unittest.cc b/chromium/services/media_session/media_controller_unittest.cc
index 16a15db88b3..9e2f0d28225 100644
--- a/chromium/services/media_session/media_controller_unittest.cc
+++ b/chromium/services/media_session/media_controller_unittest.cc
@@ -16,6 +16,7 @@
#include "services/media_session/media_session_service.h"
#include "services/media_session/public/cpp/media_metadata.h"
#include "services/media_session/public/cpp/test/mock_media_session.h"
+#include "services/media_session/public/cpp/test/test_media_controller.h"
#include "services/media_session/public/mojom/constants.mojom.h"
#include "services/service_manager/public/cpp/test/test_connector_factory.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -416,18 +417,18 @@ TEST_F(MediaControllerTest, ActiveController_Observer_StateTransition) {
}
{
- test::MockMediaSessionMojoObserver observer(controller());
+ test::TestMediaControllerObserver observer(controller());
observer.WaitForState(mojom::MediaSessionInfo::SessionState::kActive);
}
{
- test::MockMediaSessionMojoObserver observer(controller());
+ test::TestMediaControllerObserver observer(controller());
controller()->Suspend();
observer.WaitForState(mojom::MediaSessionInfo::SessionState::kSuspended);
}
{
- test::MockMediaSessionMojoObserver observer(controller());
+ test::TestMediaControllerObserver observer(controller());
RequestAudioFocus(media_session_2, mojom::AudioFocusType::kGain);
observer.WaitForState(mojom::MediaSessionInfo::SessionState::kActive);
}
@@ -439,7 +440,7 @@ TEST_F(MediaControllerTest, ActiveController_Observer_StateTransition) {
}
{
- test::MockMediaSessionMojoObserver observer(controller());
+ test::TestMediaControllerObserver observer(controller());
observer.WaitForState(mojom::MediaSessionInfo::SessionState::kActive);
}
}
@@ -523,8 +524,8 @@ TEST_F(MediaControllerTest, ActiveController_Metadata_Observer_Abandoned) {
media_session.AbandonAudioFocusFromClient();
{
- test::MockMediaSessionMojoObserver observer(controller());
- EXPECT_FALSE(observer.WaitForMetadata());
+ test::TestMediaControllerObserver observer(controller());
+ observer.WaitForEmptyMetadata();
}
}
@@ -541,9 +542,9 @@ TEST_F(MediaControllerTest, ActiveController_Metadata_Observer_Empty) {
}
{
- test::MockMediaSessionMojoObserver observer(controller());
+ test::TestMediaControllerObserver observer(controller());
media_session.SimulateMetadataChanged(test_metadata);
- EXPECT_EQ(test_metadata, observer.WaitForMetadata());
+ observer.WaitForEmptyMetadata();
}
}
@@ -565,9 +566,10 @@ TEST_F(MediaControllerTest, ActiveController_Metadata_Observer_WithInfo) {
}
{
- test::MockMediaSessionMojoObserver observer(controller());
+ test::TestMediaControllerObserver observer(controller());
media_session.SimulateMetadataChanged(test_metadata);
- EXPECT_EQ(metadata, observer.WaitForNonEmptyMetadata());
+ observer.WaitForNonEmptyMetadata();
+ EXPECT_EQ(metadata, observer.session_metadata());
}
}
@@ -586,8 +588,8 @@ TEST_F(MediaControllerTest, ActiveController_Metadata_AddObserver_Empty) {
media_session.SimulateMetadataChanged(test_metadata);
{
- test::MockMediaSessionMojoObserver observer(controller());
- EXPECT_EQ(test_metadata, observer.WaitForMetadata());
+ test::TestMediaControllerObserver observer(controller());
+ observer.WaitForEmptyMetadata();
}
}
@@ -611,8 +613,9 @@ TEST_F(MediaControllerTest, ActiveController_Metadata_AddObserver_WithInfo) {
media_session.SimulateMetadataChanged(test_metadata);
{
- test::MockMediaSessionMojoObserver observer(controller());
- EXPECT_EQ(metadata, *observer.WaitForMetadata());
+ test::TestMediaControllerObserver observer(controller());
+ observer.WaitForNonEmptyMetadata();
+ EXPECT_EQ(metadata, observer.session_metadata());
}
}
@@ -740,7 +743,7 @@ TEST_F(MediaControllerTest, ActiveController_Actions_AddObserver_Empty) {
}
{
- test::MockMediaSessionMojoObserver observer(controller());
+ test::TestMediaControllerObserver observer(controller());
observer.WaitForActions();
EXPECT_TRUE(observer.actions().empty());
}
@@ -759,7 +762,7 @@ TEST_F(MediaControllerTest, ActiveController_Actions_AddObserver_WithInfo) {
media_session.EnableAction(mojom::MediaSessionAction::kPlay);
{
- test::MockMediaSessionMojoObserver observer(controller());
+ test::TestMediaControllerObserver observer(controller());
observer.WaitForActions();
EXPECT_EQ(1u, observer.actions().size());
@@ -779,9 +782,7 @@ TEST_F(MediaControllerTest, ActiveController_Actions_Observer_Empty) {
}
{
- test::MockMediaSessionMojoObserver observer(controller());
- observer.WaitForActions();
-
+ test::TestMediaControllerObserver observer(controller());
media_session.DisableAction(mojom::MediaSessionAction::kPlay);
observer.WaitForActions();
@@ -800,9 +801,7 @@ TEST_F(MediaControllerTest, ActiveController_Actions_Observer_WithInfo) {
}
{
- test::MockMediaSessionMojoObserver observer(controller());
- observer.WaitForActions();
-
+ test::TestMediaControllerObserver observer(controller());
media_session.EnableAction(mojom::MediaSessionAction::kPlay);
observer.WaitForActions();
@@ -825,7 +824,54 @@ TEST_F(MediaControllerTest, ActiveController_Actions_Observer_Abandoned) {
media_session.AbandonAudioFocusFromClient();
{
- test::MockMediaSessionMojoObserver observer(controller());
+ test::TestMediaControllerObserver observer(controller());
+ observer.WaitForActions();
+ EXPECT_TRUE(observer.actions().empty());
+ }
+}
+
+TEST_F(MediaControllerTest, ActiveController_Observer_Abandoned) {
+ test::MockMediaSession media_session;
+ media_session.SetIsControllable(true);
+
+ {
+ test::MockMediaSessionMojoObserver observer(media_session);
+ RequestAudioFocus(media_session, mojom::AudioFocusType::kGain);
+ observer.WaitForState(mojom::MediaSessionInfo::SessionState::kActive);
+ }
+
+ {
+ test::TestMediaControllerObserver observer(controller());
+ media_session.AbandonAudioFocusFromClient();
+
+ // We should see empty info, metadata and actions flushed since the active
+ // controller is no longer bound to a media session.
+ observer.WaitForEmptyInfo();
+ observer.WaitForEmptyMetadata();
+ observer.WaitForActions();
+ EXPECT_TRUE(observer.actions().empty());
+ }
+}
+
+TEST_F(MediaControllerTest, ActiveController_AddObserver_Abandoned) {
+ test::MockMediaSession media_session;
+ media_session.SetIsControllable(true);
+
+ {
+ test::MockMediaSessionMojoObserver observer(media_session);
+ RequestAudioFocus(media_session, mojom::AudioFocusType::kGain);
+ observer.WaitForState(mojom::MediaSessionInfo::SessionState::kActive);
+ }
+
+ media_session.AbandonAudioFocusFromClient();
+
+ {
+ test::TestMediaControllerObserver observer(controller());
+
+ // We should see empty info, metadata and actions since the active
+ // controller is no longer bound to a media session.
+ observer.WaitForEmptyInfo();
+ observer.WaitForEmptyMetadata();
observer.WaitForActions();
EXPECT_TRUE(observer.actions().empty());
}
diff --git a/chromium/services/media_session/public/cpp/media_metadata.cc b/chromium/services/media_session/public/cpp/media_metadata.cc
index 0d07d04e874..42ed11b67fd 100644
--- a/chromium/services/media_session/public/cpp/media_metadata.cc
+++ b/chromium/services/media_session/public/cpp/media_metadata.cc
@@ -36,4 +36,9 @@ bool MediaMetadata::operator!=(const MediaMetadata& other) const {
return !(*this == other);
}
+bool MediaMetadata::IsEmpty() const {
+ return title.empty() && artist.empty() && album.empty() &&
+ source_title.empty() && artwork.empty();
+}
+
} // namespace media_session
diff --git a/chromium/services/media_session/public/cpp/media_metadata.h b/chromium/services/media_session/public/cpp/media_metadata.h
index 6716521c684..f209927ceb6 100644
--- a/chromium/services/media_session/public/cpp/media_metadata.h
+++ b/chromium/services/media_session/public/cpp/media_metadata.h
@@ -80,6 +80,9 @@ struct COMPONENT_EXPORT(MEDIA_SESSION_CPP) MediaMetadata {
// session. This could be the name of the app or the name of the site playing
// media.
base::string16 source_title;
+
+ // Returns whether |this| contains no metadata.
+ bool IsEmpty() const;
};
} // namespace media_session
diff --git a/chromium/services/media_session/public/mojom/media_controller.mojom b/chromium/services/media_session/public/mojom/media_controller.mojom
index 07a854b3966..2aa9af7b738 100644
--- a/chromium/services/media_session/public/mojom/media_controller.mojom
+++ b/chromium/services/media_session/public/mojom/media_controller.mojom
@@ -40,7 +40,7 @@ interface MediaController {
// Adds an observer that will forward events from the active media session.
// If the active session changes then observers do not need to be readded.
// Adding the observer will update the observer with the latest state.
- AddObserver(MediaSessionObserver observer);
+ AddObserver(MediaControllerObserver observer);
// Skip to the previous track. If there is no previous track then this will be
// a no-op.
@@ -57,3 +57,22 @@ interface MediaController {
// few seconds.
Seek(mojo_base.mojom.TimeDelta seek_time);
};
+
+// The observer for observing media controller events. This is different to a
+// MediaSessionObserver because a media controller can have nullable session
+// info which will be null if it is not bound to a media session. This would
+// be invalid for a media session because it must always have some state.
+interface MediaControllerObserver {
+ // Called when the state of the bound media session changes. If |info| is
+ // empty then the controller is no longer bound to a media session.
+ MediaSessionInfoChanged(MediaSessionInfo? info);
+
+ // Called when the bound media session has changed metadata. If |metadata|
+ // is null then it can be reset, e.g. the media that ws being played has
+ // been stopped.
+ MediaSessionMetadataChanged(MediaMetadata? metadata);
+
+ // Called when the bound media session action list has changed. This tells
+ // the observer which actions can be used to control the session.
+ MediaSessionActionsChanged(array<MediaSessionAction> action);
+};
diff --git a/chromium/services/network/mdns_responder.cc b/chromium/services/network/mdns_responder.cc
index f1f8c0220bd..a3aadf776d4 100644
--- a/chromium/services/network/mdns_responder.cc
+++ b/chromium/services/network/mdns_responder.cc
@@ -29,9 +29,7 @@
#include "net/dns/public/util.h"
#include "net/dns/record_parsed.h"
#include "net/dns/record_rdata.h"
-#include "net/socket/datagram_client_socket.h"
#include "net/socket/datagram_server_socket.h"
-#include "net/socket/udp_client_socket.h"
#include "net/socket/udp_server_socket.h"
// TODO(qingsi): Several features to implement:
@@ -76,34 +74,6 @@ const uint8_t kMaxMdnsResponseRetries = 2;
// Maximum delay allowed for per-response rate-limited responses.
const base::TimeDelta kMaxScheduledDelay = base::TimeDelta::FromSeconds(10);
-constexpr net::NetworkTrafficAnnotationTag kTrafficAnnotation =
- net::DefineNetworkTrafficAnnotation("mdns_responder", R"(
- semantics {
- sender: "mDNS Responder"
- description:
- "mDNS responder implements a multicast DNS responder as defined in "
- "RFC 6762."
- trigger:
- "Any network request that may require name registration or "
- "deregistration, and also mDNS queries for name resolution from "
- "the local network."
- data:
- "DNS records of type A, AAAA or NSEC for name registration or "
- "resolution."
- destination: OTHER
- destination_other:
- "mDNS responses are sent to the mDNS multicast groups within the "
- "subnets where the user resides."
- }
- policy {
- cookies_allowed: NO
- setting:
- "No setting for this feature. Individual usages may have their own "
- "disabling flags."
- policy_exception_justification:
- "This is core networking functionality on local networks."
- })");
-
class RandomUuidNameGenerator
: public network::MdnsResponderManager::NameGenerator {
public:
@@ -282,12 +252,11 @@ scoped_refptr<net::IOBufferWithSize> CreateNegativeResponse(
class MdnsResponderManager::SocketHandler {
public:
SocketHandler(uint16_t id,
- net::MDnsSendRecvSocketPair socket_pair,
+ std::unique_ptr<net::DatagramServerSocket> socket,
MdnsResponderManager* responder_manager)
: id_(id),
scheduler_(std::make_unique<ResponseScheduler>(this)),
- send_socket_(std::move(socket_pair.first)),
- recv_socket_(std::move(socket_pair.second)),
+ socket_(std::move(socket)),
responder_manager_(responder_manager),
io_buffer_(base::MakeRefCounted<net::IOBufferWithSize>(
net::dns_protocol::kMaxUDPSize + 1)),
@@ -296,17 +265,14 @@ class MdnsResponderManager::SocketHandler {
int Start() {
net::IPEndPoint end_point;
- int rv = recv_socket_->GetLocalAddress(&end_point);
- if (rv != net::OK)
+ int rv = socket_->GetLocalAddress(&end_point);
+ if (rv != net::OK) {
return rv;
- const net::AddressFamily af = end_point.GetFamily();
-#ifdef DEBUG
- DCHECK(af == net::ADDRESS_FAMILY_IPV4 || af == net::ADDRESS_FAMILY_IPV6);
- net::IPEndPoint send_socket_end_point;
- DCHECK(send_socket_->GetLocalAddress(&send_socket_end_point));
- DCHECK_EQ(af, send_socket_end_point.GetFamily());
-#endif
- multicast_addr_ = net::dns_util::GetMdnsGroupEndPoint(af);
+ }
+ DCHECK(end_point.GetFamily() == net::ADDRESS_FAMILY_IPV4 ||
+ end_point.GetFamily() == net::ADDRESS_FAMILY_IPV6);
+ multicast_addr_ =
+ net::dns_util::GetMdnsGroupEndPoint(end_point.GetFamily());
int result = DoReadLoop();
if (result == net::ERR_IO_PENDING) {
// An in-progress read loop is considered a completed start.
@@ -338,9 +304,9 @@ class MdnsResponderManager::SocketHandler {
int result;
do {
// Using base::Unretained(this) is safe because the CompletionOnceCallback
- // is automatically cancelled when |recv_socket_| is destroyed, and the
- // latter is owned by |this|.
- result = recv_socket_->RecvFrom(
+ // is automatically cancelled when |socket_| is destroyed, and the latter
+ // is owned by |this|.
+ result = socket_->RecvFrom(
io_buffer_.get(), io_buffer_->size(), &recv_addr_,
base::BindOnce(&MdnsResponderManager::SocketHandler::OnRead,
base::Unretained(this)));
@@ -366,8 +332,7 @@ class MdnsResponderManager::SocketHandler {
uint16_t id_;
std::unique_ptr<ResponseScheduler> scheduler_;
- std::unique_ptr<net::DatagramClientSocket> send_socket_;
- std::unique_ptr<net::DatagramServerSocket> recv_socket_;
+ std::unique_ptr<net::DatagramServerSocket> socket_;
// A back pointer to the responder manager that owns this socket handler. The
// handler should be destroyed before |responder_manager_| becomes invalid or
// a weak reference should be used to access the manager when there is no such
@@ -521,11 +486,10 @@ void MdnsResponderManager::SocketHandler::DoSend(
scoped_refptr<MdnsResponseSendOption> option) {
auto* buf_data = buf.get();
size_t buf_size = buf->size();
- send_socket_->Write(buf_data, buf_size,
- base::BindOnce(&ResponseScheduler::OnResponseSent,
- scheduler_->GetWeakPtr(), std::move(buf),
- std::move(option)),
- kTrafficAnnotation);
+ socket_->SendTo(buf_data, buf_size, multicast_addr_,
+ base::BindOnce(&ResponseScheduler::OnResponseSent,
+ scheduler_->GetWeakPtr(), std::move(buf),
+ std::move(option)));
}
void MdnsResponderManager::SocketHandler::SetTickClockForTesting(
@@ -654,16 +618,16 @@ void MdnsResponderManager::Start() {
VLOG(1) << "Starting mDNS responder manager.";
DCHECK(start_result_ == SocketHandlerStartResult::UNSPECIFIED);
DCHECK(socket_handler_by_id_.empty());
- std::vector<net::MDnsSendRecvSocketPair> socket_pairs;
+ std::vector<std::unique_ptr<net::DatagramServerSocket>> sockets;
// Create and return only bound sockets.
- socket_factory_->CreateSocketPairs(&socket_pairs);
+ socket_factory_->CreateSockets(&sockets);
uint16_t next_available_id = 1;
- for (auto& send_recv_sockets : socket_pairs) {
+ for (std::unique_ptr<net::DatagramServerSocket>& socket : sockets) {
socket_handler_by_id_.emplace(
next_available_id,
std::make_unique<MdnsResponderManager::SocketHandler>(
- next_available_id, std::move(send_recv_sockets), this));
+ next_available_id, std::move(socket), this));
++next_available_id;
}
@@ -682,7 +646,7 @@ void MdnsResponderManager::Start() {
size_t num_started_socket_handlers = socket_handler_by_id_.size();
if (socket_handler_by_id_.empty()) {
start_result_ = SocketHandlerStartResult::ALL_FAILURE;
- LOG(ERROR) << "mDNS responder manager failed to start.";
+ LOG(ERROR) << "mDNS responder manager failed to started.";
return;
}
diff --git a/chromium/services/network/mdns_responder_unittest.cc b/chromium/services/network/mdns_responder_unittest.cc
index e324d07b333..f77370c54df 100644
--- a/chromium/services/network/mdns_responder_unittest.cc
+++ b/chromium/services/network/mdns_responder_unittest.cc
@@ -79,23 +79,22 @@ class MockFailingMdnsSocketFactory : public net::MDnsSocketFactory {
~MockFailingMdnsSocketFactory() override = default;
- MOCK_METHOD1(CreateSocketPairs,
- void(std::vector<net::MDnsSendRecvSocketPair>*));
+ MOCK_METHOD1(CreateSockets,
+ void(std::vector<std::unique_ptr<net::DatagramServerSocket>>*));
MOCK_METHOD1(OnSendTo, void(const std::string&));
// Emulates the asynchronous contract of invoking |callback| in the SendTo
// primitive but failed sending;
int FailToSend(const std::string& packet,
- net::CompletionOnceCallback* callback,
- const net::NetworkTrafficAnnotationTag& traffic_annotation) {
+ const std::string& address,
+ net::CompletionRepeatingCallback callback) {
OnSendTo(packet);
- task_runner_->PostTask(FROM_HERE,
- base::BindOnce(
- [](net::CompletionOnceCallback callback) {
- std::move(callback).Run(-1);
- },
- std::move(*callback)));
+ task_runner_->PostTask(
+ FROM_HERE,
+ base::BindOnce(
+ [](net::CompletionRepeatingCallback callback) { callback.Run(-1); },
+ callback));
return -1;
}
@@ -104,13 +103,12 @@ class MockFailingMdnsSocketFactory : public net::MDnsSocketFactory {
int FailToRecv(net::IOBuffer* buffer,
int size,
net::IPEndPoint* address,
- net::CompletionOnceCallback* callback) {
- task_runner_->PostTask(FROM_HERE,
- base::BindOnce(
- [](net::CompletionOnceCallback callback) {
- std::move(callback).Run(-1);
- },
- std::move(*callback)));
+ net::CompletionRepeatingCallback callback) {
+ task_runner_->PostTask(
+ FROM_HERE,
+ base::BindOnce(
+ [](net::CompletionRepeatingCallback callback) { callback.Run(-1); },
+ callback));
return -1;
}
@@ -613,7 +611,7 @@ TEST_F(MdnsResponderTest, ResponderHostDoesCleanUpAfterMojoConnectionError) {
// Test that the host generates a Mojo connection error when no socket handler
// is successfully started.
TEST_F(MdnsResponderTest, ClosesBindingWhenNoSocketHanlderStarted) {
- EXPECT_CALL(failing_socket_factory_, CreateSocketPairs(_)).WillOnce(Return());
+ EXPECT_CALL(failing_socket_factory_, CreateSockets(_)).WillOnce(Return());
Reset(true /* use_failing_socket_factory */);
RunUntilNoTasksRemain();
// MdnsResponderTest::OnMojoConnectionError.
@@ -624,30 +622,26 @@ TEST_F(MdnsResponderTest, ClosesBindingWhenNoSocketHanlderStarted) {
// Test that an announcement is retried after send failure.
TEST_F(MdnsResponderTest, AnnouncementRetriedAfterSendFailure) {
auto create_send_failing_socket =
- [this](std::vector<net::MDnsSendRecvSocketPair>* socket_pairs) {
- auto send_socket =
- std::make_unique<NiceMock<net::MockMDnsDatagramClientSocket>>();
-
- auto recv_socket =
+ [this](std::vector<std::unique_ptr<net::DatagramServerSocket>>* sockets) {
+ auto socket =
std::make_unique<NiceMock<net::MockMDnsDatagramServerSocket>>(
net::ADDRESS_FAMILY_IPV4);
- ON_CALL(*send_socket, WriteInternal(_, _, _))
+ ON_CALL(*socket, SendToInternal(_, _, _))
.WillByDefault(Invoke(&failing_socket_factory_,
&MockFailingMdnsSocketFactory::FailToSend));
- ON_CALL(*recv_socket, RecvFromInternal(_, _, _, _))
+ ON_CALL(*socket, RecvFromInternal(_, _, _, _))
.WillByDefault(Return(-1));
- socket_pairs->push_back(
- std::make_pair(std::move(send_socket), std::move(recv_socket)));
+ sockets->push_back(std::move(socket));
};
- EXPECT_CALL(failing_socket_factory_, CreateSocketPairs(_))
+ EXPECT_CALL(failing_socket_factory_, CreateSockets(_))
.WillOnce(Invoke(create_send_failing_socket));
Reset(true /* use_failing_socket_factory */);
const auto& addr = kPublicAddrs[0];
std::string expected_announcement =
CreateResolutionResponse(kDefaultTtl, {{"0.local", addr}});
- // Mocked CreateSocketPairs above only creates one pair of sockets.
+ // Mocked CreateSockets above only creates one socket.
EXPECT_CALL(failing_socket_factory_, OnSendTo(expected_announcement))
.Times(kNumAnnouncementsPerInterface + kNumMaxRetriesPerResponse);
const auto name = CreateNameForAddress(0, addr);
@@ -973,25 +967,22 @@ TEST_F(MdnsResponderTest, ScheduledSendsAreCancelledAfterManagerDestroyed) {
// Test that if all socket handlers fail to read, the manager restarts itself.
TEST_F(MdnsResponderTest, ManagerCanRestartAfterAllSocketHandlersFailToRead) {
auto create_read_failing_socket =
- [this](std::vector<net::MDnsSendRecvSocketPair>* socket_pairs) {
- auto send_socket =
- std::make_unique<NiceMock<net::MockMDnsDatagramClientSocket>>();
- auto recv_socket =
+ [this](std::vector<std::unique_ptr<net::DatagramServerSocket>>* sockets) {
+ auto socket =
std::make_unique<NiceMock<net::MockMDnsDatagramServerSocket>>(
net::ADDRESS_FAMILY_IPV4);
- ON_CALL(*send_socket, WriteInternal(_, _, _)).WillByDefault(Return(0));
- ON_CALL(*recv_socket, RecvFromInternal(_, _, _, _))
+ ON_CALL(*socket, SendToInternal(_, _, _)).WillByDefault(Return(0));
+ ON_CALL(*socket, RecvFromInternal(_, _, _, _))
.WillByDefault(Invoke(&failing_socket_factory_,
&MockFailingMdnsSocketFactory::FailToRecv));
- socket_pairs->push_back(
- std::make_pair(std::move(send_socket), std::move(recv_socket)));
+ sockets->push_back(std::move(socket));
};
- EXPECT_CALL(failing_socket_factory_, CreateSocketPairs(_))
+ EXPECT_CALL(failing_socket_factory_, CreateSockets(_))
.WillOnce(Invoke(create_read_failing_socket));
Reset(true /* use_failing_socket_factory */);
- EXPECT_CALL(failing_socket_factory_, CreateSocketPairs(_)).Times(1);
+ EXPECT_CALL(failing_socket_factory_, CreateSockets(_)).Times(1);
RunUntilNoTasksRemain();
}
diff --git a/chromium/services/network/network_service.cc b/chromium/services/network/network_service.cc
index ffa129c237e..15cfd697779 100644
--- a/chromium/services/network/network_service.cc
+++ b/chromium/services/network/network_service.cc
@@ -10,6 +10,7 @@
#include "base/bind.h"
#include "base/command_line.h"
+#include "base/environment.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
@@ -261,6 +262,9 @@ void NetworkService::Initialize(mojom::NetworkServiceParamsPtr params) {
CRYPTO_needs_hwcap2_workaround());
#endif
+ if (!params->environment.empty())
+ SetEnvironment(std::move(params->environment));
+
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
// Set-up the global port overrides.
@@ -323,7 +327,9 @@ NetworkService::~NetworkService() {
file_net_log_observer_->StopObserving(nullptr /*polled_data*/,
base::OnceClosure());
}
- trace_net_log_observer_.StopWatchForTraceStart();
+
+ if (initialized_)
+ trace_net_log_observer_.StopWatchForTraceStart();
}
void NetworkService::set_os_crypt_is_configured() {
@@ -644,6 +650,13 @@ void NetworkService::OnApplicationStateChange(
}
#endif
+void NetworkService::SetEnvironment(
+ std::vector<mojom::EnvironmentVariablePtr> environment) {
+ std::unique_ptr<base::Environment> env(base::Environment::Create());
+ for (const auto& variable : environment)
+ env->SetVar(variable->name, variable->value);
+}
+
net::HttpAuthHandlerFactory* NetworkService::GetHttpAuthHandlerFactory() {
if (!http_auth_handler_factory_) {
http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault(
@@ -692,8 +705,10 @@ void NetworkService::DestroyNetworkContexts() {
// The SetDnsConfigOverrides() call will will fail any in-progress DNS
// lookups, but only if there are current config overrides (which there will
// be if DNS over HTTPS is currently enabled).
- host_resolver_->SetDnsConfigOverrides(net::DnsConfigOverrides());
- host_resolver_->SetRequestContext(nullptr);
+ if (host_resolver_) {
+ host_resolver_->SetDnsConfigOverrides(net::DnsConfigOverrides());
+ host_resolver_->SetRequestContext(nullptr);
+ }
DCHECK_LE(owned_network_contexts_.size(), 1u);
owned_network_contexts_.clear();
diff --git a/chromium/services/network/network_service.h b/chromium/services/network/network_service.h
index a04970001c2..b92827ce610 100644
--- a/chromium/services/network/network_service.h
+++ b/chromium/services/network/network_service.h
@@ -199,6 +199,8 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) NetworkService
#if defined(OS_ANDROID)
void OnApplicationStateChange(base::android::ApplicationState state) override;
#endif
+ void SetEnvironment(
+ std::vector<mojom::EnvironmentVariablePtr> environment) override;
// Returns the shared HttpAuthHandlerFactory for the NetworkService, creating
// one if needed.
diff --git a/chromium/services/network/public/mojom/network_service.mojom b/chromium/services/network/public/mojom/network_service.mojom
index a025436d949..ccccb45b34b 100644
--- a/chromium/services/network/public/mojom/network_service.mojom
+++ b/chromium/services/network/public/mojom/network_service.mojom
@@ -235,10 +235,20 @@ struct CryptConfig {
mojo_base.mojom.FilePath user_data_path;
};
+// Represents the value of a single environment variable.
+struct EnvironmentVariable {
+ string name;
+ string value;
+};
+
// Parameters needed to initialize the network service.
struct NetworkServiceParams {
ConnectionType initial_connection_type = CONNECTION_UNKNOWN;
ConnectionSubtype initial_connection_subtype = SUBTYPE_UNKNOWN;
+
+ // A set of environment variables that should be set in the network
+ // service when starting up.
+ array<EnvironmentVariable> environment;
};
// Browser interface to the network service.
@@ -381,4 +391,9 @@ interface NetworkService {
// Called on state changes of the Android application.
[EnableIf=is_android]
OnApplicationStateChange(mojo_base.mojom.ApplicationState state);
+
+ // Sets the given environment variables in the network service's process.
+ // This method won't modify variables that aren't present in the
+ // |environment| array.
+ SetEnvironment(array<EnvironmentVariable> environment);
};
diff --git a/chromium/services/tracing/public/cpp/traced_process_impl.cc b/chromium/services/tracing/public/cpp/traced_process_impl.cc
index e380d010dbc..7ae592a41fe 100644
--- a/chromium/services/tracing/public/cpp/traced_process_impl.cc
+++ b/chromium/services/tracing/public/cpp/traced_process_impl.cc
@@ -105,4 +105,10 @@ void TracedProcessImpl::ConnectToTracingService(
tracing::mojom::PerfettoServicePtr(std::move(request->perfetto_service)));
}
+void TracedProcessImpl::GetCategories(std::set<std::string>* category_set) {
+ for (auto* agent : agents_) {
+ agent->GetCategories(category_set);
+ }
+}
+
} // namespace tracing
diff --git a/chromium/services/tracing/public/cpp/traced_process_impl.h b/chromium/services/tracing/public/cpp/traced_process_impl.h
index 1522fdf9bf6..5d7a503a69b 100644
--- a/chromium/services/tracing/public/cpp/traced_process_impl.h
+++ b/chromium/services/tracing/public/cpp/traced_process_impl.h
@@ -35,6 +35,9 @@ class COMPONENT_EXPORT(TRACING_CPP) TracedProcessImpl
void RegisterAgent(BaseAgent* agent);
void UnregisterAgent(BaseAgent* agent);
+ // Populate categories from all of the registered agents.
+ void GetCategories(std::set<std::string>* category_set);
+
private:
friend class base::NoDestructor<TracedProcessImpl>;
TracedProcessImpl();