Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: content/browser/dom_storage/dom_storage_context_wrapper.cc

Issue 2335933003: Make DOMStorageContextWrapper a client of memory coordinator (Closed)
Patch Set: Address on ssid's review Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_wrapper.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/memory/memory_coordinator_client_registry.h"
14 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
15 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
19 #include "components/filesystem/public/interfaces/directory.mojom.h" 20 #include "components/filesystem/public/interfaces/directory.mojom.h"
20 #include "components/leveldb/public/interfaces/leveldb.mojom.h" 21 #include "components/leveldb/public/interfaces/leveldb.mojom.h"
21 #include "content/browser/dom_storage/dom_storage_area.h" 22 #include "content/browser/dom_storage/dom_storage_area.h"
22 #include "content/browser/dom_storage/dom_storage_context_impl.h" 23 #include "content/browser/dom_storage/dom_storage_context_impl.h"
23 #include "content/browser/dom_storage/dom_storage_task_runner.h" 24 #include "content/browser/dom_storage/dom_storage_task_runner.h"
24 #include "content/browser/dom_storage/session_storage_namespace_impl.h" 25 #include "content/browser/dom_storage/session_storage_namespace_impl.h"
25 #include "content/browser/leveldb_wrapper_impl.h" 26 #include "content/browser/leveldb_wrapper_impl.h"
27 #include "content/browser/memory/memory_coordinator.h"
26 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
27 #include "content/public/browser/local_storage_usage_info.h" 29 #include "content/public/browser/local_storage_usage_info.h"
28 #include "content/public/browser/session_storage_usage_info.h" 30 #include "content/public/browser/session_storage_usage_info.h"
31 #include "content/public/common/content_features.h"
29 #include "mojo/common/common_type_converters.h" 32 #include "mojo/common/common_type_converters.h"
30 #include "services/file/public/cpp/constants.h" 33 #include "services/file/public/cpp/constants.h"
31 #include "services/file/public/interfaces/file_system.mojom.h" 34 #include "services/file/public/interfaces/file_system.mojom.h"
32 #include "services/shell/public/cpp/connection.h" 35 #include "services/shell/public/cpp/connection.h"
33 #include "services/shell/public/cpp/connector.h" 36 #include "services/shell/public/cpp/connector.h"
34 37
35 namespace content { 38 namespace content {
36 namespace { 39 namespace {
37 40
38 const char kLocalStorageDirectory[] = "Local Storage"; 41 const char kLocalStorageDirectory[] = "Local Storage";
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 : data_path.AppendASCII(kLocalStorageDirectory), 280 : data_path.AppendASCII(kLocalStorageDirectory),
278 data_path.empty() ? data_path 281 data_path.empty() ? data_path
279 : data_path.AppendASCII(kSessionStorageDirectory), 282 : data_path.AppendASCII(kSessionStorageDirectory),
280 special_storage_policy, 283 special_storage_policy,
281 new DOMStorageWorkerPoolTaskRunner( 284 new DOMStorageWorkerPoolTaskRunner(
282 worker_pool, 285 worker_pool,
283 worker_pool->GetNamedSequenceToken("dom_storage_primary"), 286 worker_pool->GetNamedSequenceToken("dom_storage_primary"),
284 worker_pool->GetNamedSequenceToken("dom_storage_commit"), 287 worker_pool->GetNamedSequenceToken("dom_storage_commit"),
285 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get())); 288 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get()));
286 289
287 memory_pressure_listener_.reset(new base::MemoryPressureListener( 290 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) {
288 base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this))); 291 base::MemoryCoordinatorClientRegistry::GetInstance()->Register(this);
292 } else {
293 memory_pressure_listener_.reset(new base::MemoryPressureListener(
294 base::Bind(&DOMStorageContextWrapper::OnMemoryPressure, this)));
295 }
289 } 296 }
290 297
291 DOMStorageContextWrapper::~DOMStorageContextWrapper() {} 298 DOMStorageContextWrapper::~DOMStorageContextWrapper() {}
292 299
293 void DOMStorageContextWrapper::GetLocalStorageUsage( 300 void DOMStorageContextWrapper::GetLocalStorageUsage(
294 const GetLocalStorageUsageCallback& callback) { 301 const GetLocalStorageUsageCallback& callback) {
295 DCHECK(context_.get()); 302 DCHECK(context_.get());
296 context_->task_runner()->PostShutdownBlockingTask( 303 context_->task_runner()->PostShutdownBlockingTask(
297 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, 304 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE,
298 base::Bind(&GetLocalStorageUsageHelper, 305 base::Bind(&GetLocalStorageUsageHelper,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 365 }
359 366
360 void DOMStorageContextWrapper::Shutdown() { 367 void DOMStorageContextWrapper::Shutdown() {
361 DCHECK(context_.get()); 368 DCHECK(context_.get());
362 mojo_state_.reset(); 369 mojo_state_.reset();
363 memory_pressure_listener_.reset(); 370 memory_pressure_listener_.reset();
364 context_->task_runner()->PostShutdownBlockingTask( 371 context_->task_runner()->PostShutdownBlockingTask(
365 FROM_HERE, 372 FROM_HERE,
366 DOMStorageTaskRunner::PRIMARY_SEQUENCE, 373 DOMStorageTaskRunner::PRIMARY_SEQUENCE,
367 base::Bind(&DOMStorageContextImpl::Shutdown, context_)); 374 base::Bind(&DOMStorageContextImpl::Shutdown, context_));
375 if (base::FeatureList::IsEnabled(features::kMemoryCoordinator)) {
376 base::MemoryCoordinatorClientRegistry::GetInstance()->Unregister(this);
377 }
378
368 } 379 }
369 380
370 void DOMStorageContextWrapper::Flush() { 381 void DOMStorageContextWrapper::Flush() {
371 DCHECK(context_.get()); 382 DCHECK(context_.get());
372 context_->task_runner()->PostShutdownBlockingTask( 383 context_->task_runner()->PostShutdownBlockingTask(
373 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE, 384 FROM_HERE, DOMStorageTaskRunner::PRIMARY_SEQUENCE,
374 base::Bind(&DOMStorageContextImpl::Flush, context_)); 385 base::Bind(&DOMStorageContextImpl::Flush, context_));
375 } 386 }
376 387
377 void DOMStorageContextWrapper::OpenLocalStorage( 388 void DOMStorageContextWrapper::OpenLocalStorage(
378 const url::Origin& origin, 389 const url::Origin& origin,
379 mojom::LevelDBObserverPtr observer, 390 mojom::LevelDBObserverPtr observer,
380 mojom::LevelDBWrapperRequest request) { 391 mojom::LevelDBWrapperRequest request) {
381 mojo_state_->OpenLocalStorage( 392 mojo_state_->OpenLocalStorage(
382 origin, std::move(observer), std::move(request)); 393 origin, std::move(observer), std::move(request));
383 } 394 }
384 395
385 void DOMStorageContextWrapper::OnMemoryPressure( 396 void DOMStorageContextWrapper::OnMemoryPressure(
386 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) { 397 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level) {
387 DOMStorageContextImpl::PurgeOption purge_option = 398 DOMStorageContextImpl::PurgeOption purge_option =
388 DOMStorageContextImpl::PURGE_UNOPENED; 399 DOMStorageContextImpl::PURGE_UNOPENED;
389 if (memory_pressure_level == 400 if (memory_pressure_level ==
390 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { 401 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) {
391 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE; 402 purge_option = DOMStorageContextImpl::PURGE_AGGRESSIVE;
392 } 403 }
404 PurgeMemory(purge_option);
405 }
406
407 void DOMStorageContextWrapper::OnMemoryStateChange(base::MemoryState state) {
408 // TODO(hajimehoshi): As OnMemoryStateChange changes the state, we should
409 // adjust the limitation to the amount of cache, DomStroageContextImpl doesn't
410 // have such limitation so far though.
411 switch (state) {
412 case base::MemoryState::NORMAL:
413 // Don't have to purge memory here.
414 break;
415 case base::MemoryState::THROTTLED:
416 // TOOD(hajimehoshi): We don't have throttling 'level' so far. When we
417 // have such value, let's change the argument accroding to the value.
418 PurgeMemory(DOMStorageContextImpl::PURGE_AGGRESSIVE);
419 break;
420 case base::MemoryState::SUSPENDED:
421 // Note that SUSPENDED never occurs in the main browser process so far.
422 // Fall through.
423 case base::MemoryState::UNKNOWN:
424 NOTREACHED();
425 break;
426 }
427 }
428
429 void DOMStorageContextWrapper::PurgeMemory(DOMStorageContextImpl::PurgeOption
430 purge_option) {
393 context_->task_runner()->PostTask( 431 context_->task_runner()->PostTask(
394 FROM_HERE, 432 FROM_HERE,
395 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option)); 433 base::Bind(&DOMStorageContextImpl::PurgeMemory, context_, purge_option));
396 } 434 }
397 435
398 } // namespace content 436 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_context_wrapper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698