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

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, 1 month 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 PaymentAppContext* payment_app_context,
378 scoped_refptr<BroadcastChannelProvider> broadcast_channel_provider)
kinuko 2016/11/10 17:49:22 Whoa..!
379 : partition_path_(partition_path), 368 : partition_path_(partition_path),
380 quota_manager_(quota_manager),
381 appcache_service_(appcache_service),
382 filesystem_context_(filesystem_context),
383 database_tracker_(database_tracker),
384 dom_storage_context_(dom_storage_context),
385 indexed_db_context_(indexed_db_context),
386 cache_storage_context_(cache_storage_context),
387 service_worker_context_(service_worker_context),
388 special_storage_policy_(special_storage_policy), 369 special_storage_policy_(special_storage_policy),
389 host_zoom_level_context_(host_zoom_level_context), 370 browser_context_(browser_context),
390 platform_notification_context_(platform_notification_context), 371 weak_factory_(this) {}
391 background_sync_context_(background_sync_context),
392 payment_app_context_(payment_app_context),
393 broadcast_channel_provider_(std::move(broadcast_channel_provider)),
394 browser_context_(browser_context) {}
395 372
396 StoragePartitionImpl::~StoragePartitionImpl() { 373 StoragePartitionImpl::~StoragePartitionImpl() {
397 browser_context_ = nullptr; 374 browser_context_ = nullptr;
398 375
399 // These message loop checks are just to avoid leaks in unittests. 376 // These message loop checks are just to avoid leaks in unittests.
400 if (GetDatabaseTracker() && 377 if (GetDatabaseTracker() &&
401 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) { 378 BrowserThread::IsMessageLoopValid(BrowserThread::FILE)) {
402 BrowserThread::PostTask( 379 BrowserThread::PostTask(
403 BrowserThread::FILE, 380 BrowserThread::FILE,
404 FROM_HERE, 381 FROM_HERE,
(...skipping 27 matching lines...) Expand all
432 bool in_memory, 409 bool in_memory,
433 const base::FilePath& relative_partition_path) { 410 const base::FilePath& relative_partition_path) {
434 // Ensure that these methods are called on the UI thread, except for 411 // Ensure that these methods are called on the UI thread, except for
435 // unittests where a UI thread might not have been created. 412 // unittests where a UI thread might not have been created.
436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
437 !BrowserThread::IsMessageLoopValid(BrowserThread::UI)); 414 !BrowserThread::IsMessageLoopValid(BrowserThread::UI));
438 415
439 base::FilePath partition_path = 416 base::FilePath partition_path =
440 context->GetPath().Append(relative_partition_path); 417 context->GetPath().Append(relative_partition_path);
441 418
419 std::unique_ptr<StoragePartitionImpl> partition =
420 base::WrapUnique(new StoragePartitionImpl(
421 context, partition_path, context->GetSpecialStoragePolicy()));
422
442 // All of the clients have to be created and registered with the 423 // All of the clients have to be created and registered with the
443 // QuotaManager prior to the QuotaManger being used. We do them 424 // QuotaManager prior to the QuotaManger being used. We do them
444 // all together here prior to handing out a reference to anything 425 // all together here prior to handing out a reference to anything
445 // that utilizes the QuotaManager. 426 // that utilizes the QuotaManager.
446 scoped_refptr<storage::QuotaManager> quota_manager = 427 partition->quota_manager_ = new storage::QuotaManager(
447 new storage::QuotaManager( 428 in_memory, partition_path,
448 in_memory, partition_path, 429 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get(),
449 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get(), 430 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB).get(),
450 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB).get(), 431 context->GetSpecialStoragePolicy(),
451 context->GetSpecialStoragePolicy()); 432 base::Bind(&StoragePartitionImpl::GetQuotaSettings,
433 partition->weak_factory_.GetWeakPtr()));
434 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy =
435 partition->quota_manager_->proxy();
452 436
453 // Each consumer is responsible for registering its QuotaClient during 437 // Each consumer is responsible for registering its QuotaClient during
454 // its construction. 438 // its construction.
455 scoped_refptr<storage::FileSystemContext> filesystem_context = 439 partition->filesystem_context_ = CreateFileSystemContext(
456 CreateFileSystemContext( 440 context, partition_path, in_memory, quota_manager_proxy.get());
457 context, partition_path, in_memory, quota_manager->proxy());
458 441
459 scoped_refptr<storage::DatabaseTracker> database_tracker = 442 partition->database_tracker_ = new storage::DatabaseTracker(
460 new storage::DatabaseTracker( 443 partition_path, in_memory, context->GetSpecialStoragePolicy(),
461 partition_path, in_memory, context->GetSpecialStoragePolicy(), 444 quota_manager_proxy.get(),
462 quota_manager->proxy(), 445 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get());
463 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get());
464 446
465 scoped_refptr<DOMStorageContextWrapper> dom_storage_context = 447 partition->dom_storage_context_ = new DOMStorageContextWrapper(
466 new DOMStorageContextWrapper( 448 BrowserContext::GetConnectorFor(context),
467 BrowserContext::GetConnectorFor(context), 449 in_memory ? base::FilePath() : context->GetPath(),
468 in_memory ? base::FilePath() : context->GetPath(), 450 relative_partition_path, context->GetSpecialStoragePolicy());
469 relative_partition_path, context->GetSpecialStoragePolicy());
470 451
471 // BrowserMainLoop may not be initialized in unit tests. Tests will 452 // BrowserMainLoop may not be initialized in unit tests. Tests will
472 // need to inject their own task runner into the IndexedDBContext. 453 // need to inject their own task runner into the IndexedDBContext.
473 base::SequencedTaskRunner* idb_task_runner = 454 base::SequencedTaskRunner* idb_task_runner =
474 BrowserThread::CurrentlyOn(BrowserThread::UI) && 455 BrowserThread::CurrentlyOn(BrowserThread::UI) &&
475 BrowserMainLoop::GetInstance() 456 BrowserMainLoop::GetInstance()
476 ? BrowserMainLoop::GetInstance() 457 ? BrowserMainLoop::GetInstance()
477 ->indexed_db_thread() 458 ->indexed_db_thread()
478 ->task_runner() 459 ->task_runner()
479 .get() 460 .get()
480 : NULL; 461 : NULL;
481 462
482 base::FilePath path = in_memory ? base::FilePath() : partition_path; 463 base::FilePath path = in_memory ? base::FilePath() : partition_path;
483 scoped_refptr<IndexedDBContextImpl> indexed_db_context = 464 partition->indexed_db_context_ =
484 new IndexedDBContextImpl(path, 465 new IndexedDBContextImpl(path, context->GetSpecialStoragePolicy(),
485 context->GetSpecialStoragePolicy(), 466 quota_manager_proxy.get(), idb_task_runner);
486 quota_manager->proxy(),
487 idb_task_runner);
488 467
489 scoped_refptr<CacheStorageContextImpl> cache_storage_context = 468 partition->cache_storage_context_ = new CacheStorageContextImpl(context);
490 new CacheStorageContextImpl(context); 469 partition->cache_storage_context_->Init(path, quota_manager_proxy);
491 cache_storage_context->Init(path, make_scoped_refptr(quota_manager->proxy()));
492 470
493 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = 471 partition->service_worker_context_ = new ServiceWorkerContextWrapper(context);
494 new ServiceWorkerContextWrapper(context); 472 partition->service_worker_context_->Init(path, quota_manager_proxy.get(),
495 service_worker_context->Init(path, quota_manager->proxy(), 473 context->GetSpecialStoragePolicy());
496 context->GetSpecialStoragePolicy()); 474 partition->service_worker_context_->set_storage_partition(partition.get());
497 475
498 scoped_refptr<ChromeAppCacheService> appcache_service = 476 partition->appcache_service_ =
499 new ChromeAppCacheService(quota_manager->proxy()); 477 new ChromeAppCacheService(quota_manager_proxy.get());
500 478
501 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy( 479 partition->host_zoom_level_context_ = new HostZoomLevelContext(
502 context->GetSpecialStoragePolicy()); 480 context->CreateZoomLevelDelegate(partition_path));
503 481
504 scoped_refptr<HostZoomLevelContext> host_zoom_level_context( 482 partition->platform_notification_context_ =
505 new HostZoomLevelContext( 483 new PlatformNotificationContextImpl(path, context,
506 context->CreateZoomLevelDelegate(partition_path))); 484 partition->service_worker_context_);
485 partition->platform_notification_context_->Initialize();
507 486
508 scoped_refptr<PlatformNotificationContextImpl> platform_notification_context = 487 partition->background_sync_context_ = new BackgroundSyncContext();
509 new PlatformNotificationContextImpl(path, context, 488 partition->background_sync_context_->Init(partition->service_worker_context_);
510 service_worker_context);
511 platform_notification_context->Initialize();
512 489
513 scoped_refptr<BackgroundSyncContext> background_sync_context = 490 partition->payment_app_context_ = new PaymentAppContext();
514 new BackgroundSyncContext(); 491 partition->payment_app_context_->Init(partition->service_worker_context_);
515 background_sync_context->Init(service_worker_context);
516 492
517 scoped_refptr<PaymentAppContext> payment_app_context = 493 partition->broadcast_channel_provider_ = new BroadcastChannelProvider();
518 new PaymentAppContext();
519 payment_app_context->Init(service_worker_context);
520 494
521 scoped_refptr<BroadcastChannelProvider> 495 return partition;
522 broadcast_channel_provider = new BroadcastChannelProvider();
523
524 std::unique_ptr<StoragePartitionImpl> storage_partition(
525 new StoragePartitionImpl(
526 context, partition_path, quota_manager.get(), appcache_service.get(),
527 filesystem_context.get(), database_tracker.get(),
528 dom_storage_context.get(), indexed_db_context.get(),
529 cache_storage_context.get(), service_worker_context.get(),
530 special_storage_policy.get(), host_zoom_level_context.get(),
531 platform_notification_context.get(), background_sync_context.get(),
532 payment_app_context.get(),
533 std::move(broadcast_channel_provider)));
534
535 service_worker_context->set_storage_partition(storage_partition.get());
536
537 return storage_partition;
538 } 496 }
539 497
540 base::FilePath StoragePartitionImpl::GetPath() { 498 base::FilePath StoragePartitionImpl::GetPath() {
541 return partition_path_; 499 return partition_path_;
542 } 500 }
543 501
544 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() { 502 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() {
545 return url_request_context_.get(); 503 return url_request_context_.get();
546 } 504 }
547 505
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 void StoragePartitionImpl::SetURLRequestContext( 885 void StoragePartitionImpl::SetURLRequestContext(
928 net::URLRequestContextGetter* url_request_context) { 886 net::URLRequestContextGetter* url_request_context) {
929 url_request_context_ = url_request_context; 887 url_request_context_ = url_request_context;
930 } 888 }
931 889
932 void StoragePartitionImpl::SetMediaURLRequestContext( 890 void StoragePartitionImpl::SetMediaURLRequestContext(
933 net::URLRequestContextGetter* media_url_request_context) { 891 net::URLRequestContextGetter* media_url_request_context) {
934 media_url_request_context_ = media_url_request_context; 892 media_url_request_context_ = media_url_request_context;
935 } 893 }
936 894
895 void StoragePartitionImpl::GetQuotaSettings(
896 const base::FilePath& parition_path,
897 bool is_incognito,
898 const storage::OptionalQuotaSettingsCallback& callback) {
899 GetContentClient()->browser()->GetQuotaSettings(
900 browser_context_, parition_path, is_incognito, callback);
901 }
902
937 } // namespace content 903 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698