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