Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1812)

Side by Side Diff: content/renderer/dom_storage/webstoragearea_impl.cc

Issue 10383123: Switch to using the async DomStorage IPC messages and add a caching layer … (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/dom_storage/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/dom_storage/dom_storage_dispatcher.h"
12 #include "content/renderer/render_thread_impl.h" 13 #include "content/renderer/render_thread_impl.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
14 #include "webkit/dom_storage/dom_storage_types.h" 15 #include "webkit/dom_storage/dom_storage_cached_area.h"
15 16
17 using dom_storage::DomStorageCachedArea;
16 using WebKit::WebString; 18 using WebKit::WebString;
17 using WebKit::WebURL; 19 using WebKit::WebURL;
18 20
21 namespace {
19 typedef IDMap<WebStorageAreaImpl> AreaImplMap; 22 typedef IDMap<WebStorageAreaImpl> AreaImplMap;
20 23 base::LazyInstance<AreaImplMap>::Leaky
21 static base::LazyInstance<AreaImplMap>::Leaky
22 g_all_areas_map = LAZY_INSTANCE_INITIALIZER; 24 g_all_areas_map = LAZY_INSTANCE_INITIALIZER;
23 25
26 DomStorageDispatcher* dispatcher() {
27 return RenderThreadImpl::current()->dom_storage_dispatcher();
28 }
29 } // namespace
30
24 // static 31 // static
25 WebStorageAreaImpl* WebStorageAreaImpl::FromConnectionId( 32 WebStorageAreaImpl* WebStorageAreaImpl::FromConnectionId(int id) {
26 int id) {
27 return g_all_areas_map.Pointer()->Lookup(id); 33 return g_all_areas_map.Pointer()->Lookup(id);
28 } 34 }
29 35
30 WebStorageAreaImpl::WebStorageAreaImpl( 36 WebStorageAreaImpl::WebStorageAreaImpl(
31 int64 namespace_id, const GURL& origin) 37 int64 namespace_id, const GURL& origin)
32 : ALLOW_THIS_IN_INITIALIZER_LIST( 38 : ALLOW_THIS_IN_INITIALIZER_LIST(
33 connection_id_(g_all_areas_map.Pointer()->Add(this))) { 39 connection_id_(g_all_areas_map.Pointer()->Add(this))),
34 DCHECK(connection_id_); 40 cached_area_(dispatcher()->
35 RenderThreadImpl::current()->Send( 41 OpenCachedArea(connection_id_, namespace_id, origin)) {
36 new DOMStorageHostMsg_OpenStorageArea(
37 connection_id_, namespace_id, origin));
38 } 42 }
39 43
40 WebStorageAreaImpl::~WebStorageAreaImpl() { 44 WebStorageAreaImpl::~WebStorageAreaImpl() {
41 g_all_areas_map.Pointer()->Remove(connection_id_); 45 g_all_areas_map.Pointer()->Remove(connection_id_);
42 RenderThreadImpl::current()->Send( 46 if (dispatcher())
43 new DOMStorageHostMsg_CloseStorageArea(connection_id_)); 47 dispatcher()->CloseCachedArea(connection_id_, cached_area_);
44 } 48 }
45 49
46 // In November 2011 stats were recorded about performance of each of the
47 // DOMStorage operations. Results of median, 99% quantile, and 99.9% quantile
48 // are provided in milliseconds. The ratio of number of calls for each operation
49 // relative to the number of calls to getItem is also provided.
50 //
51 // Operation Freq 50% 99% 99.9%
52 // -------------------------------------------
53 // getItem 1.00 0.6 2.0 27.9
54 // setItem .029 0.7 13.6 114.9
55 // removeItem .003 0.9 11.8 90.7
56 // length .017 0.6 2.0 12.0
57 // key .591 0.6 2.0 29.9
58 // clear 1e-6 1.0 32.4 605.2
59
60 unsigned WebStorageAreaImpl::length() { 50 unsigned WebStorageAreaImpl::length() {
61 unsigned length; 51 return cached_area_->GetLength(connection_id_);
62 RenderThreadImpl::current()->Send(
63 new DOMStorageHostMsg_Length(connection_id_, &length));
64 return length;
65 } 52 }
66 53
67 WebString WebStorageAreaImpl::key(unsigned index) { 54 WebString WebStorageAreaImpl::key(unsigned index) {
68 NullableString16 key; 55 return cached_area_->GetKey(connection_id_, index);
69 RenderThreadImpl::current()->Send(
70 new DOMStorageHostMsg_Key(connection_id_, index, &key));
71 return key;
72 } 56 }
73 57
74 WebString WebStorageAreaImpl::getItem(const WebString& key) { 58 WebString WebStorageAreaImpl::getItem(const WebString& key) {
75 NullableString16 value; 59 return cached_area_->GetItem(connection_id_, key);
76 RenderThreadImpl::current()->Send(
77 new DOMStorageHostMsg_GetItem(connection_id_, key, &value));
78 return value;
79 } 60 }
80 61
81 void WebStorageAreaImpl::setItem( 62 void WebStorageAreaImpl::setItem(
82 const WebString& key, const WebString& value, const WebURL& url, 63 const WebString& key, const WebString& value, const WebURL& page_url,
83 WebStorageArea::Result& result, WebString& old_value_webkit) { 64 WebStorageArea::Result& result) {
84 if (key.length() + value.length() > dom_storage::kPerAreaQuota) { 65 if (!cached_area_->SetItem(connection_id_, key, value, page_url))
85 result = ResultBlockedByQuota; 66 result = ResultBlockedByQuota;
86 return; 67 else
87 } 68 result = ResultOK;
88 NullableString16 old_value;
89 RenderThreadImpl::current()->Send(new DOMStorageHostMsg_SetItem(
90 connection_id_, key, value, url, &result, &old_value));
91 old_value_webkit = old_value;
92 } 69 }
93 70
94 void WebStorageAreaImpl::removeItem( 71 void WebStorageAreaImpl::removeItem(
95 const WebString& key, const WebURL& url, WebString& old_value_webkit) { 72 const WebString& key, const WebURL& page_url) {
96 NullableString16 old_value; 73 cached_area_->RemoveItem(connection_id_, key, page_url);
97 RenderThreadImpl::current()->Send(
98 new DOMStorageHostMsg_RemoveItem(connection_id_, key, url, &old_value));
99 old_value_webkit = old_value;
100 } 74 }
101 75
102 void WebStorageAreaImpl::clear( 76 void WebStorageAreaImpl::clear(const WebURL& page_url) {
103 const WebURL& url, bool& cleared_something) { 77 cached_area_->Clear(connection_id_, page_url);
104 RenderThreadImpl::current()->Send(
105 new DOMStorageHostMsg_Clear(connection_id_, url, &cleared_something));
106 } 78 }
OLDNEW
« no previous file with comments | « content/renderer/dom_storage/webstoragearea_impl.h ('k') | content/renderer/render_thread_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698