summaryrefslogtreecommitdiff
path: root/chromium/components/cryptauth
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/components/cryptauth')
-rw-r--r--chromium/components/cryptauth/BUILD.gn4
-rw-r--r--chromium/components/cryptauth/OWNERS2
-rw-r--r--chromium/components/cryptauth/ble/OWNERS2
-rw-r--r--chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.cc2
-rw-r--r--chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.h3
-rw-r--r--chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection_unittest.cc46
-rw-r--r--chromium/components/cryptauth/bluetooth_throttler_impl.cc10
-rw-r--r--chromium/components/cryptauth/bluetooth_throttler_impl.h13
-rw-r--r--chromium/components/cryptauth/cryptauth_device_manager_unittest.cc12
-rw-r--r--chromium/components/cryptauth/cryptauth_enrollment_manager.h4
-rw-r--r--chromium/components/cryptauth/cryptauth_enrollment_manager_unittest.cc11
-rw-r--r--chromium/components/cryptauth/cryptauth_service.cc20
-rw-r--r--chromium/components/cryptauth/cryptauth_service.h45
-rw-r--r--chromium/components/cryptauth/fake_cryptauth_service.cc46
-rw-r--r--chromium/components/cryptauth/fake_cryptauth_service.h65
-rw-r--r--chromium/components/cryptauth/fake_secure_channel.cc4
-rw-r--r--chromium/components/cryptauth/fake_secure_channel.h4
-rw-r--r--chromium/components/cryptauth/secure_channel.cc22
-rw-r--r--chromium/components/cryptauth/secure_channel.h18
-rw-r--r--chromium/components/cryptauth/secure_channel_unittest.cc33
20 files changed, 293 insertions, 73 deletions
diff --git a/chromium/components/cryptauth/BUILD.gn b/chromium/components/cryptauth/BUILD.gn
index 01954c46c65..103beaa64e8 100644
--- a/chromium/components/cryptauth/BUILD.gn
+++ b/chromium/components/cryptauth/BUILD.gn
@@ -36,6 +36,8 @@ static_library("cryptauth") {
"cryptauth_gcm_manager.h",
"cryptauth_gcm_manager_impl.cc",
"cryptauth_gcm_manager_impl.h",
+ "cryptauth_service.cc",
+ "cryptauth_service.h",
"device_to_device_authenticator.cc",
"device_to_device_authenticator.h",
"device_to_device_initiator_operations.cc",
@@ -101,6 +103,8 @@ static_library("test_support") {
"fake_connection.h",
"fake_cryptauth_gcm_manager.cc",
"fake_cryptauth_gcm_manager.h",
+ "fake_cryptauth_service.cc",
+ "fake_cryptauth_service.h",
"fake_secure_channel.cc",
"fake_secure_channel.h",
"fake_secure_context.cc",
diff --git a/chromium/components/cryptauth/OWNERS b/chromium/components/cryptauth/OWNERS
index b330adf2413..238e06011df 100644
--- a/chromium/components/cryptauth/OWNERS
+++ b/chromium/components/cryptauth/OWNERS
@@ -3,3 +3,5 @@ tengs@chromium.org
xiyuan@chromium.org
khorimoto@chromium.org
hansberry@chromium.org
+
+# COMPONENT: UI>ProximityAuth
diff --git a/chromium/components/cryptauth/ble/OWNERS b/chromium/components/cryptauth/ble/OWNERS
index 067b4517ba4..5694d5144b0 100644
--- a/chromium/components/cryptauth/ble/OWNERS
+++ b/chromium/components/cryptauth/ble/OWNERS
@@ -3,3 +3,5 @@ sacomoto@chromium.org
tengs@chromium.org
khorimoto@chromium.org
hansberry@chromium.org
+
+# COMPONENT: UI>ProximityAuth
diff --git a/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.cc b/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.cc
index 8afc502b91d..42351b9e6a6 100644
--- a/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.cc
+++ b/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.cc
@@ -508,7 +508,7 @@ void BluetoothLowEnergyWeaveClientConnection::OnRemoteCharacteristicWritten() {
break;
case WriteRequestType::CONNECTION_CLOSE:
DestroyConnection();
- break;
+ return;
default:
NOTREACHED();
}
diff --git a/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.h b/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.h
index ec8dfac0ee2..c77c894ab53 100644
--- a/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.h
+++ b/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection.h
@@ -112,6 +112,9 @@ class BluetoothLowEnergyWeaveClientConnection
protected:
// Exposed for testing.
+ // NOTE: This method may indirectly cause this object's destructor to be
+ // called. Do not perform any operations that touch the internals of this
+ // class after calling this method.
void DestroyConnection();
// Exposed for testing.
diff --git a/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection_unittest.cc b/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection_unittest.cc
index a2f1ead19d8..cf84e960bc2 100644
--- a/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection_unittest.cc
+++ b/chromium/components/cryptauth/ble/bluetooth_low_energy_weave_client_connection_unittest.cc
@@ -66,11 +66,15 @@ class MockBluetoothLowEnergyCharacteristicsFinder
class MockConnectionObserver : public ConnectionObserver {
public:
- MockConnectionObserver() : num_send_completed_(0) {}
+ MockConnectionObserver()
+ : num_send_completed_(0), delete_on_disconnect_(false) {}
void OnConnectionStatusChanged(Connection* connection,
Connection::Status old_status,
- Connection::Status new_status) override {}
+ Connection::Status new_status) override {
+ if (new_status == Connection::Status::DISCONNECTED && delete_on_disconnect_)
+ delete connection;
+ }
void OnMessageReceived(const Connection& connection,
const WireMessage& message) override {}
@@ -91,10 +95,16 @@ class MockConnectionObserver : public ConnectionObserver {
int GetNumSendCompleted() { return num_send_completed_; }
+ bool delete_on_disconnect() { return delete_on_disconnect_; }
+ void set_delete_on_disconnect(bool delete_on_disconnect) {
+ delete_on_disconnect_ = delete_on_disconnect;
+ }
+
private:
std::string last_deserialized_message_;
bool last_send_success_;
int num_send_completed_;
+ bool delete_on_disconnect_;
};
} // namespace
@@ -735,7 +745,7 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
NotifySessionStarted(connection.get());
// |connection| will call WriteRemoteCharacteristics(_,_) to try to send the
- // message |kMaxNumberOfTries| times. There is alredy one EXPECTA_CALL for
+ // message |kMaxNumberOfTries| times. There is alredy one EXPECT_CALL for
// WriteRemoteCharacteristic(_,_,_) in NotifySessionStated, that's why we use
// |kMaxNumberOfTries-1| in the EXPECT_CALL statement.
EXPECT_EQ(0, connection_observer_.GetNumSendCompleted());
@@ -980,6 +990,36 @@ TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
EXPECT_EQ(connection->status(), Connection::DISCONNECTED);
}
+// Test for fix to crbug.com/708744. Without the fix, this test will crash.
+TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
+ ReceiverErrorAndConnectionDeletedTest) {
+ connection_observer_.set_delete_on_disconnect(true);
+
+ TestBluetoothLowEnergyWeaveClientConnection* connection =
+ CreateConnection().release();
+
+ InitializeConnection(connection, kDefaultMaxPacketSize);
+
+ EXPECT_CALL(*tx_characteristic_, WriteRemoteCharacteristic(_, _, _))
+ .WillOnce(
+ DoAll(SaveArg<0>(&last_value_written_on_tx_characteristic_),
+ SaveArg<1>(&write_remote_characteristic_success_callback_),
+ SaveArg<2>(&write_remote_characteristic_error_callback_)));
+
+ connection->GattCharacteristicValueChanged(
+ adapter_.get(), rx_characteristic_.get(), kErroneousPacket);
+
+ EXPECT_EQ(last_value_written_on_tx_characteristic_,
+ kConnectionCloseApplicationError);
+ EXPECT_EQ(receiver_factory_->GetMostRecentInstance()->GetReasonToClose(),
+ ReasonForClose::APPLICATION_ERROR);
+
+ RunWriteCharacteristicSuccessCallback();
+
+ // We cannot check if connection's status and sub_status are DISCONNECTED
+ // because it has been deleted.
+}
+
TEST_F(CryptAuthBluetoothLowEnergyWeaveClientConnectionTest,
WriteConnectionCloseMaxNumberOfTimes) {
std::unique_ptr<TestBluetoothLowEnergyWeaveClientConnection> connection(
diff --git a/chromium/components/cryptauth/bluetooth_throttler_impl.cc b/chromium/components/cryptauth/bluetooth_throttler_impl.cc
index d72337ef593..239528a8632 100644
--- a/chromium/components/cryptauth/bluetooth_throttler_impl.cc
+++ b/chromium/components/cryptauth/bluetooth_throttler_impl.cc
@@ -6,7 +6,9 @@
#include <utility>
+#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
+#include "base/time/default_tick_clock.h"
#include "base/time/tick_clock.h"
#include "components/cryptauth/connection.h"
@@ -18,6 +20,14 @@ const int kCooldownTimeSecs = 7;
} // namespace
+// static
+BluetoothThrottlerImpl* BluetoothThrottlerImpl::GetInstance() {
+ return base::Singleton<BluetoothThrottlerImpl>::get();
+}
+
+BluetoothThrottlerImpl::BluetoothThrottlerImpl()
+ : BluetoothThrottlerImpl(base::MakeUnique<base::DefaultTickClock>()) {}
+
BluetoothThrottlerImpl::BluetoothThrottlerImpl(
std::unique_ptr<base::TickClock> clock)
: clock_(std::move(clock)) {}
diff --git a/chromium/components/cryptauth/bluetooth_throttler_impl.h b/chromium/components/cryptauth/bluetooth_throttler_impl.h
index 2933f168119..7a9fef028f0 100644
--- a/chromium/components/cryptauth/bluetooth_throttler_impl.h
+++ b/chromium/components/cryptauth/bluetooth_throttler_impl.h
@@ -9,6 +9,7 @@
#include <set>
#include "base/macros.h"
+#include "base/memory/singleton.h"
#include "base/time/time.h"
#include "components/cryptauth/bluetooth_throttler.h"
#include "components/cryptauth/connection_observer.h"
@@ -28,9 +29,7 @@ class Connection;
class BluetoothThrottlerImpl : public BluetoothThrottler,
public ConnectionObserver {
public:
- // Creates a throttler for connections to a remote device, using the |clock|
- // as a time source.
- explicit BluetoothThrottlerImpl(std::unique_ptr<base::TickClock> clock);
+ static BluetoothThrottlerImpl* GetInstance();
~BluetoothThrottlerImpl() override;
// BluetoothThrottler:
@@ -38,11 +37,19 @@ class BluetoothThrottlerImpl : public BluetoothThrottler,
void OnConnection(Connection* connection) override;
protected:
+ // Creates a throttler for connections to a remote device, using the |clock|
+ // as a time source.
+ explicit BluetoothThrottlerImpl(std::unique_ptr<base::TickClock> clock);
+
// Returns the duration to wait, after disconnecting, before reattempting a
// connection to the remote device. Exposed for testing.
base::TimeDelta GetCooldownTimeDelta() const;
private:
+ friend struct base::DefaultSingletonTraits<BluetoothThrottlerImpl>;
+
+ BluetoothThrottlerImpl();
+
// ConnectionObserver:
void OnConnectionStatusChanged(Connection* connection,
Connection::Status old_status,
diff --git a/chromium/components/cryptauth/cryptauth_device_manager_unittest.cc b/chromium/components/cryptauth/cryptauth_device_manager_unittest.cc
index 6c6af53928a..7dcd284349e 100644
--- a/chromium/components/cryptauth/cryptauth_device_manager_unittest.cc
+++ b/chromium/components/cryptauth/cryptauth_device_manager_unittest.cc
@@ -383,11 +383,13 @@ class CryptAuthDeviceManagerTest
CryptAuthDeviceManager::RegisterPrefs(pref_service_.registry());
pref_service_.SetUserPref(
prefs::kCryptAuthDeviceSyncIsRecoveringFromFailure,
- new base::Value(false));
- pref_service_.SetUserPref(prefs::kCryptAuthDeviceSyncLastSyncTimeSeconds,
- new base::Value(kLastSyncTimeSeconds));
- pref_service_.SetUserPref(prefs::kCryptAuthDeviceSyncReason,
- new base::Value(INVOCATION_REASON_UNKNOWN));
+ base::MakeUnique<base::Value>(false));
+ pref_service_.SetUserPref(
+ prefs::kCryptAuthDeviceSyncLastSyncTimeSeconds,
+ base::MakeUnique<base::Value>(kLastSyncTimeSeconds));
+ pref_service_.SetUserPref(
+ prefs::kCryptAuthDeviceSyncReason,
+ base::MakeUnique<base::Value>(INVOCATION_REASON_UNKNOWN));
std::unique_ptr<base::DictionaryValue> device_dictionary(
new base::DictionaryValue());
diff --git a/chromium/components/cryptauth/cryptauth_enrollment_manager.h b/chromium/components/cryptauth/cryptauth_enrollment_manager.h
index e621b9f5b4e..ce4c9da774d 100644
--- a/chromium/components/cryptauth/cryptauth_enrollment_manager.h
+++ b/chromium/components/cryptauth/cryptauth_enrollment_manager.h
@@ -112,8 +112,8 @@ class CryptAuthEnrollmentManager : public SyncScheduler::Delegate,
// been completed, then an empty string will be returned.
// Note: These keys are really serialized protocol buffer messages, and should
// only be used by passing to SecureMessageDelegate.
- std::string GetUserPublicKey() const;
- std::string GetUserPrivateKey() const;
+ virtual std::string GetUserPublicKey() const;
+ virtual std::string GetUserPrivateKey() const;
protected:
// Creates a new SyncScheduler instance. Exposed for testing.
diff --git a/chromium/components/cryptauth/cryptauth_enrollment_manager_unittest.cc b/chromium/components/cryptauth/cryptauth_enrollment_manager_unittest.cc
index ccb12c18f6f..7a98f86d8e4 100644
--- a/chromium/components/cryptauth/cryptauth_enrollment_manager_unittest.cc
+++ b/chromium/components/cryptauth/cryptauth_enrollment_manager_unittest.cc
@@ -170,12 +170,13 @@ class CryptAuthEnrollmentManagerTest
CryptAuthEnrollmentManager::RegisterPrefs(pref_service_.registry());
pref_service_.SetUserPref(
prefs::kCryptAuthEnrollmentIsRecoveringFromFailure,
- new base::Value(false));
+ base::MakeUnique<base::Value>(false));
pref_service_.SetUserPref(
prefs::kCryptAuthEnrollmentLastEnrollmentTimeSeconds,
- new base::Value(kLastEnrollmentTimeSeconds));
- pref_service_.SetUserPref(prefs::kCryptAuthEnrollmentReason,
- new base::Value(INVOCATION_REASON_UNKNOWN));
+ base::MakeUnique<base::Value>(kLastEnrollmentTimeSeconds));
+ pref_service_.SetUserPref(
+ prefs::kCryptAuthEnrollmentReason,
+ base::MakeUnique<base::Value>(INVOCATION_REASON_UNKNOWN));
std::string public_key_b64, private_key_b64;
base::Base64UrlEncode(public_key_,
@@ -335,7 +336,7 @@ TEST_F(CryptAuthEnrollmentManagerTest, InitWithExistingPrefs) {
TEST_F(CryptAuthEnrollmentManagerTest, InitWithExpiredEnrollment) {
pref_service_.SetUserPref(
prefs::kCryptAuthEnrollmentLastEnrollmentTimeSeconds,
- new base::Value(kLastExpiredEnrollmentTimeSeconds));
+ base::MakeUnique<base::Value>(kLastExpiredEnrollmentTimeSeconds));
EXPECT_CALL(*sync_scheduler(),
Start(clock_->Now() - base::Time::FromDoubleT(
diff --git a/chromium/components/cryptauth/cryptauth_service.cc b/chromium/components/cryptauth/cryptauth_service.cc
new file mode 100644
index 00000000000..806516b4668
--- /dev/null
+++ b/chromium/components/cryptauth/cryptauth_service.cc
@@ -0,0 +1,20 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/cryptauth/cryptauth_service.h"
+
+#include "components/cryptauth/cryptauth_device_manager.h"
+#include "components/cryptauth/cryptauth_enrollment_manager.h"
+#include "components/cryptauth/cryptauth_gcm_manager.h"
+
+namespace cryptauth {
+
+// static
+void CryptAuthService::RegisterProfilePrefs(PrefRegistrySimple* registry) {
+ CryptAuthGCMManager::RegisterPrefs(registry);
+ CryptAuthDeviceManager::RegisterPrefs(registry);
+ CryptAuthEnrollmentManager::RegisterPrefs(registry);
+}
+
+} // namespace cryptauth
diff --git a/chromium/components/cryptauth/cryptauth_service.h b/chromium/components/cryptauth/cryptauth_service.h
new file mode 100644
index 00000000000..ebfc41549db
--- /dev/null
+++ b/chromium/components/cryptauth/cryptauth_service.h
@@ -0,0 +1,45 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_CRYPTAUTH_CRYPTAUTH_SERVICE_H_
+#define COMPONENTS_CRYPTAUTH_CRYPTAUTH_SERVICE_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "components/cryptauth/proto/cryptauth_api.pb.h"
+#include "components/prefs/pref_registry_simple.h"
+
+namespace cryptauth {
+
+class CryptAuthClientFactory;
+class CryptAuthDeviceManager;
+class CryptAuthEnrollmentManager;
+class SecureMessageDelegate;
+
+// Service which provides access to various CryptAuth singletons.
+class CryptAuthService {
+ public:
+ static void RegisterProfilePrefs(PrefRegistrySimple* registry);
+
+ virtual CryptAuthDeviceManager* GetCryptAuthDeviceManager() = 0;
+ virtual CryptAuthEnrollmentManager* GetCryptAuthEnrollmentManager() = 0;
+ virtual DeviceClassifier GetDeviceClassifier() = 0;
+ virtual std::string GetAccountId() = 0;
+ virtual std::unique_ptr<SecureMessageDelegate>
+ CreateSecureMessageDelegate() = 0;
+ virtual std::unique_ptr<CryptAuthClientFactory>
+ CreateCryptAuthClientFactory() = 0;
+
+ protected:
+ CryptAuthService() {}
+ virtual ~CryptAuthService() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CryptAuthService);
+};
+
+} // namespace cryptauth
+
+#endif // COMPONENTS_CRYPTAUTH_CRYPTAUTH_SERVICE_H_
diff --git a/chromium/components/cryptauth/fake_cryptauth_service.cc b/chromium/components/cryptauth/fake_cryptauth_service.cc
new file mode 100644
index 00000000000..93b9113cc42
--- /dev/null
+++ b/chromium/components/cryptauth/fake_cryptauth_service.cc
@@ -0,0 +1,46 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/cryptauth/fake_cryptauth_service.h"
+
+#include "base/callback.h"
+#include "base/memory/ptr_util.h"
+#include "components/cryptauth/fake_secure_message_delegate.h"
+#include "components/cryptauth/mock_cryptauth_client.h"
+
+namespace cryptauth {
+
+FakeCryptAuthService::FakeCryptAuthService() {}
+
+FakeCryptAuthService::~FakeCryptAuthService() {}
+
+CryptAuthDeviceManager* FakeCryptAuthService::GetCryptAuthDeviceManager() {
+ return cryptauth_device_manager_;
+}
+
+CryptAuthEnrollmentManager*
+FakeCryptAuthService::GetCryptAuthEnrollmentManager() {
+ return cryptauth_enrollment_manager_;
+}
+
+DeviceClassifier FakeCryptAuthService::GetDeviceClassifier() {
+ return device_classifier_;
+}
+
+std::string FakeCryptAuthService::GetAccountId() {
+ return account_id_;
+}
+
+std::unique_ptr<SecureMessageDelegate>
+FakeCryptAuthService::CreateSecureMessageDelegate() {
+ return base::MakeUnique<FakeSecureMessageDelegate>();
+}
+
+std::unique_ptr<CryptAuthClientFactory>
+FakeCryptAuthService::CreateCryptAuthClientFactory() {
+ return base::MakeUnique<MockCryptAuthClientFactory>(
+ MockCryptAuthClientFactory::MockType::MAKE_NICE_MOCKS);
+}
+
+} // namespace cryptauth
diff --git a/chromium/components/cryptauth/fake_cryptauth_service.h b/chromium/components/cryptauth/fake_cryptauth_service.h
new file mode 100644
index 00000000000..ba5ac1777f9
--- /dev/null
+++ b/chromium/components/cryptauth/fake_cryptauth_service.h
@@ -0,0 +1,65 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_CRYPTAUTH_FAKE_CRYPTAUTH_SERVICE_H_
+#define COMPONENTS_CRYPTAUTH_FAKE_CRYPTAUTH_SERVICE_H_
+
+#include <memory>
+
+#include "base/macros.h"
+#include "components/cryptauth/cryptauth_service.h"
+#include "components/cryptauth/proto/cryptauth_api.pb.h"
+
+namespace cryptauth {
+
+class CryptAuthClientFactory;
+class CryptAuthDeviceManager;
+class CryptAuthEnrollmentManager;
+class SecureMessageDelegate;
+
+// Service which provides access to various CryptAuth singletons.
+class FakeCryptAuthService : public CryptAuthService {
+ public:
+ FakeCryptAuthService();
+ ~FakeCryptAuthService() override;
+
+ void set_cryptauth_device_manager(
+ CryptAuthDeviceManager* cryptauth_device_manager) {
+ cryptauth_device_manager_ = cryptauth_device_manager;
+ }
+
+ void set_cryptauth_enrollment_manager(
+ CryptAuthEnrollmentManager* cryptauth_enrollment_manager) {
+ cryptauth_enrollment_manager_ = cryptauth_enrollment_manager;
+ }
+
+ void set_device_classifier(const DeviceClassifier& device_classifier) {
+ device_classifier_ = device_classifier;
+ }
+
+ void set_account_id(const std::string& account_id) {
+ account_id_ = account_id;
+ }
+
+ // CryptAuthService:
+ CryptAuthDeviceManager* GetCryptAuthDeviceManager() override;
+ CryptAuthEnrollmentManager* GetCryptAuthEnrollmentManager() override;
+ DeviceClassifier GetDeviceClassifier() override;
+ std::string GetAccountId() override;
+ std::unique_ptr<SecureMessageDelegate> CreateSecureMessageDelegate() override;
+ std::unique_ptr<CryptAuthClientFactory> CreateCryptAuthClientFactory()
+ override;
+
+ private:
+ CryptAuthDeviceManager* cryptauth_device_manager_;
+ CryptAuthEnrollmentManager* cryptauth_enrollment_manager_;
+ DeviceClassifier device_classifier_;
+ std::string account_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeCryptAuthService);
+};
+
+} // namespace cryptauth
+
+#endif // COMPONENTS_CRYPTAUTH_FAKE_CRYPTAUTH_SERVICE_H_
diff --git a/chromium/components/cryptauth/fake_secure_channel.cc b/chromium/components/cryptauth/fake_secure_channel.cc
index e06a0d4dd44..03956aadc48 100644
--- a/chromium/components/cryptauth/fake_secure_channel.cc
+++ b/chromium/components/cryptauth/fake_secure_channel.cc
@@ -13,8 +13,8 @@ FakeSecureChannel::SentMessage::SentMessage(const std::string& feature,
: feature(feature), payload(payload) {}
FakeSecureChannel::FakeSecureChannel(std::unique_ptr<Connection> connection,
- std::unique_ptr<Delegate> delegate)
- : SecureChannel(std::move(connection), std::move(delegate)) {}
+ CryptAuthService* cryptauth_service)
+ : SecureChannel(std::move(connection), cryptauth_service) {}
FakeSecureChannel::~FakeSecureChannel() {}
diff --git a/chromium/components/cryptauth/fake_secure_channel.h b/chromium/components/cryptauth/fake_secure_channel.h
index e086801b957..4a202d9a771 100644
--- a/chromium/components/cryptauth/fake_secure_channel.h
+++ b/chromium/components/cryptauth/fake_secure_channel.h
@@ -10,11 +10,13 @@
namespace cryptauth {
+class CryptAuthService;
+
// A fake implementation of SecureChannel to use in tests.
class FakeSecureChannel : public SecureChannel {
public:
FakeSecureChannel(std::unique_ptr<Connection> connection,
- std::unique_ptr<Delegate> delegate);
+ CryptAuthService* cryptauth_service);
~FakeSecureChannel() override;
struct SentMessage {
diff --git a/chromium/components/cryptauth/secure_channel.cc b/chromium/components/cryptauth/secure_channel.cc
index a51b5c8e587..9048f4d4f8b 100644
--- a/chromium/components/cryptauth/secure_channel.cc
+++ b/chromium/components/cryptauth/secure_channel.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/memory/ptr_util.h"
+#include "components/cryptauth/cryptauth_service.h"
#include "components/cryptauth/wire_message.h"
#include "components/proximity_auth/logging/logging.h"
@@ -17,12 +18,12 @@ SecureChannel::Factory* SecureChannel::Factory::factory_instance_ = nullptr;
// static
std::unique_ptr<SecureChannel> SecureChannel::Factory::NewInstance(
std::unique_ptr<Connection> connection,
- std::unique_ptr<Delegate> delegate) {
+ CryptAuthService* cryptauth_service) {
if (!factory_instance_) {
factory_instance_ = new Factory();
}
return factory_instance_->BuildInstance(std::move(connection),
- std::move(delegate));
+ cryptauth_service);
}
// static
@@ -32,9 +33,9 @@ void SecureChannel::Factory::SetInstanceForTesting(Factory* factory) {
std::unique_ptr<SecureChannel> SecureChannel::Factory::BuildInstance(
std::unique_ptr<Connection> connection,
- std::unique_ptr<Delegate> delegate) {
+ CryptAuthService* cryptauth_service) {
return base::WrapUnique(
- new SecureChannel(std::move(connection), std::move(delegate)));
+ new SecureChannel(std::move(connection), cryptauth_service));
}
// static
@@ -55,8 +56,6 @@ std::string SecureChannel::StatusToString(const Status& status) {
}
}
-SecureChannel::Delegate::~Delegate() {}
-
SecureChannel::PendingMessage::PendingMessage() {}
SecureChannel::PendingMessage::PendingMessage(
@@ -66,15 +65,15 @@ SecureChannel::PendingMessage::PendingMessage(
SecureChannel::PendingMessage::~PendingMessage() {}
SecureChannel::SecureChannel(std::unique_ptr<Connection> connection,
- std::unique_ptr<Delegate> delegate)
+ CryptAuthService* cryptauth_service)
: status_(Status::DISCONNECTED),
connection_(std::move(connection)),
- delegate_(std::move(delegate)),
+ cryptauth_service_(cryptauth_service),
weak_ptr_factory_(this) {
DCHECK(connection_);
DCHECK(!connection_->IsConnected());
DCHECK(!connection_->remote_device().user_id.empty());
- DCHECK(delegate_);
+ DCHECK(cryptauth_service);
connection_->AddObserver(this);
}
@@ -201,9 +200,8 @@ void SecureChannel::Authenticate() {
DCHECK(!authenticator_);
authenticator_ = DeviceToDeviceAuthenticator::Factory::NewInstance(
- connection_.get(),
- connection_->remote_device().user_id,
- delegate_->CreateSecureMessageDelegate());
+ connection_.get(), connection_->remote_device().user_id,
+ cryptauth_service_->CreateSecureMessageDelegate());
authenticator_->Authenticate(
base::Bind(&SecureChannel::OnAuthenticationResult,
weak_ptr_factory_.GetWeakPtr()));
diff --git a/chromium/components/cryptauth/secure_channel.h b/chromium/components/cryptauth/secure_channel.h
index 3732f242ed6..e0d83b2f853 100644
--- a/chromium/components/cryptauth/secure_channel.h
+++ b/chromium/components/cryptauth/secure_channel.h
@@ -19,6 +19,8 @@
namespace cryptauth {
+class CryptAuthService;
+
// An authenticated bi-directional channel for exchanging messages with remote
// devices. |SecureChannel| manages a |Connection| by initializing it and
// authenticating it via a security handshake once the connection has occurred.
@@ -59,26 +61,18 @@ class SecureChannel : public ConnectionObserver {
const std::string& payload) = 0;
};
- class Delegate {
- public:
- virtual ~Delegate();
-
- virtual std::unique_ptr<SecureMessageDelegate>
- CreateSecureMessageDelegate() = 0;
- };
-
class Factory {
public:
static std::unique_ptr<SecureChannel> NewInstance(
std::unique_ptr<Connection> connection,
- std::unique_ptr<Delegate> delegate);
+ CryptAuthService* cryptauth_service);
static void SetInstanceForTesting(Factory* factory);
protected:
virtual std::unique_ptr<SecureChannel> BuildInstance(
std::unique_ptr<Connection> connection,
- std::unique_ptr<Delegate> delegate);
+ CryptAuthService* cryptauth_service);
private:
static Factory* factory_instance_;
@@ -112,7 +106,7 @@ class SecureChannel : public ConnectionObserver {
protected:
SecureChannel(std::unique_ptr<Connection> connection,
- std::unique_ptr<Delegate> delegate);
+ CryptAuthService* cryptauth_service);
Status status_;
@@ -141,7 +135,7 @@ class SecureChannel : public ConnectionObserver {
std::unique_ptr<SecureContext> secure_context);
std::unique_ptr<Connection> connection_;
- std::unique_ptr<Delegate> delegate_;
+ CryptAuthService* cryptauth_service_; // Outlives this instance.
std::unique_ptr<Authenticator> authenticator_;
std::unique_ptr<SecureContext> secure_context_;
std::deque<PendingMessage> queued_messages_;
diff --git a/chromium/components/cryptauth/secure_channel_unittest.cc b/chromium/components/cryptauth/secure_channel_unittest.cc
index 3e7968cdb6e..f894110238c 100644
--- a/chromium/components/cryptauth/secure_channel_unittest.cc
+++ b/chromium/components/cryptauth/secure_channel_unittest.cc
@@ -11,6 +11,7 @@
#include "base/memory/weak_ptr.h"
#include "components/cryptauth/fake_authenticator.h"
#include "components/cryptauth/fake_connection.h"
+#include "components/cryptauth/fake_cryptauth_service.h"
#include "components/cryptauth/fake_secure_context.h"
#include "components/cryptauth/fake_secure_message_delegate.h"
#include "components/cryptauth/remote_device_test_util.h"
@@ -23,21 +24,6 @@ namespace {
const std::string test_user_id = "testUserId";
-class TestDelegate : public SecureChannel::Delegate {
- public:
- TestDelegate(std::unique_ptr<SecureMessageDelegate> secure_message_delegate)
- : secure_message_delegate_(std::move(secure_message_delegate)) {}
- ~TestDelegate() override {}
-
- std::unique_ptr<SecureMessageDelegate> CreateSecureMessageDelegate()
- override {
- return std::move(secure_message_delegate_);
- }
-
- private:
- std::unique_ptr<SecureMessageDelegate> secure_message_delegate_;
-};
-
struct SecureChannelStatusChange {
SecureChannelStatusChange(
const SecureChannel::Status& old_status,
@@ -122,8 +108,8 @@ RemoteDevice CreateTestRemoteDevice() {
class TestSecureChannel : public SecureChannel {
public:
TestSecureChannel(std::unique_ptr<Connection> connection,
- std::unique_ptr<Delegate> delegate)
- : SecureChannel(std::move(connection), std::move(delegate)) {}
+ CryptAuthService* cryptauth_service)
+ : SecureChannel(std::move(connection), cryptauth_service) {}
};
} // namespace
@@ -141,17 +127,14 @@ class CryptAuthSecureChannelTest : public testing::Test {
fake_secure_context_ = nullptr;
- fake_secure_message_delegate_ = new FakeSecureMessageDelegate();
-
- test_delegate_ =
- new TestDelegate(base::WrapUnique(fake_secure_message_delegate_));
+ fake_cryptauth_service_ = base::MakeUnique<FakeCryptAuthService>();
fake_connection_ =
new FakeConnection(test_device_, /* should_auto_connect */ false);
EXPECT_FALSE(fake_connection_->observers().size());
secure_channel_ = base::MakeUnique<TestSecureChannel>(
- base::WrapUnique(fake_connection_), base::WrapUnique(test_delegate_));
+ base::WrapUnique(fake_connection_), fake_cryptauth_service_.get());
EXPECT_EQ(static_cast<size_t>(1), fake_connection_->observers().size());
EXPECT_EQ(secure_channel_.get(), fake_connection_->observers()[0]);
@@ -300,11 +283,7 @@ class CryptAuthSecureChannelTest : public testing::Test {
// Owned by secure_channel_.
FakeConnection* fake_connection_;
- // Owned by secure_chanel_.
- TestDelegate* test_delegate_;
-
- // Owned by test_delegate_.
- FakeSecureMessageDelegate* fake_secure_message_delegate_;
+ std::unique_ptr<FakeCryptAuthService> fake_cryptauth_service_;
// Owned by secure_channel_ once authentication has completed successfully.
FakeSecureContext* fake_secure_context_;