Skip to content

Commit

Permalink
Switch from base::PassKey to base::WrapUnique.
Browse files Browse the repository at this point in the history
Since Encryptor has a private constructor, to create a unique_ptr
for storage in the OSCryptAsync object, a base::PassKey was
being used.

However, an alternative method is simply to use base::WrapUnique
as it can access the private constructor, and this pattern
is more commonly used in Chromium code.

This CL removes the base::PassKey and replaces it base::WrapUnique.

No functional changes.

BUG=1373092

Change-Id: I97efc070fb225676e47b74453ef498f8c56eb6f1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4348030
Reviewed-by: James Forshaw <forshaw@chromium.org>
Commit-Queue: Will Harris <wfh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1118981}
  • Loading branch information
Will Harris authored and Chromium LUCI CQ committed Mar 18, 2023
1 parent f2fe037 commit daf6fca
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
5 changes: 2 additions & 3 deletions components/os_crypt/async/browser/os_crypt_async.cc
Expand Up @@ -5,8 +5,8 @@
#include "components/os_crypt/async/browser/os_crypt_async.h"

#include "base/callback_list.h"
#include "base/memory/ptr_util.h"
#include "base/sequence_checker.h"
#include "base/types/pass_key.h"
#include "components/os_crypt/async/common/encryptor.h"

namespace os_crypt_async {
Expand All @@ -22,8 +22,7 @@ base::CallbackListSubscription OSCryptAsync::GetInstance(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);

if (!is_initialized_) {
encryptor_instance_ =
std::make_unique<Encryptor>(/*passkey=*/base::PassKey<OSCryptAsync>());
encryptor_instance_ = base::WrapUnique<Encryptor>(new Encryptor());
is_initialized_ = true;
}

Expand Down
2 changes: 0 additions & 2 deletions components/os_crypt/async/common/encryptor.cc
Expand Up @@ -8,7 +8,6 @@
#include <vector>

#include "base/containers/span.h"
#include "base/types/pass_key.h"
#include "components/os_crypt/sync/os_crypt.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

Expand All @@ -18,7 +17,6 @@ Encryptor::Encryptor(Encryptor&& other) = default;
Encryptor& Encryptor::operator=(Encryptor&& other) = default;

Encryptor::Encryptor() = default;
Encryptor::Encryptor(base::PassKey<OSCryptAsync> passkey) {}

Encryptor::~Encryptor() = default;

Expand Down
4 changes: 1 addition & 3 deletions components/os_crypt/async/common/encryptor.h
Expand Up @@ -11,7 +11,6 @@
#include "base/containers/span.h"
#include "base/functional/callback.h"
#include "base/gtest_prod_util.h"
#include "base/types/pass_key.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

namespace os_crypt_async {
Expand All @@ -22,7 +21,6 @@ class OSCryptAsync;
// obtained by calling `os_crypt_async::OSCryptAsync::GetInstance`.
class Encryptor {
public:
explicit Encryptor(base::PassKey<OSCryptAsync> passkey);
~Encryptor();

// Moveable, not copyable.
Expand Down Expand Up @@ -52,7 +50,7 @@ class Encryptor {
private:
friend class OSCryptAsync;

// Used for cloning.
// Used for cloning and creation of the template instance.
Encryptor();

// Clone is used by the factory to vend instances.
Expand Down

0 comments on commit daf6fca

Please sign in to comment.