Commit 19ecd2fc authored by Marijn Kruisselbrink's avatar Marijn Kruisselbrink Committed by Commit Bot

Remove logic to revoke URLs by UUID of the pointed to object.

These methods are never called, so get rid of them to make future
refactoring and cleanup easier. Also change the map in PublicURLManager
to now map from URL to Registry, rather than the other way around.

Bug: 756743
Change-Id: I1a7fec77f498b11c916fce1adc520ffda9268545
Reviewed-on: https://chromium-review.googlesource.com/822153Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Marijn Kruisselbrink <mek@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523724}
parent b702a6d8
......@@ -23,7 +23,7 @@ String URLFileAPI::createObjectURL(ScriptState* script_state,
DCHECK(execution_context);
UseCounter::Count(execution_context, WebFeature::kCreateObjectURLBlob);
return DOMURL::CreatePublicURL(execution_context, blob, blob->Uuid());
return DOMURL::CreatePublicURL(execution_context, blob);
}
// static
......
......@@ -44,52 +44,27 @@ PublicURLManager::PublicURLManager(ExecutionContext* context)
: ContextLifecycleObserver(context), is_stopped_(false) {}
String PublicURLManager::RegisterURL(ExecutionContext* context,
URLRegistrable* registrable,
const String& uuid) {
URLRegistrable* registrable) {
SecurityOrigin* origin = context->GetMutableSecurityOrigin();
const KURL& url = BlobURL::CreatePublicURL(origin);
DCHECK(!url.IsEmpty());
const String& url_string = url.GetString();
if (!is_stopped_) {
RegistryURLMap::ValueType* found =
registry_to_url_.insert(&registrable->Registry(), URLMap())
.stored_value;
found->key->RegisterURL(origin, url, registrable);
found->value.insert(url_string, uuid);
URLRegistry* registry = &registrable->Registry();
registry->RegisterURL(origin, url, registrable);
url_to_registry_.insert(url_string, registry);
}
return url_string;
}
void PublicURLManager::Revoke(const KURL& url) {
for (auto& registry_url : registry_to_url_) {
if (registry_url.value.Contains(url.GetString())) {
registry_url.key->UnregisterURL(url);
registry_url.value.erase(url.GetString());
break;
}
}
}
void PublicURLManager::Revoke(const String& uuid) {
// A linear scan; revoking by UUID is assumed rare.
Vector<String> urls_to_remove;
for (auto& registry_url : registry_to_url_) {
URLRegistry* registry = registry_url.key;
URLMap& registered_urls = registry_url.value;
for (auto& registered_url : registered_urls) {
if (uuid == registered_url.value) {
KURL url(registered_url.key);
GetExecutionContext()->RemoveURLFromMemoryCache(url);
registry->UnregisterURL(url);
urls_to_remove.push_back(registered_url.key);
}
}
for (const auto& url : urls_to_remove)
registered_urls.erase(url);
urls_to_remove.clear();
}
auto it = url_to_registry_.find(url.GetString());
if (it == url_to_registry_.end())
return;
it->value->UnregisterURL(url);
url_to_registry_.erase(it);
}
void PublicURLManager::ContextDestroyed(ExecutionContext*) {
......@@ -97,12 +72,10 @@ void PublicURLManager::ContextDestroyed(ExecutionContext*) {
return;
is_stopped_ = true;
for (auto& registry_url : registry_to_url_) {
for (auto& url : registry_url.value)
registry_url.key->UnregisterURL(KURL(url.key));
}
for (auto& url_registry : url_to_registry_)
url_registry.value->UnregisterURL(KURL(url_registry.key));
registry_to_url_.clear();
url_to_registry_.clear();
}
void PublicURLManager::Trace(blink::Visitor* visitor) {
......
......@@ -29,6 +29,7 @@
#include "core/dom/ContextLifecycleObserver.h"
#include "platform/heap/Handle.h"
#include "platform/wtf/HashMap.h"
#include "platform/wtf/HashSet.h"
#include "platform/wtf/text/WTFString.h"
namespace blink {
......@@ -49,16 +50,9 @@ class PublicURLManager final
// Generates a new Blob URL and registers the URLRegistrable to the
// corresponding URLRegistry with the Blob URL. Returns the serialization
// of the Blob URL.
//
// |uuid| can be used for revoke() to revoke all URLs associated with the
// |uuid|. It's not the UUID generated and appended to the BlobURL, but an
// identifier for the object to which URL(s) are generated e.g. ones
// returned by blink::Blob::uuid().
String RegisterURL(ExecutionContext*, URLRegistrable*, const String& uuid);
String RegisterURL(ExecutionContext*, URLRegistrable*);
// Revokes the given URL.
void Revoke(const KURL&);
// Revokes all URLs associated with |uuid|.
void Revoke(const String& uuid);
// ContextLifecycleObserver interface.
void ContextDestroyed(ExecutionContext*) override;
......@@ -68,16 +62,11 @@ class PublicURLManager final
private:
explicit PublicURLManager(ExecutionContext*);
// One or more URLs can be associated with the same unique ID.
// Objects need be revoked by unique ID in some cases.
typedef String URLString;
typedef HashMap<URLString, String> URLMap;
// Map from URLRegistry instances to the maps which store association
// between URLs registered with the URLRegistry and UUIDs assigned for
// each of the URLs.
typedef HashMap<URLRegistry*, URLMap> RegistryURLMap;
// Map from URLs to the URLRegistry they are registered with.
typedef HashMap<URLString, URLRegistry*> URLToRegistryMap;
URLToRegistryMap url_to_registry_;
RegistryURLMap registry_to_url_;
bool is_stopped_;
};
......
......@@ -78,18 +78,9 @@ void DOMURL::setSearch(const String& value) {
}
String DOMURL::CreatePublicURL(ExecutionContext* execution_context,
URLRegistrable* registrable,
const String& uuid) {
return execution_context->GetPublicURLManager().RegisterURL(
execution_context, registrable, uuid);
}
void DOMURL::RevokeObjectUUID(ExecutionContext* execution_context,
const String& uuid) {
if (!execution_context)
return;
execution_context->GetPublicURLManager().Revoke(uuid);
URLRegistrable* registrable) {
return execution_context->GetPublicURLManager().RegisterURL(execution_context,
registrable);
}
URLSearchParams* DOMURL::searchParams() {
......
......@@ -56,10 +56,7 @@ class DOMURL final : public ScriptWrappable, public DOMURLUtils {
}
~DOMURL();
CORE_EXPORT static String CreatePublicURL(ExecutionContext*,
URLRegistrable*,
const String& uuid = String());
static void RevokeObjectUUID(ExecutionContext*, const String&);
CORE_EXPORT static String CreatePublicURL(ExecutionContext*, URLRegistrable*);
KURL Url() const override { return url_; }
void SetURL(const KURL& url) override { url_ = url; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment