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

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

Issue 9718029: DomStorage commit task sequencing. (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_AREA_H_ 5 #ifndef WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_
6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ 6 #define WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "base/nullable_string16.h" 12 #include "base/nullable_string16.h"
13 #include "base/string16.h" 13 #include "base/string16.h"
14 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
15 #include "webkit/dom_storage/dom_storage_database.h" 15 #include "webkit/dom_storage/dom_storage_database.h"
16 #include "webkit/dom_storage/dom_storage_types.h" 16 #include "webkit/dom_storage/dom_storage_types.h"
17 17
18 namespace dom_storage { 18 namespace dom_storage {
19 19
20 class DomStorageMap; 20 class DomStorageMap;
21 class DomStorageTaskRunner; 21 class DomStorageTaskRunner;
22 22
23 // Container for a per-origin Map of key/value pairs potentially 23 // Container for a per-origin Map of key/value pairs potentially
24 // backed by storage on disk and lazily commits changes to disk. 24 // backed by storage on disk and lazily commits changes to disk.
25 // See class comments for DomStorageContext for a larger overview. 25 // See class comments for DomStorageContext for a larger overview.
26 class DomStorageArea 26 class DomStorageArea
27 : public base::RefCountedThreadSafe<DomStorageArea> { 27 : public base::RefCountedThreadSafe<DomStorageArea> {
28 28
29 public: 29 public:
30 static FilePath DatabaseFileNameFromOrigin(const GURL& origin);
benm (inactive) 2012/03/19 14:22:53 Why is this public now?
michaeln 2012/03/19 16:04:42 This change really belongs in https://chromiumcode
31 static const FilePath::CharType kDatabaseFileExtension[];
32
30 DomStorageArea(int64 namespace_id, 33 DomStorageArea(int64 namespace_id,
31 const GURL& origin, 34 const GURL& origin,
32 const FilePath& directory, 35 const FilePath& directory,
33 DomStorageTaskRunner* task_runner); 36 DomStorageTaskRunner* task_runner);
34 37
35 const GURL& origin() const { return origin_; } 38 const GURL& origin() const { return origin_; }
36 int64 namespace_id() const { return namespace_id_; } 39 int64 namespace_id() const { return namespace_id_; }
37 40
38 unsigned Length(); 41 unsigned Length();
39 NullableString16 Key(unsigned index); 42 NullableString16 Key(unsigned index);
40 NullableString16 GetItem(const string16& key); 43 NullableString16 GetItem(const string16& key);
41 bool SetItem(const string16& key, const string16& value, 44 bool SetItem(const string16& key, const string16& value,
42 NullableString16* old_value); 45 NullableString16* old_value);
43 bool RemoveItem(const string16& key, string16* old_value); 46 bool RemoveItem(const string16& key, string16* old_value);
44 bool Clear(); 47 bool Clear();
45 48
46 DomStorageArea* ShallowCopy(int64 destination_namespace_id); 49 DomStorageArea* ShallowCopy(int64 destination_namespace_id);
47 50
51 void Shutdown();
52
48 private: 53 private:
49 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics); 54 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, DomStorageAreaBasics);
50 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened); 55 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, BackingDatabaseOpened);
51 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath); 56 FRIEND_TEST_ALL_PREFIXES(DomStorageAreaTest, TestDatabaseFilePath);
52 friend class base::RefCountedThreadSafe<DomStorageArea>; 57 friend class base::RefCountedThreadSafe<DomStorageArea>;
53 58
59 struct CommitBatch;
60
54 // If we haven't done so already and this is a local storage area, 61 // If we haven't done so already and this is a local storage area,
55 // will attempt to read any values for this origin currently 62 // will attempt to read any values for this origin currently
56 // stored on disk. 63 // stored on disk.
57 void InitialImportIfNeeded(); 64 void InitialImportIfNeeded();
58 65
59 // Posts a task to write the set of changed values to disk. 66 // Post tasks to defer writing a batch of changed values to
60 void ScheduleCommitChanges(); 67 // disk on the commit sequence, and to call back on the main
68 // task sequence when complete.
69 CommitBatch* GetCommitBatch();
70 void OnCommitTimer();
61 void CommitChanges(); 71 void CommitChanges();
62 72 void OnCommitComplete();
63 static FilePath DatabaseFileNameFromOrigin(const GURL& origin); 73 void CommitShutdownChanges();
64 74
65 ~DomStorageArea(); 75 ~DomStorageArea();
66 76
67 int64 namespace_id_; 77 int64 namespace_id_;
68 GURL origin_; 78 GURL origin_;
69 FilePath directory_; 79 FilePath directory_;
70 scoped_refptr<DomStorageTaskRunner> task_runner_; 80 scoped_refptr<DomStorageTaskRunner> task_runner_;
71 scoped_refptr<DomStorageMap> map_; 81 scoped_refptr<DomStorageMap> map_;
72 scoped_ptr<DomStorageDatabase> backing_; 82 scoped_ptr<DomStorageDatabase> backing_;
73 bool initial_import_done_; 83 bool is_initial_import_done_;
74 ValuesMap changed_values_; 84 bool is_shutdown_;
75 bool clear_all_next_commit_; 85
76 bool commit_in_flight_; 86 scoped_ptr<CommitBatch> commit_batch_;
87 scoped_ptr<CommitBatch> in_flight_commit_batch_;
77 }; 88 };
78 89
79 } // namespace dom_storage 90 } // namespace dom_storage
80 91
81 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_ 92 #endif // WEBKIT_DOM_STORAGE_DOM_STORAGE_AREA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698