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, ...@@ -23,7 +23,7 @@ String URLFileAPI::createObjectURL(ScriptState* script_state,
DCHECK(execution_context); DCHECK(execution_context);
UseCounter::Count(execution_context, WebFeature::kCreateObjectURLBlob); UseCounter::Count(execution_context, WebFeature::kCreateObjectURLBlob);
return DOMURL::CreatePublicURL(execution_context, blob, blob->Uuid()); return DOMURL::CreatePublicURL(execution_context, blob);
} }
// static // static
......
...@@ -44,52 +44,27 @@ PublicURLManager::PublicURLManager(ExecutionContext* context) ...@@ -44,52 +44,27 @@ PublicURLManager::PublicURLManager(ExecutionContext* context)
: ContextLifecycleObserver(context), is_stopped_(false) {} : ContextLifecycleObserver(context), is_stopped_(false) {}
String PublicURLManager::RegisterURL(ExecutionContext* context, String PublicURLManager::RegisterURL(ExecutionContext* context,
URLRegistrable* registrable, URLRegistrable* registrable) {
const String& uuid) {
SecurityOrigin* origin = context->GetMutableSecurityOrigin(); SecurityOrigin* origin = context->GetMutableSecurityOrigin();
const KURL& url = BlobURL::CreatePublicURL(origin); const KURL& url = BlobURL::CreatePublicURL(origin);
DCHECK(!url.IsEmpty()); DCHECK(!url.IsEmpty());
const String& url_string = url.GetString(); const String& url_string = url.GetString();
if (!is_stopped_) { if (!is_stopped_) {
RegistryURLMap::ValueType* found = URLRegistry* registry = &registrable->Registry();
registry_to_url_.insert(&registrable->Registry(), URLMap()) registry->RegisterURL(origin, url, registrable);
.stored_value; url_to_registry_.insert(url_string, registry);
found->key->RegisterURL(origin, url, registrable);
found->value.insert(url_string, uuid);
} }
return url_string; return url_string;
} }
void PublicURLManager::Revoke(const KURL& url) { void PublicURLManager::Revoke(const KURL& url) {
for (auto& registry_url : registry_to_url_) { auto it = url_to_registry_.find(url.GetString());
if (registry_url.value.Contains(url.GetString())) { if (it == url_to_registry_.end())
registry_url.key->UnregisterURL(url); return;
registry_url.value.erase(url.GetString()); it->value->UnregisterURL(url);
break; url_to_registry_.erase(it);
}
}
}
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();
}
} }
void PublicURLManager::ContextDestroyed(ExecutionContext*) { void PublicURLManager::ContextDestroyed(ExecutionContext*) {
...@@ -97,12 +72,10 @@ void PublicURLManager::ContextDestroyed(ExecutionContext*) { ...@@ -97,12 +72,10 @@ void PublicURLManager::ContextDestroyed(ExecutionContext*) {
return; return;
is_stopped_ = true; is_stopped_ = true;
for (auto& registry_url : registry_to_url_) { for (auto& url_registry : url_to_registry_)
for (auto& url : registry_url.value) url_registry.value->UnregisterURL(KURL(url_registry.key));
registry_url.key->UnregisterURL(KURL(url.key));
}
registry_to_url_.clear(); url_to_registry_.clear();
} }
void PublicURLManager::Trace(blink::Visitor* visitor) { void PublicURLManager::Trace(blink::Visitor* visitor) {
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "core/dom/ContextLifecycleObserver.h" #include "core/dom/ContextLifecycleObserver.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "platform/wtf/HashMap.h" #include "platform/wtf/HashMap.h"
#include "platform/wtf/HashSet.h"
#include "platform/wtf/text/WTFString.h" #include "platform/wtf/text/WTFString.h"
namespace blink { namespace blink {
...@@ -49,16 +50,9 @@ class PublicURLManager final ...@@ -49,16 +50,9 @@ class PublicURLManager final
// Generates a new Blob URL and registers the URLRegistrable to the // Generates a new Blob URL and registers the URLRegistrable to the
// corresponding URLRegistry with the Blob URL. Returns the serialization // corresponding URLRegistry with the Blob URL. Returns the serialization
// of the Blob URL. // of the Blob URL.
// String RegisterURL(ExecutionContext*, URLRegistrable*);
// |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);
// Revokes the given URL. // Revokes the given URL.
void Revoke(const KURL&); void Revoke(const KURL&);
// Revokes all URLs associated with |uuid|.
void Revoke(const String& uuid);
// ContextLifecycleObserver interface. // ContextLifecycleObserver interface.
void ContextDestroyed(ExecutionContext*) override; void ContextDestroyed(ExecutionContext*) override;
...@@ -68,16 +62,11 @@ class PublicURLManager final ...@@ -68,16 +62,11 @@ class PublicURLManager final
private: private:
explicit PublicURLManager(ExecutionContext*); 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 String URLString;
typedef HashMap<URLString, String> URLMap; // Map from URLs to the URLRegistry they are registered with.
// Map from URLRegistry instances to the maps which store association typedef HashMap<URLString, URLRegistry*> URLToRegistryMap;
// between URLs registered with the URLRegistry and UUIDs assigned for URLToRegistryMap url_to_registry_;
// each of the URLs.
typedef HashMap<URLRegistry*, URLMap> RegistryURLMap;
RegistryURLMap registry_to_url_;
bool is_stopped_; bool is_stopped_;
}; };
......
...@@ -78,18 +78,9 @@ void DOMURL::setSearch(const String& value) { ...@@ -78,18 +78,9 @@ void DOMURL::setSearch(const String& value) {
} }
String DOMURL::CreatePublicURL(ExecutionContext* execution_context, String DOMURL::CreatePublicURL(ExecutionContext* execution_context,
URLRegistrable* registrable, URLRegistrable* registrable) {
const String& uuid) { return execution_context->GetPublicURLManager().RegisterURL(execution_context,
return execution_context->GetPublicURLManager().RegisterURL( registrable);
execution_context, registrable, uuid);
}
void DOMURL::RevokeObjectUUID(ExecutionContext* execution_context,
const String& uuid) {
if (!execution_context)
return;
execution_context->GetPublicURLManager().Revoke(uuid);
} }
URLSearchParams* DOMURL::searchParams() { URLSearchParams* DOMURL::searchParams() {
......
...@@ -56,10 +56,7 @@ class DOMURL final : public ScriptWrappable, public DOMURLUtils { ...@@ -56,10 +56,7 @@ class DOMURL final : public ScriptWrappable, public DOMURLUtils {
} }
~DOMURL(); ~DOMURL();
CORE_EXPORT static String CreatePublicURL(ExecutionContext*, CORE_EXPORT static String CreatePublicURL(ExecutionContext*, URLRegistrable*);
URLRegistrable*,
const String& uuid = String());
static void RevokeObjectUUID(ExecutionContext*, const String&);
KURL Url() const override { return url_; } KURL Url() const override { return url_; }
void SetURL(const KURL& url) override { url_ = 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