2011-05-16 18:56:12 +02:00
|
|
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
|
2010-09-13 03:59:43 +02:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "browser_webblobregistry_impl.h"
|
|
|
|
|
2011-10-20 22:34:13 +02:00
|
|
|
#include "base/bind.h"
|
2010-09-13 03:59:43 +02:00
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "googleurl/src/gurl.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
|
2010-09-13 03:59:43 +02:00
|
|
|
#include "webkit/blob/blob_data.h"
|
|
|
|
#include "webkit/blob/blob_storage_controller.h"
|
|
|
|
|
|
|
|
using WebKit::WebBlobData;
|
|
|
|
using WebKit::WebURL;
|
2011-10-20 22:34:13 +02:00
|
|
|
using webkit_blob::BlobData;
|
2010-09-13 03:59:43 +02:00
|
|
|
|
2010-10-15 20:37:25 +02:00
|
|
|
namespace {
|
|
|
|
|
2010-09-13 03:59:43 +02:00
|
|
|
MessageLoop* g_io_thread;
|
|
|
|
webkit_blob::BlobStorageController* g_blob_storage_controller;
|
|
|
|
|
2010-10-15 20:37:25 +02:00
|
|
|
} // namespace
|
|
|
|
|
2010-09-13 03:59:43 +02:00
|
|
|
/* static */
|
|
|
|
void BrowserWebBlobRegistryImpl::InitializeOnIOThread(
|
|
|
|
webkit_blob::BlobStorageController* blob_storage_controller) {
|
|
|
|
g_io_thread = MessageLoop::current();
|
|
|
|
g_blob_storage_controller = blob_storage_controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void BrowserWebBlobRegistryImpl::Cleanup() {
|
|
|
|
g_io_thread = NULL;
|
|
|
|
g_blob_storage_controller = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserWebBlobRegistryImpl::BrowserWebBlobRegistryImpl() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebBlobRegistryImpl::registerBlobURL(
|
|
|
|
const WebURL& url, WebBlobData& data) {
|
|
|
|
DCHECK(g_io_thread);
|
2011-10-20 22:34:13 +02:00
|
|
|
GURL thread_safe_url = url; // WebURL uses refcounted strings.
|
|
|
|
g_io_thread->PostTask(FROM_HERE, base::Bind(
|
|
|
|
&BrowserWebBlobRegistryImpl::AddFinishedBlob, this,
|
|
|
|
thread_safe_url, make_scoped_refptr(new BlobData(data))));
|
2010-09-13 03:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebBlobRegistryImpl::registerBlobURL(
|
|
|
|
const WebURL& url, const WebURL& src_url) {
|
|
|
|
DCHECK(g_io_thread);
|
2011-10-20 22:34:13 +02:00
|
|
|
GURL thread_safe_url = url;
|
|
|
|
GURL thread_safe_src_url = src_url;
|
|
|
|
g_io_thread->PostTask(FROM_HERE, base::Bind(
|
|
|
|
&BrowserWebBlobRegistryImpl::CloneBlob, this,
|
|
|
|
thread_safe_url, thread_safe_src_url));
|
2010-09-13 03:59:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BrowserWebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) {
|
|
|
|
DCHECK(g_io_thread);
|
2011-10-20 22:34:13 +02:00
|
|
|
GURL thread_safe_url = url;
|
|
|
|
g_io_thread->PostTask(FROM_HERE, base::Bind(
|
|
|
|
&BrowserWebBlobRegistryImpl::RemoveBlob, this,
|
|
|
|
thread_safe_url));
|
2010-09-13 03:59:43 +02:00
|
|
|
}
|
|
|
|
|
2011-10-20 22:34:13 +02:00
|
|
|
void BrowserWebBlobRegistryImpl::AddFinishedBlob(
|
|
|
|
const GURL& url, BlobData* blob_data) {
|
2010-09-13 03:59:43 +02:00
|
|
|
DCHECK(g_blob_storage_controller);
|
2011-10-20 22:34:13 +02:00
|
|
|
g_blob_storage_controller->AddFinishedBlob(url, blob_data);
|
2010-09-13 03:59:43 +02:00
|
|
|
}
|
|
|
|
|
2011-10-20 22:34:13 +02:00
|
|
|
void BrowserWebBlobRegistryImpl::CloneBlob(
|
2010-09-13 03:59:43 +02:00
|
|
|
const GURL& url, const GURL& src_url) {
|
|
|
|
DCHECK(g_blob_storage_controller);
|
2011-10-20 22:34:13 +02:00
|
|
|
g_blob_storage_controller->CloneBlob(url, src_url);
|
2010-09-13 03:59:43 +02:00
|
|
|
}
|
|
|
|
|
2011-10-20 22:34:13 +02:00
|
|
|
void BrowserWebBlobRegistryImpl::RemoveBlob(const GURL& url) {
|
2010-09-13 03:59:43 +02:00
|
|
|
DCHECK(g_blob_storage_controller);
|
2011-10-20 22:34:13 +02:00
|
|
|
g_blob_storage_controller->RemoveBlob(url);
|
2010-09-13 03:59:43 +02:00
|
|
|
}
|