Skip to content

Commit

Permalink
Add Profile::OTRProfileID::CreateFromProfileID() via chromium override
Browse files Browse the repository at this point in the history
The constructor Profile::OTRProfileID::OTRProfileID is private now, so
we need a way of creating an instance from Brave's TorProfileManager
that doesn't require access to Profile::OTRProfileID's private members.

Chromium change:

https://chromium.googlesource.com/chromium/src.git/+/990446325f38f9c1cdc22d6b1703aa0554089424

commit 990446325f38f9c1cdc22d6b1703aa0554089424
Author: Ramin Halavati <[email protected]>
Date:   Mon Apr 19 12:10:37 2021 +0000

    Make OTRProfileID constructor private.

    OTRProfileID constructor is made private to reduce the possibility of
    using duplicate ids and making MakeUnique function more visible.

    OTRProfileID::CreateUniqueForTesting() is added to be used as a
    shorthand in tests since we don't need specific id prefixes in tests.

    This CL does not change any behavior.

    Bug: 1196661
  • Loading branch information
mariospr committed Apr 20, 2021
1 parent 6c13519 commit 13fe236
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion browser/tor/tor_profile_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ TorProfileManager::~TorProfileManager() {

Profile* TorProfileManager::GetTorProfile(Profile* original_profile) {
Profile* tor_profile = original_profile->GetOffTheRecordProfile(
Profile::OTRProfileID(tor::kTorProfileID), /*create_if_needed=*/true);
Profile::OTRProfileID::CreateFromProfileID(tor::kTorProfileID),
/*create_if_needed=*/true);

const std::string context_id = tor_profile->UniqueId();
auto it = tor_profiles_.find(context_id);
Expand Down
6 changes: 6 additions & 0 deletions chromium_src/chrome/browser/profiles/profile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const Profile::OTRProfileID Profile::OTRProfileID::TorID() {
return OTRProfileID(tor::kTorProfileID);
}

// static
Profile::OTRProfileID Profile::OTRProfileID::CreateFromProfileID(
const std::string& profile_id) {
return OTRProfileID(profile_id);
}

bool Profile::IsTor() const {
return IsOffTheRecord() && GetOTRProfileID() == OTRProfileID::TorID();
}
Expand Down
6 changes: 5 additions & 1 deletion chromium_src/chrome/browser/profiles/profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_PROFILES_PROFILE_H_

#define PrimaryID PrimaryID(); static const OTRProfileID TorID
#define CreateUniqueForTesting \
CreateFromProfileID(const std::string& profile_id); \
static OTRProfileID CreateUniqueForTesting
#define HasPrimaryOTRProfile IsTor() const override; bool HasPrimaryOTRProfile
#define IsIncognitoProfile \
IsIncognitoProfile_ChromiumImpl() const; \
bool IsIncognitoProfile
#include "../../../../../chrome/browser/profiles/profile.h"
#undef IsIncognitoProfile
#undef PrimaryID
#undef HasPrimaryOTRProfile
#undef CreateUniqueForTesting
#undef PrimaryID

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_PROFILES_PROFILE_H_

0 comments on commit 13fe236

Please sign in to comment.