Chromium Code Reviews| 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, |
|
michaeln
2012/05/10 18:42:59
fyi: this method/syncipc is soon to be deleted fro
|
| 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( |
|
michaeln
2012/05/10 18:42:59
ditto this method/syncipc is soon to be deleted
|
| @@ -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) { |