1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/dom_storage/dom_storage_area.h"
#include "webkit/dom_storage/dom_storage_map.h"
#include "webkit/dom_storage/dom_storage_namespace.h"
namespace dom_storage {
DomStorageArea::DomStorageArea(
int64 namespace_id, const GURL& origin,
const FilePath& directory, DomStorageTaskRunner* task_runner)
: namespace_id_(namespace_id), origin_(origin),
directory_(directory), task_runner_(task_runner),
map_(new DomStorageMap()) {
}
DomStorageArea::~DomStorageArea() {
}
unsigned DomStorageArea::Length() {
return map_->Length();
}
NullableString16 DomStorageArea::Key(unsigned index) {
return map_->Key(index);
}
NullableString16 DomStorageArea::GetItem(const string16& key) {
return map_->GetItem(key);
}
bool DomStorageArea::SetItem(
const string16& key, const string16& value,
NullableString16* old_value) {
if (!map_->HasOneRef())
map_ = map_->DeepCopy();
return map_->SetItem(key, value, old_value);
}
bool DomStorageArea::RemoveItem(
const string16& key,
string16* old_value) {
if (!map_->HasOneRef())
map_ = map_->DeepCopy();
return map_->RemoveItem(key, old_value);
}
bool DomStorageArea::Clear() {
if (map_->Length() == 0)
return false;
map_ = new DomStorageMap();
return true;
}
DomStorageArea* DomStorageArea::ShallowCopy(int64 destination_namespace_id) {
DCHECK_NE(kLocalStorageNamespaceId, namespace_id_);
DCHECK_NE(kLocalStorageNamespaceId, destination_namespace_id);
// SessionNamespaces aren't backed by files on disk.
DomStorageArea* copy = new DomStorageArea(destination_namespace_id, origin_,
FilePath(), task_runner_);
copy->map_ = map_;
return copy;
}
} // namespace dom_storage
|