OLD | NEW |
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 #include "webkit/dom_storage/dom_storage_area.h" | 5 #include "webkit/dom_storage/dom_storage_area.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/tracked_objects.h" | 10 #include "base/tracked_objects.h" |
11 #include "webkit/dom_storage/dom_storage_map.h" | 11 #include "webkit/dom_storage/dom_storage_map.h" |
12 #include "webkit/dom_storage/dom_storage_namespace.h" | 12 #include "webkit/dom_storage/dom_storage_namespace.h" |
13 #include "webkit/dom_storage/dom_storage_task_runner.h" | 13 #include "webkit/dom_storage/dom_storage_task_runner.h" |
14 #include "webkit/dom_storage/dom_storage_types.h" | 14 #include "webkit/dom_storage/dom_storage_types.h" |
15 #include "webkit/fileapi/file_system_util.h" | 15 #include "webkit/fileapi/file_system_util.h" |
16 | 16 |
17 namespace dom_storage { | 17 namespace dom_storage { |
18 | 18 |
| 19 // static |
| 20 const FilePath::CharType DomStorageArea::kDatabaseFileExtension[] = |
| 21 FILE_PATH_LITERAL("localstorage"); |
| 22 |
| 23 // static |
| 24 FilePath DomStorageArea::DatabaseFileNameFromOrigin(const GURL& origin) { |
| 25 std::string filename = fileapi::GetOriginIdentifierFromURL(origin); |
| 26 return FilePath().AppendASCII(filename).ReplaceExtension( |
| 27 kDatabaseFileExtension); |
| 28 } |
| 29 |
19 DomStorageArea::DomStorageArea( | 30 DomStorageArea::DomStorageArea( |
20 int64 namespace_id, const GURL& origin, | 31 int64 namespace_id, const GURL& origin, |
21 const FilePath& directory, DomStorageTaskRunner* task_runner) | 32 const FilePath& directory, DomStorageTaskRunner* task_runner) |
22 : namespace_id_(namespace_id), origin_(origin), | 33 : namespace_id_(namespace_id), origin_(origin), |
23 directory_(directory), | 34 directory_(directory), |
24 task_runner_(task_runner), | 35 task_runner_(task_runner), |
25 map_(new DomStorageMap(kPerAreaQuota)), | 36 map_(new DomStorageMap(kPerAreaQuota)), |
26 backing_(NULL), | 37 backing_(NULL), |
27 initial_import_done_(false), | 38 initial_import_done_(false), |
28 clear_all_next_commit_(false), | 39 clear_all_next_commit_(false), |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 DCHECK_EQ(kLocalStorageNamespaceId, namespace_id_); | 155 DCHECK_EQ(kLocalStorageNamespaceId, namespace_id_); |
145 DCHECK(backing_.get()); | 156 DCHECK(backing_.get()); |
146 DCHECK(clear_all_next_commit_ || !changed_values_.empty()); | 157 DCHECK(clear_all_next_commit_ || !changed_values_.empty()); |
147 DCHECK(task_runner_.get()); | 158 DCHECK(task_runner_.get()); |
148 | 159 |
149 if (commit_in_flight_) | 160 if (commit_in_flight_) |
150 return; | 161 return; |
151 | 162 |
152 commit_in_flight_ = task_runner_->PostDelayedTask( | 163 commit_in_flight_ = task_runner_->PostDelayedTask( |
153 FROM_HERE, base::Bind(&DomStorageArea::CommitChanges, this), | 164 FROM_HERE, base::Bind(&DomStorageArea::CommitChanges, this), |
154 base::TimeDelta::FromSeconds(1)); | 165 base::TimeDelta::FromSeconds(60)); |
155 DCHECK(commit_in_flight_); | 166 DCHECK(commit_in_flight_); |
156 } | 167 } |
157 | 168 |
158 void DomStorageArea::CommitChanges() { | 169 void DomStorageArea::CommitChanges() { |
159 DCHECK(backing_.get()); | 170 DCHECK(backing_.get()); |
160 if (backing_->CommitChanges(clear_all_next_commit_, changed_values_)) { | 171 if (backing_->CommitChanges(clear_all_next_commit_, changed_values_)) { |
161 clear_all_next_commit_ = false; | 172 clear_all_next_commit_ = false; |
162 changed_values_.clear(); | 173 changed_values_.clear(); |
163 } | 174 } |
164 commit_in_flight_ = false; | 175 commit_in_flight_ = false; |
165 } | 176 } |
166 | 177 |
167 // static | |
168 FilePath DomStorageArea::DatabaseFileNameFromOrigin(const GURL& origin) { | |
169 std::string filename = fileapi::GetOriginIdentifierFromURL(origin) | |
170 + ".localstorage"; | |
171 return FilePath().AppendASCII(filename); | |
172 } | |
173 | |
174 } // namespace dom_storage | 178 } // namespace dom_storage |
OLD | NEW |