OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/in_process_webkit/dom_storage_context.h" | 5 #include "content/browser/in_process_webkit/dom_storage_context.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
45 file_util::Delete(file_path, false); | 45 file_util::Delete(file_path, false); |
46 } | 46 } |
47 } | 47 } |
48 } | 48 } |
49 | 49 |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 const FilePath::CharType DOMStorageContext::kLocalStorageDirectory[] = | 52 const FilePath::CharType DOMStorageContext::kLocalStorageDirectory[] = |
53 FILE_PATH_LITERAL("Local Storage"); | 53 FILE_PATH_LITERAL("Local Storage"); |
54 | 54 |
55 const FilePath::CharType DOMStorageContext::kSessionStorageDirectory[] = | |
56 FILE_PATH_LITERAL("Session Storage"); | |
57 | |
55 const FilePath::CharType DOMStorageContext::kLocalStorageExtension[] = | 58 const FilePath::CharType DOMStorageContext::kLocalStorageExtension[] = |
56 FILE_PATH_LITERAL(".localstorage"); | 59 FILE_PATH_LITERAL(".localstorage"); |
57 | 60 |
58 DOMStorageContext::DOMStorageContext( | 61 DOMStorageContext::DOMStorageContext( |
59 WebKitContext* webkit_context, | 62 WebKitContext* webkit_context, |
60 quota::SpecialStoragePolicy* special_storage_policy) | 63 quota::SpecialStoragePolicy* special_storage_policy) |
61 : last_storage_area_id_(0), | 64 : last_storage_area_id_(0), |
62 last_session_storage_namespace_id_on_ui_thread_(kLocalStorageNamespaceId), | 65 last_session_storage_namespace_id_on_ui_thread_(kLocalStorageNamespaceId), |
63 last_session_storage_namespace_id_on_io_thread_(kLocalStorageNamespaceId), | 66 last_session_storage_namespace_id_on_io_thread_(kLocalStorageNamespaceId), |
64 clear_local_state_on_exit_(false), | 67 clear_local_state_on_exit_(false), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 StorageNamespaceMap::iterator iter = storage_namespace_map_.find(id); | 160 StorageNamespaceMap::iterator iter = storage_namespace_map_.find(id); |
158 if (iter != storage_namespace_map_.end()) | 161 if (iter != storage_namespace_map_.end()) |
159 return iter->second; | 162 return iter->second; |
160 if (!allocation_allowed) | 163 if (!allocation_allowed) |
161 return NULL; | 164 return NULL; |
162 if (id == kLocalStorageNamespaceId) | 165 if (id == kLocalStorageNamespaceId) |
163 return CreateLocalStorage(); | 166 return CreateLocalStorage(); |
164 return CreateSessionStorage(id); | 167 return CreateSessionStorage(id); |
165 } | 168 } |
166 | 169 |
170 DOMStorageNamespace* DOMStorageContext::RecreateSessionStorageNamespace( | |
171 int64 id, | |
172 const FilePath& session_storage_directory) { | |
173 FilePath dir_path; | |
174 if (!data_path_.empty()) { | |
175 dir_path = data_path_.Append(kSessionStorageDirectory) | |
michaeln
2011/12/13 20:40:03
in what circumstances is data_path_ empty, i'm gue
marja
2012/01/11 15:17:53
Yes.
| |
176 .Append(session_storage_directory); | |
177 } | |
178 DOMStorageNamespace* new_namespace = | |
179 DOMStorageNamespace::CreateSessionStorageNamespace(this, dir_path, id); | |
180 RegisterStorageNamespace(new_namespace); | |
181 return new_namespace; | |
182 } | |
183 | |
167 void DOMStorageContext::RegisterMessageFilter( | 184 void DOMStorageContext::RegisterMessageFilter( |
168 DOMStorageMessageFilter* message_filter) { | 185 DOMStorageMessageFilter* message_filter) { |
169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
170 DCHECK(message_filter_set_.find(message_filter) == | 187 DCHECK(message_filter_set_.find(message_filter) == |
171 message_filter_set_.end()); | 188 message_filter_set_.end()); |
172 message_filter_set_.insert(message_filter); | 189 message_filter_set_.insert(message_filter); |
173 } | 190 } |
174 | 191 |
175 void DOMStorageContext::UnregisterMessageFilter( | 192 void DOMStorageContext::UnregisterMessageFilter( |
176 DOMStorageMessageFilter* message_filter) { | 193 DOMStorageMessageFilter* message_filter) { |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 if (!data_path_.empty()) | 275 if (!data_path_.empty()) |
259 dir_path = data_path_.Append(kLocalStorageDirectory); | 276 dir_path = data_path_.Append(kLocalStorageDirectory); |
260 DOMStorageNamespace* new_namespace = | 277 DOMStorageNamespace* new_namespace = |
261 DOMStorageNamespace::CreateLocalStorageNamespace(this, dir_path); | 278 DOMStorageNamespace::CreateLocalStorageNamespace(this, dir_path); |
262 RegisterStorageNamespace(new_namespace); | 279 RegisterStorageNamespace(new_namespace); |
263 return new_namespace; | 280 return new_namespace; |
264 } | 281 } |
265 | 282 |
266 DOMStorageNamespace* DOMStorageContext::CreateSessionStorage( | 283 DOMStorageNamespace* DOMStorageContext::CreateSessionStorage( |
267 int64 namespace_id) { | 284 int64 namespace_id) { |
285 FilePath dir_path; | |
286 if (!data_path_.empty()) { | |
287 // We cannot use derive the directory name for the sessionStorage databases | |
jochen (gone - plz use gerrit)
2011/12/13 13:47:32
remove "use"
marja
2012/01/11 15:17:53
Done.
| |
288 // directly from |namespace_id|. There is no guarantee that the same | |
289 // directory won't be created before we restore the session. | |
michaeln
2011/12/13 20:40:03
can you say more about the latter part of the comm
marja
2012/01/11 15:17:53
This was inaccurate, changed it to "There is no gu
| |
290 file_util::CreateDirectory(data_path_.Append(kSessionStorageDirectory)); | |
291 file_util::CreateTemporaryDirInDir( | |
292 data_path_.Append(kSessionStorageDirectory), "", &dir_path); | |
michaeln
2011/12/13 20:40:03
where/when are these directories deleted?
marja
2012/01/11 15:17:53
The deletion code is not yet in this CL, but the d
| |
293 } | |
268 DOMStorageNamespace* new_namespace = | 294 DOMStorageNamespace* new_namespace = |
269 DOMStorageNamespace::CreateSessionStorageNamespace(this, namespace_id); | 295 DOMStorageNamespace::CreateSessionStorageNamespace(this, dir_path, |
296 namespace_id); | |
270 RegisterStorageNamespace(new_namespace); | 297 RegisterStorageNamespace(new_namespace); |
271 return new_namespace; | 298 return new_namespace; |
272 } | 299 } |
273 | 300 |
274 void DOMStorageContext::RegisterStorageNamespace( | 301 void DOMStorageContext::RegisterStorageNamespace( |
275 DOMStorageNamespace* storage_namespace) { | 302 DOMStorageNamespace* storage_namespace) { |
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); | 303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)); |
277 int64 id = storage_namespace->id(); | 304 int64 id = storage_namespace->id(); |
278 DCHECK(!GetStorageNamespace(id, false)); | 305 DCHECK(!GetStorageNamespace(id, false)); |
279 storage_namespace_map_[id] = storage_namespace; | 306 storage_namespace_map_[id] = storage_namespace; |
(...skipping 11 matching lines...) Expand all Loading... | |
291 } | 318 } |
292 | 319 |
293 FilePath DOMStorageContext::GetLocalStorageFilePath( | 320 FilePath DOMStorageContext::GetLocalStorageFilePath( |
294 const string16& origin_id) const { | 321 const string16& origin_id) const { |
295 FilePath storageDir = data_path_.Append( | 322 FilePath storageDir = data_path_.Append( |
296 DOMStorageContext::kLocalStorageDirectory); | 323 DOMStorageContext::kLocalStorageDirectory); |
297 FilePath::StringType id = | 324 FilePath::StringType id = |
298 webkit_glue::WebStringToFilePathString(origin_id); | 325 webkit_glue::WebStringToFilePathString(origin_id); |
299 return storageDir.Append(id.append(kLocalStorageExtension)); | 326 return storageDir.Append(id.append(kLocalStorageExtension)); |
300 } | 327 } |
OLD | NEW |