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

Side by Side Diff: content/browser/storage_partition_impl.cc

Issue 1782053004: Change how the quota system computes the total poolsize for temporary storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 2 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
OLDNEW
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 "content/browser/storage_partition_impl.h" 5 #include "content/browser/storage_partition_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/location.h" 13 #include "base/location.h"
14 #include "base/sequenced_task_runner.h" 14 #include "base/sequenced_task_runner.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "content/browser/browser_main_loop.h" 17 #include "content/browser/browser_main_loop.h"
18 #include "content/browser/fileapi/browser_file_system_helper.h" 18 #include "content/browser/fileapi/browser_file_system_helper.h"
19 #include "content/browser/gpu/shader_disk_cache.h" 19 #include "content/browser/gpu/shader_disk_cache.h"
20 #include "content/browser/host_zoom_map_impl.h" 20 #include "content/browser/host_zoom_map_impl.h"
21 #include "content/browser/notifications/platform_notification_context_impl.h" 21 #include "content/browser/notifications/platform_notification_context_impl.h"
22 #include "content/common/dom_storage/dom_storage_types.h" 22 #include "content/common/dom_storage/dom_storage_types.h"
23 #include "content/public/browser/browser_context.h" 23 #include "content/public/browser/browser_context.h"
24 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/content_browser_client.h"
25 #include "content/public/browser/dom_storage_context.h" 26 #include "content/public/browser/dom_storage_context.h"
26 #include "content/public/browser/indexed_db_context.h" 27 #include "content/public/browser/indexed_db_context.h"
27 #include "content/public/browser/local_storage_usage_info.h" 28 #include "content/public/browser/local_storage_usage_info.h"
28 #include "content/public/browser/session_storage_usage_info.h" 29 #include "content/public/browser/session_storage_usage_info.h"
30 #include "content/public/common/content_client.h"
29 #include "net/base/completion_callback.h" 31 #include "net/base/completion_callback.h"
30 #include "net/base/net_errors.h" 32 #include "net/base/net_errors.h"
31 #include "net/cookies/canonical_cookie.h" 33 #include "net/cookies/canonical_cookie.h"
32 #include "net/cookies/cookie_monster.h" 34 #include "net/cookies/cookie_monster.h"
33 #include "net/url_request/url_request_context.h" 35 #include "net/url_request/url_request_context.h"
34 #include "net/url_request/url_request_context_getter.h" 36 #include "net/url_request/url_request_context_getter.h"
35 #include "storage/browser/database/database_tracker.h" 37 #include "storage/browser/database/database_tracker.h"
36 #include "storage/browser/quota/quota_manager.h" 38 #include "storage/browser/quota/quota_manager.h"
37 39
38 #if defined(ENABLE_PLUGINS) 40 #if defined(ENABLE_PLUGINS)
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 quota_storage_remove_mask, 357 quota_storage_remove_mask,
356 storage_origin, 358 storage_origin,
357 callback); 359 callback);
358 helper->ClearDataOnIOThread(quota_manager, begin, special_storage_policy, 360 helper->ClearDataOnIOThread(quota_manager, begin, special_storage_policy,
359 origin_matcher); 361 origin_matcher);
360 } 362 }
361 363
362 StoragePartitionImpl::StoragePartitionImpl( 364 StoragePartitionImpl::StoragePartitionImpl(
363 BrowserContext* browser_context, 365 BrowserContext* browser_context,
364 const base::FilePath& partition_path, 366 const base::FilePath& partition_path,
365 storage::QuotaManager* quota_manager, 367 storage::SpecialStoragePolicy* special_storage_policy)
366 ChromeAppCacheService* appcache_service,
367 storage::FileSystemContext* filesystem_context,
368 storage::DatabaseTracker* database_tracker,
369 DOMStorageContextWrapper* dom_storage_context,
370 IndexedDBContextImpl* indexed_db_context,
371 CacheStorageContextImpl* cache_storage_context,
372 ServiceWorkerContextWrapper* service_worker_context,
373 storage::SpecialStoragePolicy* special_storage_policy,
374 HostZoomLevelContext* host_zoom_level_context,
375 PlatformNotificationContextImpl* platform_notification_context,
376 BackgroundSyncContext* background_sync_context,
377 scoped_refptr<BroadcastChannelProvider> broadcast_channel_provider)
378 : partition_path_(partition_path), 368 : partition_path_(partition_path),
379 quota_manager_(quota_manager),
380 appcache_service_(appcache_service),
381 filesystem_context_(filesystem_context),
382 database_tracker_(database_tracker),
383 dom_storage_context_(dom_storage_context),
384 indexed_db_context_(indexed_db_context),
385 cache_storage_context_(cache_storage_context),
386 service_worker_context_(service_worker_context),
387 special_storage_policy_(special_storage_policy), 369 special_storage_policy_(special_storage_policy),
388 host_zoom_level_context_(host_zoom_level_context), 370 browser_context_(browser_context),
389 platform_notification_context_(platform_notification_context), 371 weak_factory_(this) {}
390 background_sync_context_(background_sync_context),
391 broadcast_channel_provider_(std::move(broadcast_channel_provider)),
392 browser_context_(browser_context) {}
393 372
394 StoragePartitionImpl::~StoragePartitionImpl() { 373 StoragePartitionImpl::~StoragePartitionImpl() {
395 browser_context_ = nullptr; 374 browser_context_ = nullptr;
396 375
397 // These message loop checks are just to avoid leaks in unittests. 376 // These message loop checks are just to avoid leaks in unittests.
398 if (GetDatabaseTracker() && 377 if (GetDatabaseTracker() &&
399 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { 378 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
400 BrowserThread::PostTask( 379 BrowserThread::PostTask(
401 BrowserThread::FILE, 380 BrowserThread::FILE,
402 FROM_HERE, 381 FROM_HERE,
(...skipping 24 matching lines...) Expand all
427 bool in_memory, 406 bool in_memory,
428 const base::FilePath& relative_partition_path) { 407 const base::FilePath& relative_partition_path) {
429 // Ensure that these methods are called on the UI thread, except for 408 // Ensure that these methods are called on the UI thread, except for
430 // unittests where a UI thread might not have been created. 409 // unittests where a UI thread might not have been created.
431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
432 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); 411 !BrowserThread::IsMessageLoopValid(BrowserThread::UI));
433 412
434 base::FilePath partition_path = 413 base::FilePath partition_path =
435 context->GetPath().Append(relative_partition_path); 414 context->GetPath().Append(relative_partition_path);
436 415
416 std::unique_ptr<StoragePartitionImpl> partition = base::WrapUnique(
417 new StoragePartitionImpl(
418 context, partition_path, context->GetSpecialStoragePolicy()));
419
437 // All of the clients have to be created and registered with the 420 // All of the clients have to be created and registered with the
438 // QuotaManager prior to the QuotaManger being used. We do them 421 // QuotaManager prior to the QuotaManger being used. We do them
439 // all together here prior to handing out a reference to anything 422 // all together here prior to handing out a reference to anything
440 // that utilizes the QuotaManager. 423 // that utilizes the QuotaManager.
441 scoped_refptr<storage::QuotaManager> quota_manager = 424 partition->quota_manager_ =
442 new storage::QuotaManager( 425 new storage::QuotaManager(
443 in_memory, partition_path, 426 in_memory, partition_path,
444 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get(), 427 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get(),
445 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB).get(), 428 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB).get(),
446 context->GetSpecialStoragePolicy()); 429 context->GetSpecialStoragePolicy(),
430 base::Bind(&StoragePartitionImpl::GetTemporaryStorageConfiguration,
431 partition->weak_factory_.GetWeakPtr()));
432 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy =
433 partition->quota_manager_->proxy();
447 434
448 // Each consumer is responsible for registering its QuotaClient during 435 // Each consumer is responsible for registering its QuotaClient during
449 // its construction. 436 // its construction.
450 scoped_refptr<storage::FileSystemContext> filesystem_context = 437 partition->filesystem_context_ =
451 CreateFileSystemContext( 438 CreateFileSystemContext(
452 context, partition_path, in_memory, quota_manager->proxy()); 439 context, partition_path, in_memory, quota_manager_proxy.get());
453 440
454 scoped_refptr<storage::DatabaseTracker> database_tracker = 441 partition->database_tracker_ =
455 new storage::DatabaseTracker( 442 new storage::DatabaseTracker(
456 partition_path, in_memory, context->GetSpecialStoragePolicy(), 443 partition_path, in_memory, context->GetSpecialStoragePolicy(),
457 quota_manager->proxy(), 444 quota_manager_proxy.get(),
458 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); 445 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get());
459 446
460 scoped_refptr<DOMStorageContextWrapper> dom_storage_context = 447 partition->dom_storage_context_ =
461 new DOMStorageContextWrapper( 448 new DOMStorageContextWrapper(
462 BrowserContext::GetConnectorFor(context), 449 BrowserContext::GetConnectorFor(context),
463 in_memory ? base::FilePath() : context->GetPath(), 450 in_memory ? base::FilePath() : context->GetPath(),
464 relative_partition_path, context->GetSpecialStoragePolicy()); 451 relative_partition_path, context->GetSpecialStoragePolicy());
465 452
466 // BrowserMainLoop may not be initialized in unit tests. Tests will 453 // BrowserMainLoop may not be initialized in unit tests. Tests will
467 // need to inject their own task runner into the IndexedDBContext. 454 // need to inject their own task runner into the IndexedDBContext.
468 base::SequencedTaskRunner* idb_task_runner = 455 base::SequencedTaskRunner* idb_task_runner =
469 BrowserThread::CurrentlyOn(BrowserThread::UI) && 456 BrowserThread::CurrentlyOn(BrowserThread::UI) &&
470 BrowserMainLoop::GetInstance() 457 BrowserMainLoop::GetInstance()
471 ? BrowserMainLoop::GetInstance() 458 ? BrowserMainLoop::GetInstance()
472 ->indexed_db_thread() 459 ->indexed_db_thread()
473 ->task_runner() 460 ->task_runner()
474 .get() 461 .get()
475 : NULL; 462 : NULL;
476 463
477 base::FilePath path = in_memory ? base::FilePath() : partition_path; 464 base::FilePath path = in_memory ? base::FilePath() : partition_path;
478 scoped_refptr<IndexedDBContextImpl> indexed_db_context = 465 partition->indexed_db_context_ =
479 new IndexedDBContextImpl(path, 466 new IndexedDBContextImpl(path,
480 context->GetSpecialStoragePolicy(), 467 context->GetSpecialStoragePolicy(),
481 quota_manager->proxy(), 468 quota_manager_proxy.get(),
482 idb_task_runner); 469 idb_task_runner);
483 470
484 scoped_refptr<CacheStorageContextImpl> cache_storage_context = 471 partition->cache_storage_context_ = new CacheStorageContextImpl(context);
485 new CacheStorageContextImpl(context); 472 partition->cache_storage_context_->Init(path, quota_manager_proxy);
486 cache_storage_context->Init(path, make_scoped_refptr(quota_manager->proxy()));
487 473
488 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = 474 partition->service_worker_context_ = new ServiceWorkerContextWrapper(context);
489 new ServiceWorkerContextWrapper(context); 475 partition->service_worker_context_->Init(
490 service_worker_context->Init(path, quota_manager->proxy(), 476 path, quota_manager_proxy.get(), context->GetSpecialStoragePolicy());
491 context->GetSpecialStoragePolicy()); 477 partition->service_worker_context_->set_storage_partition(partition.get());
492 478
493 scoped_refptr<ChromeAppCacheService> appcache_service = 479 partition->appcache_service_ =
494 new ChromeAppCacheService(quota_manager->proxy()); 480 new ChromeAppCacheService(quota_manager_proxy.get());
495 481
496 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy( 482 partition->host_zoom_level_context_ =
497 context->GetSpecialStoragePolicy()); 483 new HostZoomLevelContext(
484 context->CreateZoomLevelDelegate(partition_path));
498 485
499 scoped_refptr<HostZoomLevelContext> host_zoom_level_context( 486 partition->platform_notification_context_ =
500 new HostZoomLevelContext( 487 new PlatformNotificationContextImpl(
501 context->CreateZoomLevelDelegate(partition_path))); 488 path, context, partition->service_worker_context_);
489 partition->platform_notification_context_->Initialize();
502 490
503 scoped_refptr<PlatformNotificationContextImpl> platform_notification_context = 491 partition->background_sync_context_ = new BackgroundSyncContext();
504 new PlatformNotificationContextImpl(path, context, 492 partition->background_sync_context_->Init(partition->service_worker_context_);
505 service_worker_context);
506 platform_notification_context->Initialize();
507 493
508 scoped_refptr<BackgroundSyncContext> background_sync_context = 494 partition->broadcast_channel_provider_ = new BroadcastChannelProvider();
509 new BackgroundSyncContext();
510 background_sync_context->Init(service_worker_context);
511 495
512 scoped_refptr<BroadcastChannelProvider> 496 return partition;
513 broadcast_channel_provider = new BroadcastChannelProvider();
514
515 std::unique_ptr<StoragePartitionImpl> storage_partition(
516 new StoragePartitionImpl(
517 context, partition_path, quota_manager.get(), appcache_service.get(),
518 filesystem_context.get(), database_tracker.get(),
519 dom_storage_context.get(), indexed_db_context.get(),
520 cache_storage_context.get(), service_worker_context.get(),
521 special_storage_policy.get(), host_zoom_level_context.get(),
522 platform_notification_context.get(), background_sync_context.get(),
523 std::move(broadcast_channel_provider)));
524
525 service_worker_context->set_storage_partition(storage_partition.get());
526
527 return storage_partition;
528 } 497 }
529 498
530 base::FilePath StoragePartitionImpl::GetPath() { 499 base::FilePath StoragePartitionImpl::GetPath() {
531 return partition_path_; 500 return partition_path_;
532 } 501 }
533 502
534 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() { 503 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() {
535 return url_request_context_.get(); 504 return url_request_context_.get();
536 } 505 }
537 506
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
913 void StoragePartitionImpl::SetURLRequestContext( 882 void StoragePartitionImpl::SetURLRequestContext(
914 net::URLRequestContextGetter* url_request_context) { 883 net::URLRequestContextGetter* url_request_context) {
915 url_request_context_ = url_request_context; 884 url_request_context_ = url_request_context;
916 } 885 }
917 886
918 void StoragePartitionImpl::SetMediaURLRequestContext( 887 void StoragePartitionImpl::SetMediaURLRequestContext(
919 net::URLRequestContextGetter* media_url_request_context) { 888 net::URLRequestContextGetter* media_url_request_context) {
920 media_url_request_context_ = media_url_request_context; 889 media_url_request_context_ = media_url_request_context;
921 } 890 }
922 891
892 void StoragePartitionImpl::GetTemporaryStorageConfiguration(
893 const base::FilePath& parition_path, bool is_incognito,
894 const storage::TemporaryStorageConfigurationCallback& callback) {
895 GetContentClient()->browser()->GetTemporaryStorageConfiguration(
896 browser_context_, parition_path, is_incognito, callback);
897 }
898
923 } // namespace content 899 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698