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

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: address review comments Created 4 years, 4 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 StoragePartitionImpl* partition = new StoragePartitionImpl(
417 context, partition_path, context->GetSpecialStoragePolicy());
418
437 // All of the clients have to be created and registered with the 419 // All of the clients have to be created and registered with the
438 // QuotaManager prior to the QuotaManger being used. We do them 420 // QuotaManager prior to the QuotaManger being used. We do them
439 // all together here prior to handing out a reference to anything 421 // all together here prior to handing out a reference to anything
440 // that utilizes the QuotaManager. 422 // that utilizes the QuotaManager.
441 scoped_refptr<storage::QuotaManager> quota_manager = 423 partition->quota_manager_ =
442 new storage::QuotaManager( 424 new storage::QuotaManager(
443 in_memory, partition_path, 425 in_memory, partition_path,
444 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get(), 426 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get(),
445 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB).get(), 427 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB).get(),
446 context->GetSpecialStoragePolicy()); 428 context->GetSpecialStoragePolicy(),
429 base::Bind(&StoragePartitionImpl::GetTemporaryStorageConfiguration,
430 partition->weak_factory_.GetWeakPtr()));
431 scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy =
432 partition->quota_manager_->proxy();
447 433
448 // Each consumer is responsible for registering its QuotaClient during 434 // Each consumer is responsible for registering its QuotaClient during
449 // its construction. 435 // its construction.
450 scoped_refptr<storage::FileSystemContext> filesystem_context = 436 partition->filesystem_context_ =
451 CreateFileSystemContext( 437 CreateFileSystemContext(
452 context, partition_path, in_memory, quota_manager->proxy()); 438 context, partition_path, in_memory, quota_manager_proxy.get());
453 439
454 scoped_refptr<storage::DatabaseTracker> database_tracker = 440 partition->database_tracker_ =
455 new storage::DatabaseTracker( 441 new storage::DatabaseTracker(
456 partition_path, in_memory, context->GetSpecialStoragePolicy(), 442 partition_path, in_memory, context->GetSpecialStoragePolicy(),
457 quota_manager->proxy(), 443 quota_manager_proxy.get(),
458 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); 444 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get());
459 445
460 scoped_refptr<DOMStorageContextWrapper> dom_storage_context = 446 partition->dom_storage_context_ =
461 new DOMStorageContextWrapper( 447 new DOMStorageContextWrapper(
462 BrowserContext::GetShellConnectorFor(context), 448 BrowserContext::GetShellConnectorFor(context),
463 in_memory ? base::FilePath() : context->GetPath(), 449 in_memory ? base::FilePath() : context->GetPath(),
464 relative_partition_path, context->GetSpecialStoragePolicy()); 450 relative_partition_path, context->GetSpecialStoragePolicy());
465 451
466 // BrowserMainLoop may not be initialized in unit tests. Tests will 452 // BrowserMainLoop may not be initialized in unit tests. Tests will
467 // need to inject their own task runner into the IndexedDBContext. 453 // need to inject their own task runner into the IndexedDBContext.
468 base::SequencedTaskRunner* idb_task_runner = 454 base::SequencedTaskRunner* idb_task_runner =
469 BrowserThread::CurrentlyOn(BrowserThread::UI) && 455 BrowserThread::CurrentlyOn(BrowserThread::UI) &&
470 BrowserMainLoop::GetInstance() 456 BrowserMainLoop::GetInstance()
471 ? BrowserMainLoop::GetInstance() 457 ? BrowserMainLoop::GetInstance()
472 ->indexed_db_thread() 458 ->indexed_db_thread()
473 ->task_runner() 459 ->task_runner()
474 .get() 460 .get()
475 : NULL; 461 : NULL;
476 462
477 base::FilePath path = in_memory ? base::FilePath() : partition_path; 463 base::FilePath path = in_memory ? base::FilePath() : partition_path;
478 scoped_refptr<IndexedDBContextImpl> indexed_db_context = 464 partition->indexed_db_context_ =
479 new IndexedDBContextImpl(path, 465 new IndexedDBContextImpl(path,
480 context->GetSpecialStoragePolicy(), 466 context->GetSpecialStoragePolicy(),
481 quota_manager->proxy(), 467 quota_manager_proxy.get(),
482 idb_task_runner); 468 idb_task_runner);
483 469
484 scoped_refptr<CacheStorageContextImpl> cache_storage_context = 470 partition->cache_storage_context_ = new CacheStorageContextImpl(context);
485 new CacheStorageContextImpl(context); 471 partition->cache_storage_context_->Init(path, quota_manager_proxy);
486 cache_storage_context->Init(path, make_scoped_refptr(quota_manager->proxy()));
487 472
488 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = 473 partition->service_worker_context_ = new ServiceWorkerContextWrapper(context);
489 new ServiceWorkerContextWrapper(context); 474 partition->service_worker_context_->Init(
490 service_worker_context->Init(path, quota_manager->proxy(), 475 path, quota_manager_proxy.get(), context->GetSpecialStoragePolicy());
491 context->GetSpecialStoragePolicy()); 476 partition->service_worker_context_->set_storage_partition(partition);
492 477
493 scoped_refptr<ChromeAppCacheService> appcache_service = 478 partition->appcache_service_ =
494 new ChromeAppCacheService(quota_manager->proxy()); 479 new ChromeAppCacheService(quota_manager_proxy.get());
495 480
496 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy( 481 partition->host_zoom_level_context_ =
497 context->GetSpecialStoragePolicy()); 482 new HostZoomLevelContext(
483 context->CreateZoomLevelDelegate(partition_path));
498 484
499 scoped_refptr<HostZoomLevelContext> host_zoom_level_context( 485 partition->platform_notification_context_ =
500 new HostZoomLevelContext( 486 new PlatformNotificationContextImpl(
501 context->CreateZoomLevelDelegate(partition_path))); 487 path, context, partition->service_worker_context_);
488 partition->platform_notification_context_->Initialize();
502 489
503 scoped_refptr<PlatformNotificationContextImpl> platform_notification_context = 490 partition->background_sync_context_ = new BackgroundSyncContext();
504 new PlatformNotificationContextImpl(path, context, 491 partition->background_sync_context_->Init(partition->service_worker_context_);
505 service_worker_context);
506 platform_notification_context->Initialize();
507 492
508 scoped_refptr<BackgroundSyncContext> background_sync_context = 493 partition->broadcast_channel_provider_ = new BroadcastChannelProvider();
509 new BackgroundSyncContext();
510 background_sync_context->Init(service_worker_context);
511 494
512 scoped_refptr<BroadcastChannelProvider> 495 return partition;
513 broadcast_channel_provider = new BroadcastChannelProvider();
514
515 StoragePartitionImpl* storage_partition = new StoragePartitionImpl(
516 context, partition_path, quota_manager.get(), appcache_service.get(),
517 filesystem_context.get(), database_tracker.get(),
518 dom_storage_context.get(), indexed_db_context.get(),
519 cache_storage_context.get(), service_worker_context.get(),
520 special_storage_policy.get(), host_zoom_level_context.get(),
521 platform_notification_context.get(), background_sync_context.get(),
522 std::move(broadcast_channel_provider));
523
524 service_worker_context->set_storage_partition(storage_partition);
525
526 return storage_partition;
527 } 496 }
528 497
529 base::FilePath StoragePartitionImpl::GetPath() { 498 base::FilePath StoragePartitionImpl::GetPath() {
530 return partition_path_; 499 return partition_path_;
531 } 500 }
532 501
533 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() { 502 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() {
534 return url_request_context_.get(); 503 return url_request_context_.get();
535 } 504 }
536 505
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 void StoragePartitionImpl::SetURLRequestContext( 881 void StoragePartitionImpl::SetURLRequestContext(
913 net::URLRequestContextGetter* url_request_context) { 882 net::URLRequestContextGetter* url_request_context) {
914 url_request_context_ = url_request_context; 883 url_request_context_ = url_request_context;
915 } 884 }
916 885
917 void StoragePartitionImpl::SetMediaURLRequestContext( 886 void StoragePartitionImpl::SetMediaURLRequestContext(
918 net::URLRequestContextGetter* media_url_request_context) { 887 net::URLRequestContextGetter* media_url_request_context) {
919 media_url_request_context_ = media_url_request_context; 888 media_url_request_context_ = media_url_request_context;
920 } 889 }
921 890
891 void StoragePartitionImpl::GetTemporaryStorageConfiguration(
892 const base::FilePath& parition_path, bool is_incognito,
893 const storage::TemporaryStorageConfigurationCallback& callback) {
894 GetContentClient()->browser()->GetTemporaryStorageConfiguration(
895 browser_context_, parition_path, is_incognito, callback);
896 }
897
922 } // namespace content 898 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698