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