blob: ba26d60d37539aef34665ff2326a61304ff86779 (
plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// 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.
#ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_
#define WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_
#pragma once
#include "base/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
#include "base/nullable_string16.h"
#include "base/string16.h"
#include "googleurl/src/gurl.h"
#include "webkit/dom_storage/dom_storage_database.h"
#include "webkit/dom_storage/dom_storage_types.h"
namespace dom_storage {
class DomStorageMap;
class DomStorageTaskRunner;
// Container for a per-origin Map of key/value pairs potentially
// backed by storage on disk and lazily commits changes to disk.
// See class comments for DomStorageContext for a larger overview.
class DomStorageArea
: public base::RefCountedThreadSafe<DomStorageArea> {
public:
DomStorageArea(int64 namespace_id,
const GURL& origin,
const FilePath& directory,
DomStorageTaskRunner* task_runner);
const GURL& origin() const { return origin_; }
int64 namespace_id() const { return namespace_id_; }
unsigned Length();
NullableString16 Key(unsigned index);
NullableString16 GetItem(const string16& key);
bool SetItem(const string16& key, const string16& value,
NullableString16* old_value);
bool RemoveItem(const string16& key, string16* old_value);
bool Clear();
DomStorageArea* ShallowCopy(int64 destination_namespace_id);
private:
FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics);
FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened);
FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath);
friend class base::RefCountedThreadSafe<DomStorageArea>;
// If we haven't done so already and this is a local storage area,
// will attempt to read any values for this origin currently
// stored on disk.
void InitialImportIfNeeded();
// Posts a task to write the set of changed values to disk.
void ScheduleCommitChanges();
void CommitChanges();
static FilePath DatabaseFileNameFromOrigin(const GURL& origin);
~DomStorageArea();
int64 namespace_id_;
GURL origin_;
FilePath directory_;
scoped_refptr<DomStorageTaskRunner> task_runner_;
scoped_refptr<DomStorageMap> map_;
scoped_ptr<DomStorageDatabase> backing_;
bool initial_import_done_;
ValuesMap changed_values_;
bool clear_all_next_commit_;
bool commit_in_flight_;
};
} // namespace dom_storage
#endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_
|