Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Unified Diff: content/browser/dom_storage/dom_storage_message_filter.cc

Issue 10389067: Optimized webstorage performance (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/dom_storage/dom_storage_message_filter.h ('k') | content/common/dom_storage_messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/dom_storage/dom_storage_message_filter.cc
diff --git a/content/browser/dom_storage/dom_storage_message_filter.cc b/content/browser/dom_storage/dom_storage_message_filter.cc
index 15d19b308ec41271a4bd5d5279917adc26d94818..5828984e605f5da3307c89856850454f73da2bdc 100644
--- a/content/browser/dom_storage/dom_storage_message_filter.cc
+++ b/content/browser/dom_storage/dom_storage_message_filter.cc
@@ -7,6 +7,7 @@
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/nullable_string16.h"
+#include "base/process_util.h"
#include "base/threading/sequenced_worker_pool.h"
#include "base/utf_string_conversions.h"
#include "content/public/browser/user_metrics.h"
@@ -16,6 +17,8 @@
#include "webkit/dom_storage/dom_storage_area.h"
#include "webkit/dom_storage/dom_storage_host.h"
#include "webkit/dom_storage/dom_storage_task_runner.h"
+#include "webkit/dom_storage/dom_storage_types.h"
+
using content::BrowserThread;
using content::UserMetricsAction;
@@ -91,6 +94,7 @@ bool DOMStorageMessageFilter::OnMessageReceived(const IPC::Message& message,
IPC_MESSAGE_HANDLER(DOMStorageHostMsg_Key, OnKey)
IPC_MESSAGE_HANDLER(DOMStorageHostMsg_GetItem, OnGetItem)
IPC_MESSAGE_HANDLER(DOMStorageHostMsg_SetItem, OnSetItem)
+ IPC_MESSAGE_HANDLER(DOMStorageHostMsg_SetItemOpt, OnSetItemOpt)
IPC_MESSAGE_HANDLER(DOMStorageHostMsg_SetItemAsync, OnSetItemAsync)
IPC_MESSAGE_HANDLER(DOMStorageHostMsg_RemoveItem, OnRemoveItem)
IPC_MESSAGE_HANDLER(DOMStorageHostMsg_RemoveItemAsync, OnRemoveItemAsync)
@@ -139,9 +143,39 @@ void DOMStorageMessageFilter::OnKey(int connection_id, unsigned index,
void DOMStorageMessageFilter::OnGetItem(int connection_id,
const string16& key,
+ int* ipc_flag,
+ base::SharedMemoryHandle* shm_handle,
+ unsigned* shm_size,
NullableString16* value) {
DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
*value = host_->GetAreaItem(connection_id, key);
+ int value_len = value->string().length()*sizeof(WebKit::WebUChar);
+ // small size data, go through channel
+ if (value->is_null() || value_len * sizeof(char16)
+ < dom_storage::kShmEnableThreshold) {
+ *ipc_flag = dom_storage::Channel;
+ *shm_size = 0;
+ return;
+ }
+
+ base::SharedMemory shared_buf;
+ // try shm for big size data,
+ // if fail, go through channel
+ if (!shared_buf.CreateAndMapAnonymous(value_len)) {
+ *ipc_flag = dom_storage::Channel;
+ *shm_size = 0;
+ return;
+ }
+ // go through shm
+ shared_buf.Lock();
+ memcpy(shared_buf.memory(), value->string().data(), value_len);
+ shared_buf.Unlock();
+ shared_buf.GiveToProcess(peer_handle(), shm_handle);
+ shared_buf.Close();
+ *ipc_flag = dom_storage::SharedMemory;
+ *shm_size = value->string().length();
+ string16 tmp;
+ *value = NullableString16(tmp, true);
}
void DOMStorageMessageFilter::OnSetItem(
@@ -156,6 +190,36 @@ void DOMStorageMessageFilter::OnSetItem(
*result = WebKit::WebStorageArea::ResultBlockedByQuota;
}
+void DOMStorageMessageFilter::OnSetItemOpt(
+ int connection_id, const string16& key,
+ const int value_len,
+ base::SharedMemoryHandle renderer_handle,
+ const GURL& page_url,
+ WebKit::WebStorageArea::Result* result,
+ NullableString16* old_value) {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::IO));
+ string16 value;
+ *old_value = NullableString16(true);
+ // get value from shared memory
+ if (!base::SharedMemory::IsHandleValid(renderer_handle)) {
+ NOTREACHED() << "We got an invalid shared buffer handle!\n";
+ return;
+ }
+
+ base::SharedMemory shared_buf(renderer_handle, true, peer_handle());
+ shared_buf.Map(value_len*sizeof(char16));
+
+ shared_buf.Lock();
+ value.append(static_cast<char16*>(shared_buf.memory()), value_len);
+ shared_buf.Unlock();
+ shared_buf.Close();
+ //
+ if (host_->SetAreaItem(connection_id, key, value, page_url, old_value))
+ *result = WebKit::WebStorageArea::ResultOK;
+ else
+ *result = WebKit::WebStorageArea::ResultBlockedByQuota;
+}
+
void DOMStorageMessageFilter::OnSetItemAsync(
int connection_id, int operation_id, const string16& key,
const string16& value, const GURL& page_url) {
« no previous file with comments | « content/browser/dom_storage/dom_storage_message_filter.h ('k') | content/common/dom_storage_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698