Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ElectronBrowserContext::PartitionKey comparisons #41084

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 16 additions & 34 deletions shell/browser/electron_browser_context.h
Expand Up @@ -8,6 +8,7 @@
#include <map>
#include <memory>
#include <string>
#include <string_view>
#include <variant>
#include <vector>
#include "base/memory/raw_ptr.h"
Expand Down Expand Up @@ -78,41 +79,22 @@ class ElectronBrowserContext : public content::BrowserContext {

// partition_id => browser_context
struct PartitionKey {
enum class KeyType { Partition, FilePath };
std::string location;
bool in_memory;
KeyType partition_type;

PartitionKey(const std::string& partition, bool in_memory)
: location(partition),
in_memory(in_memory),
partition_type(KeyType::Partition) {}
PartitionKey(const std::string_view partition, bool in_memory)
: type_{Type::Partition}, location_{partition}, in_memory_{in_memory} {}

explicit PartitionKey(const base::FilePath& file_path)
: location(file_path.AsUTF8Unsafe()),
in_memory(false),
partition_type(KeyType::FilePath) {}

bool operator<(const PartitionKey& other) const {
if (partition_type == KeyType::Partition) {
if (location == other.location)
return in_memory < other.in_memory;
return location < other.location;
} else {
if (location == other.location)
return false;
return location < other.location;
}
}

bool operator==(const PartitionKey& other) const {
if (partition_type == KeyType::Partition) {
return (location == other.location) && (in_memory < other.in_memory);
} else {
if (location == other.location)
return true;
return false;
}
}
: type_{Type::Path},
location_{file_path.AsUTF8Unsafe()},
in_memory_{false} {}

friend auto operator<=>(const PartitionKey&, const PartitionKey&) = default;

private:
enum class Type { Partition, Path };

Type type_;
std::string location_;
bool in_memory_;
};

using BrowserContextMap =
Expand Down