#include "services/network/http_auth_cache_proxy_copier.h"
#include "base/logging.h"
#include "net/http/http_auth_cache.h"
namespace network {
HttpAuthCacheProxyCopier::HttpAuthCacheProxyCopier() = default;
HttpAuthCacheProxyCopier::~HttpAuthCacheProxyCopier() = default;
base::UnguessableToken HttpAuthCacheProxyCopier::SaveHttpAuthCache(
const net::HttpAuthCache& cache) {
base::UnguessableToken key = base::UnguessableToken::Create();
auto cache_it = caches_.emplace(
key, std::make_unique<net::HttpAuthCache>(
true));
DCHECK(cache_it.second);
cache_it.first->second->CopyProxyEntriesFrom(cache);
return key;
}
void HttpAuthCacheProxyCopier::LoadHttpAuthCache(
const base::UnguessableToken& key,
net::HttpAuthCache* cache) {
auto it = caches_.find(key);
if (it == caches_.end()) {
DLOG(ERROR) << "Unknown HttpAuthCache key: " << key;
return;
}
cache->CopyProxyEntriesFrom(*it->second);
caches_.erase(it);
}
}