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

Side by Side Diff: webkit/dom_storage/dom_storage_database.h

Issue 9817011: DomStorage data deletion and memory purging. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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) 2012 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 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_
6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/nullable_string16.h" 14 #include "base/nullable_string16.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "sql/connection.h" 16 #include "sql/connection.h"
17 #include "webkit/dom_storage/dom_storage_types.h" 17 #include "webkit/dom_storage/dom_storage_types.h"
18 18
19 namespace dom_storage { 19 namespace dom_storage {
20 20
21 // Represents a SQLite based backing for DOM storage data. This 21 // Represents a SQLite based backing for DOM storage data. This
22 // class is designed to be used on a single thread. 22 // class is designed to be used on a single thread.
23 class DomStorageDatabase { 23 class DomStorageDatabase {
24 public: 24 public:
25 static FilePath GetJournalFilePath(const FilePath& database_path);
26
25 explicit DomStorageDatabase(const FilePath& file_path); 27 explicit DomStorageDatabase(const FilePath& file_path);
26 virtual ~DomStorageDatabase(); // virtual for unit testing 28 virtual ~DomStorageDatabase(); // virtual for unit testing
27 29
28 // Reads all the key, value pairs stored in the database and returns 30 // Reads all the key, value pairs stored in the database and returns
29 // them. |result| is assumed to be empty and any duplicate keys will 31 // them. |result| is assumed to be empty and any duplicate keys will
30 // be overwritten. If the database exists on disk then it will be 32 // be overwritten. If the database exists on disk then it will be
31 // opened. If it does not exist then it will not be created and 33 // opened. If it does not exist then it will not be created and
32 // |result| will be unmodified. 34 // |result| will be unmodified.
33 void ReadAllValues(ValuesMap* result); 35 void ReadAllValues(ValuesMap* result);
34 36
35 // Updates the backing database. Will remove all keys before updating 37 // Updates the backing database. Will remove all keys before updating
36 // the database if |clear_all_first| is set. Then all entries in 38 // the database if |clear_all_first| is set. Then all entries in
37 // |changes| will be examined - keys mapped to a null NullableString16 39 // |changes| will be examined - keys mapped to a null NullableString16
38 // will be removed and all others will be inserted/updated as appropriate. 40 // will be removed and all others will be inserted/updated as appropriate.
39 bool CommitChanges(bool clear_all_first, const ValuesMap& changes); 41 bool CommitChanges(bool clear_all_first, const ValuesMap& changes);
40 42
43 // Simple getter for the path we were constructed with.
44 const FilePath& file_path() const { return file_path_; }
45
41 protected: 46 protected:
42 // Constructor that uses an in-memory sqlite database, for testing. 47 // Constructor that uses an in-memory sqlite database, for testing.
43 DomStorageDatabase(); 48 DomStorageDatabase();
44 49
45 private: 50 private:
46 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleOpenAndClose); 51 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, SimpleOpenAndClose);
47 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestLazyOpenIsLazy); 52 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestLazyOpenIsLazy);
48 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestDetectSchemaVersion); 53 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, TestDetectSchemaVersion);
49 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest, 54 FRIEND_TEST_ALL_PREFIXES(DomStorageDatabaseTest,
50 TestLazyOpenUpgradesDatabase); 55 TestLazyOpenUpgradesDatabase);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // version 2. 98 // version 2.
94 bool UpgradeVersion1To2(); 99 bool UpgradeVersion1To2();
95 100
96 void Close(); 101 void Close();
97 bool IsOpen() const { return db_.get() ? db_->is_open() : false; } 102 bool IsOpen() const { return db_.get() ? db_->is_open() : false; }
98 103
99 // Initialization code shared between the two constructors of this class. 104 // Initialization code shared between the two constructors of this class.
100 void Init(); 105 void Init();
101 106
102 // Path to the database on disk. 107 // Path to the database on disk.
103 FilePath file_path_; 108 const FilePath file_path_;
104 scoped_ptr<sql::Connection> db_; 109 scoped_ptr<sql::Connection> db_;
105 bool failed_to_open_; 110 bool failed_to_open_;
106 bool tried_to_recreate_; 111 bool tried_to_recreate_;
107 bool known_to_be_empty_; 112 bool known_to_be_empty_;
108 }; 113 };
109 114
110 } // namespace dom_storage 115 } // namespace dom_storage
111 116
112 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_ 117 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698