| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/dom_storage/dom_storage_context_wrapper.h" | 5 #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { | 268 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { |
| 269 DOMStorageContextImpl::PurgeOption purge_option = | 269 DOMStorageContextImpl::PurgeOption purge_option = |
| 270 DOMStorageContextImpl::PURGE_UNOPENED; | 270 DOMStorageContextImpl::PURGE_UNOPENED; |
| 271 if (memory_pressure_level == | 271 if (memory_pressure_level == |
| 272 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 272 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 273 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; | 273 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; |
| 274 } | 274 } |
| 275 PurgeMemory(purge_option); | 275 PurgeMemory(purge_option); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void DOMStorageContextWrapper::OnMemoryStateChange(base::MemoryState state) { | 278 void DOMStorageContextWrapper::OnPurgeMemory() { |
| 279 // TODO(hajimehoshi): As OnMemoryStateChange changes the state, we should | 279 PurgeMemory(DOMStorageContextImpl::PURGE_AGGRESSIVE); |
| 280 // adjust the limitation to the amount of cache, DomStroageContextImpl doesn't | |
| 281 // have such limitation so far though. | |
| 282 switch (state) { | |
| 283 case base::MemoryState::NORMAL: | |
| 284 // Don't have to purge memory here. | |
| 285 break; | |
| 286 case base::MemoryState::THROTTLED: | |
| 287 // TOOD(hajimehoshi): We don't have throttling 'level' so far. When we | |
| 288 // have such value, let's change the argument accroding to the value. | |
| 289 PurgeMemory(DOMStorageContextImpl::PURGE_AGGRESSIVE); | |
| 290 break; | |
| 291 case base::MemoryState::SUSPENDED: | |
| 292 // Note that SUSPENDED never occurs in the main browser process so far. | |
| 293 // Fall through. | |
| 294 case base::MemoryState::UNKNOWN: | |
| 295 NOTREACHED(); | |
| 296 break; | |
| 297 } | |
| 298 } | 280 } |
| 299 | 281 |
| 300 void DOMStorageContextWrapper::PurgeMemory(DOMStorageContextImpl::PurgeOption | 282 void DOMStorageContextWrapper::PurgeMemory(DOMStorageContextImpl::PurgeOption |
| 301 purge_option) { | 283 purge_option) { |
| 302 context_->task_runner()->PostTask( | 284 context_->task_runner()->PostTask( |
| 303 FROM_HERE, | 285 FROM_HERE, |
| 304 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); | 286 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); |
| 305 } | 287 } |
| 306 | 288 |
| 307 void DOMStorageContextWrapper::GotMojoLocalStorageUsage( | 289 void DOMStorageContextWrapper::GotMojoLocalStorageUsage( |
| 308 GetLocalStorageUsageCallback callback, | 290 GetLocalStorageUsageCallback callback, |
| 309 std::vector<LocalStorageUsageInfo> usage) { | 291 std::vector<LocalStorageUsageInfo> usage) { |
| 310 context_->task_runner()->PostShutdownBlockingTask( | 292 context_->task_runner()->PostShutdownBlockingTask( |
| 311 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, | 293 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, |
| 312 base::Bind(&GetLocalStorageUsageHelper, base::Passed(&usage), | 294 base::Bind(&GetLocalStorageUsageHelper, base::Passed(&usage), |
| 313 base::RetainedRef(base::ThreadTaskRunnerHandle::Get()), | 295 base::RetainedRef(base::ThreadTaskRunnerHandle::Get()), |
| 314 base::RetainedRef(context_), callback)); | 296 base::RetainedRef(context_), callback)); |
| 315 } | 297 } |
| 316 | 298 |
| 317 } // namespace content | 299 } // namespace content |
| OLD | NEW |