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

Side by Side Diff: webkit/dom_storage/dom_storage_area.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
OLDNEW
1 // Copyright (c) 2011 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/browser/in_process_webkit/dom_storage_area.h" 5 #include "webkit/dom_storage/dom_storage_area.h"
6 #include "webkit/dom_storage/dom_storage_map.h"
7 #include "webkit/dom_storage/dom_storage_namespace.h"
6 8
7 #include "base/logging.h" 9 namespace dom_storage {
8 #include "content/browser/in_process_webkit/dom_storage_context.h"
9 #include "content/browser/in_process_webkit/dom_storage_namespace.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
14 #include "webkit/glue/webkit_glue.h"
15 10
16 using WebKit::WebSecurityOrigin; 11 DomStorageArea::DomStorageArea(
17 using WebKit::WebStorageArea; 12 int64 namespace_id, const GURL& origin,
18 using WebKit::WebString; 13 const FilePath& directory, DomStorageTaskRunner* task_runner)
19 using WebKit::WebURL; 14 : namespace_id_(namespace_id), origin_(origin),
20 15 directory_(directory), task_runner_(task_runner),
21 DOMStorageArea::DOMStorageArea( 16 map_(new DomStorageMap()) {
22 const string16& origin,
23 int64 id,
24 DOMStorageNamespace* owner)
25 : origin_(origin),
26 origin_url_(origin),
27 id_(id),
28 owner_(owner) {
29 DCHECK(owner_);
30 } 17 }
31 18
32 DOMStorageArea::~DOMStorageArea() { 19 DomStorageArea::~DomStorageArea() {
33 } 20 }
34 21
35 unsigned DOMStorageArea::Length() { 22 unsigned DomStorageArea::Length() {
36 CreateWebStorageAreaIfNecessary(); 23 return map_->Length();
37 return storage_area_->length();
38 } 24 }
39 25
40 NullableString16 DOMStorageArea::Key(unsigned index) { 26 NullableString16 DomStorageArea::Key(unsigned index) {
41 CreateWebStorageAreaIfNecessary(); 27 return map_->Key(index);
42 return storage_area_->key(index);
43 } 28 }
44 29
45 NullableString16 DOMStorageArea::GetItem(const string16& key) { 30 NullableString16 DomStorageArea::GetItem(const string16& key) {
46 CreateWebStorageAreaIfNecessary(); 31 return map_->GetItem(key);
47 return storage_area_->getItem(key);
48 } 32 }
49 33
50 NullableString16 DOMStorageArea::SetItem( 34 bool DomStorageArea::SetItem(
51 const string16& key, const string16& value, 35 const string16& key, const string16& value,
52 WebStorageArea::Result* result) { 36 NullableString16* old_value) {
53 CreateWebStorageAreaIfNecessary(); 37 if (!map_->HasOneRef())
54 WebString old_value; 38 map_ = map_->DeepCopy();
55 storage_area_->setItem(key, value, WebURL(), *result, old_value); 39 return map_->SetItem(key, value, old_value);
56 return old_value;
57 } 40 }
58 41
59 NullableString16 DOMStorageArea::RemoveItem(const string16& key) { 42 bool DomStorageArea::RemoveItem(
60 CreateWebStorageAreaIfNecessary(); 43 const string16& key,
61 WebString old_value; 44 string16* old_value) {
62 storage_area_->removeItem(key, WebURL(), old_value); 45 if (!map_->HasOneRef())
63 return old_value; 46 map_ = map_->DeepCopy();
47 return map_->RemoveItem(key, old_value);
64 } 48 }
65 49
66 bool DOMStorageArea::Clear() { 50 bool DomStorageArea::Clear() {
67 CreateWebStorageAreaIfNecessary(); 51 if (map_->Length() == 0)
68 bool somethingCleared; 52 return false;
69 storage_area_->clear(WebURL(), somethingCleared); 53 map_ = new DomStorageMap();
70 return somethingCleared; 54 return true;
71 } 55 }
72 56
73 void DOMStorageArea::PurgeMemory() { 57 DomStorageArea* DomStorageArea::ShallowCopy(int64 destination_namespace_id) {
74 storage_area_.reset(); 58 DCHECK_NE(kLocalStorageNamespaceId, namespace_id_);
59 DCHECK_NE(kLocalStorageNamespaceId, destination_namespace_id);
60 // SessionNamespaces aren't backed by files on disk.
61 DomStorageArea* copy = new DomStorageArea(destination_namespace_id, origin_,
62 FilePath(), task_runner_);
63 copy->map_ = map_;
64 return copy;
75 } 65 }
76 66
77 void DOMStorageArea::CreateWebStorageAreaIfNecessary() { 67 } // namespace dom_storage
78 if (!storage_area_.get())
79 storage_area_.reset(owner_->CreateWebStorageArea(origin_));
80 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698