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