Chromium Code Reviews| 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_context.h" | 5 #include "webkit/dom_storage/dom_storage_context.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 | 24 |
| 25 DomStorageContext::DomStorageContext( | 25 DomStorageContext::DomStorageContext( |
| 26 const FilePath& localstorage_directory, | 26 const FilePath& localstorage_directory, |
| 27 const FilePath& sessionstorage_directory, | 27 const FilePath& sessionstorage_directory, |
| 28 quota::SpecialStoragePolicy* special_storage_policy, | 28 quota::SpecialStoragePolicy* special_storage_policy, |
| 29 DomStorageTaskRunner* task_runner) | 29 DomStorageTaskRunner* task_runner) |
| 30 : localstorage_directory_(localstorage_directory), | 30 : localstorage_directory_(localstorage_directory), |
| 31 sessionstorage_directory_(sessionstorage_directory), | 31 sessionstorage_directory_(sessionstorage_directory), |
| 32 task_runner_(task_runner), | 32 task_runner_(task_runner), |
| 33 is_shutdown_(false), | 33 is_shutdown_(false), |
| 34 clear_local_state_(false), | |
| 35 save_session_state_(false), | 34 save_session_state_(false), |
| 36 special_storage_policy_(special_storage_policy) { | 35 special_storage_policy_(special_storage_policy) { |
| 37 // AtomicSequenceNum starts at 0 but we want to start session | 36 // AtomicSequenceNum starts at 0 but we want to start session |
| 38 // namespace ids at one since zero is reserved for the | 37 // namespace ids at one since zero is reserved for the |
| 39 // kLocalStorageNamespaceId. | 38 // kLocalStorageNamespaceId. |
| 40 session_id_sequence_.GetNext(); | 39 session_id_sequence_.GetNext(); |
| 41 } | 40 } |
| 42 | 41 |
| 43 DomStorageContext::~DomStorageContext() { | 42 DomStorageContext::~DomStorageContext() { |
| 44 } | 43 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 128 |
| 130 // Respect the content policy settings about what to | 129 // Respect the content policy settings about what to |
| 131 // keep and what to discard. | 130 // keep and what to discard. |
| 132 if (save_session_state_) | 131 if (save_session_state_) |
| 133 return; // Keep everything. | 132 return; // Keep everything. |
| 134 | 133 |
| 135 bool has_session_only_origins = | 134 bool has_session_only_origins = |
| 136 special_storage_policy_.get() && | 135 special_storage_policy_.get() && |
| 137 special_storage_policy_->HasSessionOnlyOrigins(); | 136 special_storage_policy_->HasSessionOnlyOrigins(); |
| 138 | 137 |
| 139 if (clear_local_state_ || has_session_only_origins) { | 138 if (has_session_only_origins) { |
| 140 // We may have to delete something. We continue on the | 139 // We may have to delete something. We continue on the |
| 141 // commit sequence after area shutdown tasks have cycled | 140 // commit sequence after area shutdown tasks have cycled |
| 142 // thru that sequence (and closed their database files). | 141 // thru that sequence (and closed their database files). |
| 143 bool success = task_runner_->PostShutdownBlockingTask( | 142 bool success = task_runner_->PostShutdownBlockingTask( |
| 144 FROM_HERE, | 143 FROM_HERE, |
| 145 DomStorageTaskRunner::COMMIT_SEQUENCE, | 144 DomStorageTaskRunner::COMMIT_SEQUENCE, |
| 146 base::Bind(&DomStorageContext::ClearLocalStateInCommitSequence, this)); | 145 base::Bind(&DomStorageContext::ClearLocalStateInCommitSequence, this)); |
|
michaeln
2012/06/01 02:06:17
nit: the name of the ClearLocalStateInCommitSequen
jochen (gone - plz use gerrit)
2012/06/01 12:15:19
Done.
jochen (gone - plz use gerrit)
2012/06/01 12:15:19
Done.
| |
| 147 DCHECK(success); | 146 DCHECK(success); |
| 148 } | 147 } |
| 149 } | 148 } |
| 150 | 149 |
| 151 void DomStorageContext::AddEventObserver(EventObserver* observer) { | 150 void DomStorageContext::AddEventObserver(EventObserver* observer) { |
| 152 event_observers_.AddObserver(observer); | 151 event_observers_.AddObserver(observer); |
| 153 } | 152 } |
| 154 | 153 |
| 155 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { | 154 void DomStorageContext::RemoveEventObserver(EventObserver* observer) { |
| 156 event_observers_.RemoveObserver(observer); | 155 event_observers_.RemoveObserver(observer); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 | 215 |
| 217 void DomStorageContext::ClearLocalStateInCommitSequence() { | 216 void DomStorageContext::ClearLocalStateInCommitSequence() { |
| 218 std::vector<UsageInfo> infos; | 217 std::vector<UsageInfo> infos; |
| 219 const bool kDontIncludeFileInfo = false; | 218 const bool kDontIncludeFileInfo = false; |
| 220 GetUsageInfo(&infos, kDontIncludeFileInfo); | 219 GetUsageInfo(&infos, kDontIncludeFileInfo); |
| 221 for (size_t i = 0; i < infos.size(); ++i) { | 220 for (size_t i = 0; i < infos.size(); ++i) { |
| 222 const GURL& origin = infos[i].origin; | 221 const GURL& origin = infos[i].origin; |
| 223 if (special_storage_policy_ && | 222 if (special_storage_policy_ && |
| 224 special_storage_policy_->IsStorageProtected(origin)) | 223 special_storage_policy_->IsStorageProtected(origin)) |
| 225 continue; | 224 continue; |
| 226 if (!clear_local_state_ && | 225 if (!special_storage_policy_->IsStorageSessionOnly(origin)) |
| 227 !special_storage_policy_->IsStorageSessionOnly(origin)) | |
| 228 continue; | 226 continue; |
| 229 | 227 |
| 230 const bool kNotRecursive = false; | 228 const bool kNotRecursive = false; |
| 231 FilePath database_file_path = localstorage_directory_.Append( | 229 FilePath database_file_path = localstorage_directory_.Append( |
| 232 DomStorageArea::DatabaseFileNameFromOrigin(origin)); | 230 DomStorageArea::DatabaseFileNameFromOrigin(origin)); |
| 233 file_util::Delete(database_file_path, kNotRecursive); | 231 file_util::Delete(database_file_path, kNotRecursive); |
| 234 file_util::Delete( | 232 file_util::Delete( |
| 235 DomStorageDatabase::GetJournalFilePath(database_file_path), | 233 DomStorageDatabase::GetJournalFilePath(database_file_path), |
| 236 kNotRecursive); | 234 kNotRecursive); |
| 237 } | 235 } |
| 238 } | 236 } |
| 239 | 237 |
| 240 } // namespace dom_storage | 238 } // namespace dom_storage |
| OLD | NEW |