Make USB permissions work in the new permission message system
[chromium-blink-merge.git] / content / renderer / dom_storage / webstoragearea_impl.cc
blobc3075352dd553844023e2de3cb870cfb7af5ecc8
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.
5 #include "content/renderer/dom_storage/webstoragearea_impl.h"
7 #include "base/lazy_instance.h"
8 #include "base/metrics/histogram.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "base/time/time.h"
11 #include "content/common/dom_storage/dom_storage_messages.h"
12 #include "content/renderer/dom_storage/dom_storage_cached_area.h"
13 #include "content/renderer/dom_storage/dom_storage_dispatcher.h"
14 #include "content/renderer/render_thread_impl.h"
15 #include "third_party/WebKit/public/platform/WebURL.h"
17 using blink::WebString;
18 using blink::WebURL;
20 namespace content {
22 namespace {
23 typedef IDMap<WebStorageAreaImpl> AreaImplMap;
24 base::LazyInstance<AreaImplMap>::Leaky
25 g_all_areas_map = LAZY_INSTANCE_INITIALIZER;
27 DomStorageDispatcher* dispatcher() {
28 return RenderThreadImpl::current()->dom_storage_dispatcher();
30 } // namespace
32 // static
33 WebStorageAreaImpl* WebStorageAreaImpl::FromConnectionId(int id) {
34 return g_all_areas_map.Pointer()->Lookup(id);
37 WebStorageAreaImpl::WebStorageAreaImpl(
38 int64 namespace_id, const GURL& origin)
39 : connection_id_(g_all_areas_map.Pointer()->Add(this)),
40 cached_area_(dispatcher()->
41 OpenCachedArea(connection_id_, namespace_id, origin)) {
44 WebStorageAreaImpl::~WebStorageAreaImpl() {
45 g_all_areas_map.Pointer()->Remove(connection_id_);
46 if (dispatcher())
47 dispatcher()->CloseCachedArea(connection_id_, cached_area_.get());
50 unsigned WebStorageAreaImpl::length() {
51 return cached_area_->GetLength(connection_id_);
54 WebString WebStorageAreaImpl::key(unsigned index) {
55 return cached_area_->GetKey(connection_id_, index);
58 WebString WebStorageAreaImpl::getItem(const WebString& key) {
59 return cached_area_->GetItem(connection_id_, key);
62 void WebStorageAreaImpl::setItem(
63 const WebString& key, const WebString& value, const WebURL& page_url,
64 WebStorageArea::Result& result) {
65 if (!cached_area_->SetItem(connection_id_, key, value, page_url))
66 result = ResultBlockedByQuota;
67 else
68 result = ResultOK;
71 void WebStorageAreaImpl::removeItem(
72 const WebString& key, const WebURL& page_url) {
73 cached_area_->RemoveItem(connection_id_, key, page_url);
76 void WebStorageAreaImpl::clear(const WebURL& page_url) {
77 cached_area_->Clear(connection_id_, page_url);
80 size_t WebStorageAreaImpl::memoryBytesUsedByCache() const {
81 return cached_area_->MemoryBytesUsedByCache();
84 } // namespace content