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

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, 11 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::GetKey(int connection_id, int index) {
48 DOMStorageArea* area = GetOpenArea(connection_id);
49 if (!area)
50 return NullableString16();
51 return area->Key(index);
52 }
53
54 NullableString16 DOMStorageHost::GetItem(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::SetItem(int connection_id, const string16& key,
63 const string16& value, const GURL& page_url,
64 NullableString16* old_value) {
65 DOMStorageArea* area = GetOpenArea(connection_id);
66 if (!area)
67 return false;
68 if (!area->SetItem(key, value, old_value))
69 return false;
70 context_->NotifyEventListeners();
71 return true;
72 }
73
74 bool DOMStorageHost::RemoveItem(int connection_id, const string16& key,
75 const GURL& page_url,
76 NullableString16* old_value) {
77 DOMStorageArea* area = GetOpenArea(connection_id);
78 if (!area)
79 return false;
80 if (!area->RemoveItem(key, old_value))
81 return false;
82 context_->NotifyEventListeners();
83 return true;
84 }
85
86 bool DOMStorageHost::ClearArea(int connection_id, const GURL& page_url) {
87 DOMStorageArea* area = GetOpenArea(connection_id);
88 if (!area)
89 return false;
90 if (!area->Clear())
91 return false;
92 context_->NotifyEventListeners();
93 return true;
94 }
95
96 DOMStorageArea* DOMStorageHost::GetOpenArea(int connection_id) {
97 AreaMap::iterator found = connections_.find(connection_id);
98 if (found == connections_.end())
99 return NULL;
100 return found->second;
101 }
102
103 } // namespace dom_storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698