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

Side by Side Diff: webkit/dom_storage/dom_storage_host.cc

Issue 9146025: Framing for a DOMStorage backend that does not depend on in-process-webkit. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 10 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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.
4
5 #include "webkit/dom_storage/dom_storage_host.h"
6
7 #include "googleurl/src/gurl.h"
8 #include "webkit/dom_storage/dom_storage_area.h"
9 #include "webkit/dom_storage/dom_storage_context.h"
10 #include "webkit/dom_storage/dom_storage_namespace.h"
11
12 namespace dom_storage {
13
14 DomStorageHost::DomStorageHost(DomStorageContext* context)
15 : last_connection_id_(0),
16 context_(context) {
17 }
18
19 DomStorageHost::~DomStorageHost() {
20 }
21
22 // TODO(michaeln): have the caller pass in the 'connection_id' value
23 // instead of generating them here, avoids a sync ipc on open.
24 int DomStorageHost::OpenStorageArea(int namespace_id, const GURL& origin) {
25 DomStorageNamespace* name_space = context_->GetStorageNamespace(namespace_id);
26 if (!name_space)
27 return -1;
28 DomStorageArea* area = name_space->GetStorageArea(origin);
29 if (!area)
30 return -1;
31 int id = ++last_connection_id_;
32 connections_[id] = area;
33 return id;
34 }
35
36 void DomStorageHost::CloseStorageArea(int connection_id) {
37 connections_.erase(connection_id);
38 }
39
40 int DomStorageHost::GetAreaLength(int connection_id) {
41 DomStorageArea* area = GetOpenArea(connection_id);
42 if (!area)
43 return 0;
44 return area->Length();
45 }
46
47 NullableString16 DomStorageHost::GetAreaKey(int connection_id, int index) {
48 DomStorageArea* area = GetOpenArea(connection_id);
49 if (!area)
50 return NullableString16();
benm (inactive) 2012/01/31 18:03:38 NullableString16 is not null by default... think y
michaeln 2012/01/31 21:17:45 Done here and below
51 return area->Key(index);
52 }
53
54 NullableString16 DomStorageHost::GetAreaItem(int connection_id,
55 const string16& key) {
56 DomStorageArea* area = GetOpenArea(connection_id);
57 if (!area)
58 return NullableString16();
59 return area->GetItem(key);
60 }
61
62 bool DomStorageHost::SetAreaItem(
63 int connection_id, const string16& key,
64 const string16& value, const GURL& page_url,
65 NullableString16* old_value) {
66 DomStorageArea* area = GetOpenArea(connection_id);
67 if (!area)
68 return false;
69 if (!area->SetItem(key, value, old_value))
70 return false;
71 context_->NotifyItemSet(area, key, value, *old_value, page_url);
72 return true;
73 }
74
75 bool DomStorageHost::RemoveAreaItem(int connection_id, const string16& key,
76 const GURL& page_url,
77 string16* old_value) {
78 DomStorageArea* area = GetOpenArea(connection_id);
79 if (!area)
80 return false;
81 if (!area->RemoveItem(key, old_value))
82 return false;
83 context_->NotifyItemRemoved(area, key, *old_value, page_url);
84 return true;
85 }
86
87 bool DomStorageHost::ClearArea(int connection_id, const GURL& page_url) {
88 DomStorageArea* area = GetOpenArea(connection_id);
89 if (!area)
90 return false;
91 if (!area->Clear())
92 return false;
93 context_->NotifyAreaCleared(area, page_url);
94 return true;
95 }
96
97 DomStorageArea* DomStorageHost::GetOpenArea(int connection_id) {
98 AreaMap::iterator found = connections_.find(connection_id);
99 if (found == connections_.end())
100 return NULL;
101 return found->second;
102 }
103
104 } // namespace dom_storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698