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
|
// 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/dom_storage/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/dom_storage/dom_storage_dispatcher.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_cached_area.h"
using dom_storage::DomStorageCachedArea;
using WebKit::WebString;
using WebKit::WebURL;
namespace {
typedef IDMap<WebStorageAreaImpl> AreaImplMap;
base::LazyInstance<AreaImplMap>::Leaky
g_all_areas_map = LAZY_INSTANCE_INITIALIZER;
DomStorageDispatcher* dispatcher() {
return RenderThreadImpl::current()->dom_storage_dispatcher();
}
} // namespace
// static
WebStorageAreaImpl* WebStorageAreaImpl::FromConnectionId(int id) {
return g_all_areas_map.Pointer()->Lookup(id);
}
WebStorageAreaImpl::WebStorageAreaImpl(
int64 namespace_id, const GURL& origin)
: ALLOW_THIS_IN_INITIALIZER_LIST(
connection_id_(g_all_areas_map.Pointer()->Add(this))),
cached_area_(dispatcher()->
OpenCachedArea(connection_id_, namespace_id, origin)) {
}
WebStorageAreaImpl::~WebStorageAreaImpl() {
g_all_areas_map.Pointer()->Remove(connection_id_);
if (dispatcher())
dispatcher()->CloseCachedArea(connection_id_, cached_area_);
}
unsigned WebStorageAreaImpl::length() {
return cached_area_->GetLength(connection_id_);
}
WebString WebStorageAreaImpl::key(unsigned index) {
return cached_area_->GetKey(connection_id_, index);
}
WebString WebStorageAreaImpl::getItem(const WebString& key) {
return cached_area_->GetItem(connection_id_, key);
}
void WebStorageAreaImpl::setItem(
const WebString& key, const WebString& value, const WebURL& page_url,
WebStorageArea::Result& result) {
if (!cached_area_->SetItem(connection_id_, key, value, page_url))
result = ResultBlockedByQuota;
else
result = ResultOK;
}
void WebStorageAreaImpl::removeItem(
const WebString& key, const WebURL& page_url) {
cached_area_->RemoveItem(connection_id_, key, page_url);
}
void WebStorageAreaImpl::clear(const WebURL& page_url) {
cached_area_->Clear(connection_id_, page_url);
}
size_t WebStorageAreaImpl::memoryBytesUsedByCache() const {
return cached_area_->MemoryBytesUsedByCache();
}
|