| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/renderer_webstoragearea_impl.h" | |
| 6 | |
| 7 #include "base/lazy_instance.h" | |
| 8 #include "base/metrics/histogram.h" | |
| 9 #include "base/time.h" | |
| 10 #include "base/utf_string_conversions.h" | |
| 11 #include "content/common/dom_storage_messages.h" | |
| 12 #include "content/renderer/render_thread_impl.h" | |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | |
| 14 #include "webkit/dom_storage/dom_storage_types.h" | |
| 15 | |
| 16 using WebKit::WebString; | |
| 17 using WebKit::WebURL; | |
| 18 | |
| 19 typedef IDMap<RendererWebStorageAreaImpl> AreaImplMap; | |
| 20 | |
| 21 static base::LazyInstance<AreaImplMap>::Leaky | |
| 22 g_all_areas_map = LAZY_INSTANCE_INITIALIZER; | |
| 23 | |
| 24 // static | |
| 25 RendererWebStorageAreaImpl* RendererWebStorageAreaImpl::FromConnectionId( | |
| 26 int id) { | |
| 27 return g_all_areas_map.Pointer()->Lookup(id); | |
| 28 } | |
| 29 | |
| 30 RendererWebStorageAreaImpl::RendererWebStorageAreaImpl( | |
| 31 int64 namespace_id, const WebString& origin) | |
| 32 : ALLOW_THIS_IN_INITIALIZER_LIST( | |
| 33 connection_id_(g_all_areas_map.Pointer()->Add(this))) { | |
| 34 // TODO(michaeln): fix the webkit api to have the 'origin' input | |
| 35 // be a URL instead of a string. | |
| 36 DCHECK(connection_id_); | |
| 37 RenderThreadImpl::current()->Send( | |
| 38 new DOMStorageHostMsg_OpenStorageArea( | |
| 39 connection_id_, namespace_id, GURL(origin))); | |
| 40 } | |
| 41 | |
| 42 RendererWebStorageAreaImpl::~RendererWebStorageAreaImpl() { | |
| 43 g_all_areas_map.Pointer()->Remove(connection_id_); | |
| 44 RenderThreadImpl::current()->Send( | |
| 45 new DOMStorageHostMsg_CloseStorageArea(connection_id_)); | |
| 46 } | |
| 47 | |
| 48 // In November 2011 stats were recorded about performance of each of the | |
| 49 // DOMStorage operations. Results of median, 99% quantile, and 99.9% quantile | |
| 50 // are provided in milliseconds. The ratio of number of calls for each operation | |
| 51 // relative to the number of calls to getItem is also provided. | |
| 52 // | |
| 53 // Operation Freq 50% 99% 99.9% | |
| 54 // ------------------------------------------- | |
| 55 // getItem 1.00 0.6 2.0 27.9 | |
| 56 // setItem .029 0.7 13.6 114.9 | |
| 57 // removeItem .003 0.9 11.8 90.7 | |
| 58 // length .017 0.6 2.0 12.0 | |
| 59 // key .591 0.6 2.0 29.9 | |
| 60 // clear 1e-6 1.0 32.4 605.2 | |
| 61 | |
| 62 unsigned RendererWebStorageAreaImpl::length() { | |
| 63 unsigned length; | |
| 64 RenderThreadImpl::current()->Send( | |
| 65 new DOMStorageHostMsg_Length(connection_id_, &length)); | |
| 66 return length; | |
| 67 } | |
| 68 | |
| 69 WebString RendererWebStorageAreaImpl::key(unsigned index) { | |
| 70 NullableString16 key; | |
| 71 RenderThreadImpl::current()->Send( | |
| 72 new DOMStorageHostMsg_Key(connection_id_, index, &key)); | |
| 73 return key; | |
| 74 } | |
| 75 | |
| 76 WebString RendererWebStorageAreaImpl::getItem(const WebString& key) { | |
| 77 NullableString16 value; | |
| 78 RenderThreadImpl::current()->Send( | |
| 79 new DOMStorageHostMsg_GetItem(connection_id_, key, &value)); | |
| 80 return value; | |
| 81 } | |
| 82 | |
| 83 void RendererWebStorageAreaImpl::setItem( | |
| 84 const WebString& key, const WebString& value, const WebURL& url, | |
| 85 WebStorageArea::Result& result, WebString& old_value_webkit) { | |
| 86 if (key.length() + value.length() > dom_storage::kPerAreaQuota) { | |
| 87 result = ResultBlockedByQuota; | |
| 88 return; | |
| 89 } | |
| 90 NullableString16 old_value; | |
| 91 RenderThreadImpl::current()->Send(new DOMStorageHostMsg_SetItem( | |
| 92 connection_id_, key, value, url, &result, &old_value)); | |
| 93 old_value_webkit = old_value; | |
| 94 } | |
| 95 | |
| 96 void RendererWebStorageAreaImpl::removeItem( | |
| 97 const WebString& key, const WebURL& url, WebString& old_value_webkit) { | |
| 98 NullableString16 old_value; | |
| 99 RenderThreadImpl::current()->Send( | |
| 100 new DOMStorageHostMsg_RemoveItem(connection_id_, key, url, &old_value)); | |
| 101 old_value_webkit = old_value; | |
| 102 } | |
| 103 | |
| 104 void RendererWebStorageAreaImpl::clear( | |
| 105 const WebURL& url, bool& cleared_something) { | |
| 106 RenderThreadImpl::current()->Send( | |
| 107 new DOMStorageHostMsg_Clear(connection_id_, url, &cleared_something)); | |
| 108 } | |
| OLD | NEW |