OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #include "content/browser/in_process_webkit/dom_storage_namespace.h" | 5 #include "content/browser/in_process_webkit/dom_storage_namespace.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "content/browser/in_process_webkit/dom_storage_area.h" | 8 #include "content/browser/in_process_webkit/dom_storage_area.h" |
9 #include "content/browser/in_process_webkit/dom_storage_context.h" | 9 #include "content/browser/in_process_webkit/dom_storage_context.h" |
10 #include "content/browser/in_process_webkit/dom_storage_message_filter.h" | 10 #include "content/browser/in_process_webkit/dom_storage_message_filter.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageArea.h" |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h
" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebStorageNamespace.h
" |
13 #include "webkit/glue/webkit_glue.h" | 13 #include "webkit/glue/webkit_glue.h" |
14 | 14 |
15 using WebKit::WebStorageArea; | 15 using WebKit::WebStorageArea; |
16 using WebKit::WebStorageNamespace; | 16 using WebKit::WebStorageNamespace; |
17 using WebKit::WebString; | 17 using WebKit::WebString; |
18 | 18 |
19 /* static */ | 19 /* static */ |
20 DOMStorageNamespace* DOMStorageNamespace::CreateLocalStorageNamespace( | 20 DOMStorageNamespace* DOMStorageNamespace::CreateLocalStorageNamespace( |
21 DOMStorageContext* dom_storage_context, const FilePath& data_dir_path) { | 21 DOMStorageContext* dom_storage_context, const FilePath& data_dir_path) { |
22 int64 id = kLocalStorageNamespaceId; | 22 int64 id = kLocalStorageNamespaceId; |
23 DCHECK(!dom_storage_context->GetStorageNamespace(id, false)); | 23 DCHECK(!dom_storage_context->GetStorageNamespace(id, false)); |
24 return new DOMStorageNamespace(dom_storage_context, id, | 24 return new DOMStorageNamespace(dom_storage_context, id, FilePath(""), |
25 webkit_glue::FilePathToWebString(data_dir_path), DOM_STORAGE_LOCAL); | 25 webkit_glue::FilePathToWebString(data_dir_path), DOM_STORAGE_LOCAL); |
26 } | 26 } |
27 | 27 |
28 /* static */ | 28 /* static */ |
29 DOMStorageNamespace* DOMStorageNamespace::CreateSessionStorageNamespace( | 29 DOMStorageNamespace* DOMStorageNamespace::CreateSessionStorageNamespace( |
30 DOMStorageContext* dom_storage_context, int64 id) { | 30 DOMStorageContext* dom_storage_context, const FilePath& data_dir_path, |
| 31 int64 id) { |
31 DCHECK(!dom_storage_context->GetStorageNamespace(id, false)); | 32 DCHECK(!dom_storage_context->GetStorageNamespace(id, false)); |
32 return new DOMStorageNamespace(dom_storage_context, id, WebString(), | 33 return new DOMStorageNamespace( |
33 DOM_STORAGE_SESSION); | 34 dom_storage_context, id, data_dir_path.BaseName(), |
| 35 webkit_glue::FilePathToWebString(data_dir_path), DOM_STORAGE_SESSION); |
34 } | 36 } |
35 | 37 |
36 DOMStorageNamespace::DOMStorageNamespace(DOMStorageContext* dom_storage_context, | 38 DOMStorageNamespace::DOMStorageNamespace( |
37 int64 id, | 39 DOMStorageContext* dom_storage_context, |
38 const WebString& data_dir_path, | 40 int64 id, |
39 DOMStorageType dom_storage_type) | 41 const FilePath& session_storage_directory, |
| 42 const WebString& data_dir_path, |
| 43 DOMStorageType dom_storage_type) |
40 : dom_storage_context_(dom_storage_context), | 44 : dom_storage_context_(dom_storage_context), |
41 id_(id), | 45 id_(id), |
| 46 session_storage_directory_(session_storage_directory), |
42 data_dir_path_(data_dir_path), | 47 data_dir_path_(data_dir_path), |
43 dom_storage_type_(dom_storage_type) { | 48 dom_storage_type_(dom_storage_type) { |
44 DCHECK(dom_storage_context_); | 49 DCHECK(dom_storage_context_); |
45 } | 50 } |
46 | 51 |
47 DOMStorageNamespace::~DOMStorageNamespace() { | 52 DOMStorageNamespace::~DOMStorageNamespace() { |
48 // TODO(jorlow): If the DOMStorageContext is being destructed, there's no need | 53 // TODO(jorlow): If the DOMStorageContext is being destructed, there's no need |
49 // to do these calls. Maybe we should add a fast path? | 54 // to do these calls. Maybe we should add a fast path? |
50 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); | 55 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); |
51 iter != origin_to_storage_area_.end(); ++iter) { | 56 iter != origin_to_storage_area_.end(); ++iter) { |
(...skipping 14 matching lines...) Expand all Loading... |
66 DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this); | 71 DOMStorageArea* storage_area = new DOMStorageArea(origin, id, this); |
67 origin_to_storage_area_[origin] = storage_area; | 72 origin_to_storage_area_[origin] = storage_area; |
68 dom_storage_context_->RegisterStorageArea(storage_area); | 73 dom_storage_context_->RegisterStorageArea(storage_area); |
69 return storage_area; | 74 return storage_area; |
70 } | 75 } |
71 | 76 |
72 DOMStorageNamespace* DOMStorageNamespace::Copy(int64 id) { | 77 DOMStorageNamespace* DOMStorageNamespace::Copy(int64 id) { |
73 DCHECK(dom_storage_type_ == DOM_STORAGE_SESSION); | 78 DCHECK(dom_storage_type_ == DOM_STORAGE_SESSION); |
74 DCHECK(!dom_storage_context_->GetStorageNamespace(id, false)); | 79 DCHECK(!dom_storage_context_->GetStorageNamespace(id, false)); |
75 DOMStorageNamespace* new_storage_namespace = new DOMStorageNamespace( | 80 DOMStorageNamespace* new_storage_namespace = new DOMStorageNamespace( |
76 dom_storage_context_, id, data_dir_path_, dom_storage_type_); | 81 dom_storage_context_, id, session_storage_directory_, data_dir_path_, |
| 82 dom_storage_type_); |
77 // If we haven't used the namespace yet, there's nothing to copy. | 83 // If we haven't used the namespace yet, there's nothing to copy. |
78 if (storage_namespace_.get()) | 84 if (storage_namespace_.get()) |
79 new_storage_namespace->storage_namespace_.reset(storage_namespace_->copy()); | 85 new_storage_namespace->storage_namespace_.reset(storage_namespace_->copy()); |
80 return new_storage_namespace; | 86 return new_storage_namespace; |
81 } | 87 } |
82 | 88 |
83 void DOMStorageNamespace::PurgeMemory() { | 89 void DOMStorageNamespace::PurgeMemory() { |
84 DCHECK(dom_storage_type_ == DOM_STORAGE_LOCAL); | |
85 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); | 90 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); |
86 iter != origin_to_storage_area_.end(); ++iter) | 91 iter != origin_to_storage_area_.end(); ++iter) |
87 iter->second->PurgeMemory(); | 92 iter->second->PurgeMemory(); |
88 storage_namespace_.reset(); | 93 storage_namespace_.reset(); |
89 } | 94 } |
90 | 95 |
91 WebStorageArea* DOMStorageNamespace::CreateWebStorageArea( | 96 WebStorageArea* DOMStorageNamespace::CreateWebStorageArea( |
92 const string16& origin) { | 97 const string16& origin) { |
93 CreateWebStorageNamespaceIfNecessary(); | 98 CreateWebStorageNamespaceIfNecessary(); |
94 return storage_namespace_->createStorageArea(origin); | 99 return storage_namespace_->createStorageArea(origin); |
95 } | 100 } |
96 | 101 |
| 102 void DOMStorageNamespace::CopyDataTo(DOMStorageNamespace* other) { |
| 103 for (OriginToStorageAreaMap::iterator iter(origin_to_storage_area_.begin()); |
| 104 iter != origin_to_storage_area_.end(); ++iter) { |
| 105 DOMStorageArea* to_area = other->GetStorageArea(iter->first); |
| 106 DCHECK(to_area); |
| 107 iter->second->CopyDataTo(to_area); |
| 108 } |
| 109 } |
| 110 |
97 void DOMStorageNamespace::CreateWebStorageNamespaceIfNecessary() { | 111 void DOMStorageNamespace::CreateWebStorageNamespaceIfNecessary() { |
98 if (storage_namespace_.get()) | 112 if (storage_namespace_.get()) |
99 return; | 113 return; |
100 | 114 |
101 if (dom_storage_type_ == DOM_STORAGE_LOCAL) { | 115 // From WebKit point of view, also sessionStorage is localStorage, since we |
102 storage_namespace_.reset( | 116 // want to save it on disk. (Except for incognito.) |
103 WebStorageNamespace::createLocalStorageNamespace(data_dir_path_, | 117 if (dom_storage_type_ == DOM_STORAGE_SESSION && |
104 WebStorageNamespace::m_localStorageQuota)); | 118 data_dir_path_.isEmpty()) { |
105 } else { | |
106 storage_namespace_.reset(WebStorageNamespace::createSessionStorageNamespace( | 119 storage_namespace_.reset(WebStorageNamespace::createSessionStorageNamespace( |
107 WebStorageNamespace::m_sessionStorageQuota)); | 120 WebStorageNamespace::m_sessionStorageQuota)); |
| 121 } else { |
| 122 storage_namespace_.reset( |
| 123 WebStorageNamespace::createLocalStorageNamespace( |
| 124 data_dir_path_, |
| 125 WebStorageNamespace::m_localStorageQuota)); |
108 } | 126 } |
109 } | 127 } |
| 128 |
| 129 SessionStorageCreatedDetails::SessionStorageCreatedDetails() { } |
| 130 |
| 131 SessionStorageCreatedDetails::SessionStorageCreatedDetails( |
| 132 int64 id, |
| 133 const FilePath& session_storage_directory) |
| 134 : id(id), |
| 135 session_storage_directory(session_storage_directory) { } |
| 136 |
| 137 SessionStorageCreatedDetails::~SessionStorageCreatedDetails() { } |
OLD | NEW |