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