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 "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 Loading... | |
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 Loading... | |
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 = | |
417 base::WrapUnique(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_ = new storage::QuotaManager( |
442 new storage::QuotaManager( | 425 in_memory, partition_path, |
443 in_memory, partition_path, | 426 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get(), |
444 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO).get(), | 427 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB).get(), |
445 BrowserThread::GetTaskRunnerForThread(BrowserThread::DB).get(), | 428 context->GetSpecialStoragePolicy(), |
446 context->GetSpecialStoragePolicy()); | 429 base::Bind(&StoragePartitionImpl::GetQuotaSettings, |
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_ = CreateFileSystemContext( |
451 CreateFileSystemContext( | 437 context, partition_path, in_memory, quota_manager_proxy.get()); |
452 context, partition_path, in_memory, quota_manager->proxy()); | |
453 | 438 |
454 scoped_refptr<storage::DatabaseTracker> database_tracker = | 439 partition->database_tracker_ = new storage::DatabaseTracker( |
455 new storage::DatabaseTracker( | 440 partition_path, in_memory, context->GetSpecialStoragePolicy(), |
456 partition_path, in_memory, context->GetSpecialStoragePolicy(), | 441 quota_manager_proxy.get(), |
457 quota_manager->proxy(), | 442 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); |
458 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE).get()); | |
459 | 443 |
460 scoped_refptr<DOMStorageContextWrapper> dom_storage_context = | 444 partition->dom_storage_context_ = new DOMStorageContextWrapper( |
461 new DOMStorageContextWrapper( | 445 BrowserContext::GetConnectorFor(context), |
462 BrowserContext::GetConnectorFor(context), | 446 in_memory ? base::FilePath() : context->GetPath(), |
463 in_memory ? base::FilePath() : context->GetPath(), | 447 relative_partition_path, context->GetSpecialStoragePolicy()); |
464 relative_partition_path, context->GetSpecialStoragePolicy()); | |
465 | 448 |
466 // BrowserMainLoop may not be initialized in unit tests. Tests will | 449 // BrowserMainLoop may not be initialized in unit tests. Tests will |
467 // need to inject their own task runner into the IndexedDBContext. | 450 // need to inject their own task runner into the IndexedDBContext. |
468 base::SequencedTaskRunner* idb_task_runner = | 451 base::SequencedTaskRunner* idb_task_runner = |
469 BrowserThread::CurrentlyOn(BrowserThread::UI) && | 452 BrowserThread::CurrentlyOn(BrowserThread::UI) && |
470 BrowserMainLoop::GetInstance() | 453 BrowserMainLoop::GetInstance() |
471 ? BrowserMainLoop::GetInstance() | 454 ? BrowserMainLoop::GetInstance() |
472 ->indexed_db_thread() | 455 ->indexed_db_thread() |
473 ->task_runner() | 456 ->task_runner() |
474 .get() | 457 .get() |
475 : NULL; | 458 : NULL; |
476 | 459 |
477 base::FilePath path = in_memory ? base::FilePath() : partition_path; | 460 base::FilePath path = in_memory ? base::FilePath() : partition_path; |
478 scoped_refptr<IndexedDBContextImpl> indexed_db_context = | 461 partition->indexed_db_context_ = |
479 new IndexedDBContextImpl(path, | 462 new IndexedDBContextImpl(path, context->GetSpecialStoragePolicy(), |
480 context->GetSpecialStoragePolicy(), | 463 quota_manager_proxy.get(), idb_task_runner); |
481 quota_manager->proxy(), | |
482 idb_task_runner); | |
483 | 464 |
484 scoped_refptr<CacheStorageContextImpl> cache_storage_context = | 465 partition->cache_storage_context_ = new CacheStorageContextImpl(context); |
485 new CacheStorageContextImpl(context); | 466 partition->cache_storage_context_->Init(path, quota_manager_proxy); |
486 cache_storage_context->Init(path, make_scoped_refptr(quota_manager->proxy())); | |
487 | 467 |
488 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context = | 468 partition->service_worker_context_ = new ServiceWorkerContextWrapper(context); |
489 new ServiceWorkerContextWrapper(context); | 469 partition->service_worker_context_->Init(path, quota_manager_proxy.get(), |
490 service_worker_context->Init(path, quota_manager->proxy(), | 470 context->GetSpecialStoragePolicy()); |
491 context->GetSpecialStoragePolicy()); | 471 partition->service_worker_context_->set_storage_partition(partition.get()); |
492 | 472 |
493 scoped_refptr<ChromeAppCacheService> appcache_service = | 473 partition->appcache_service_ = |
494 new ChromeAppCacheService(quota_manager->proxy()); | 474 new ChromeAppCacheService(quota_manager_proxy.get()); |
495 | 475 |
496 scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy( | 476 partition->host_zoom_level_context_ = new HostZoomLevelContext( |
497 context->GetSpecialStoragePolicy()); | 477 context->CreateZoomLevelDelegate(partition_path)); |
498 | 478 |
499 scoped_refptr<HostZoomLevelContext> host_zoom_level_context( | 479 partition->platform_notification_context_ = |
500 new HostZoomLevelContext( | 480 new PlatformNotificationContextImpl(path, context, |
501 context->CreateZoomLevelDelegate(partition_path))); | 481 partition->service_worker_context_); |
482 partition->platform_notification_context_->Initialize(); | |
502 | 483 |
503 scoped_refptr<PlatformNotificationContextImpl> platform_notification_context = | 484 partition->background_sync_context_ = new BackgroundSyncContext(); |
504 new PlatformNotificationContextImpl(path, context, | 485 partition->background_sync_context_->Init(partition->service_worker_context_); |
505 service_worker_context); | |
506 platform_notification_context->Initialize(); | |
507 | 486 |
508 scoped_refptr<BackgroundSyncContext> background_sync_context = | 487 partition->broadcast_channel_provider_ = new BroadcastChannelProvider(); |
509 new BackgroundSyncContext(); | |
510 background_sync_context->Init(service_worker_context); | |
511 | 488 |
512 scoped_refptr<BroadcastChannelProvider> | 489 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 } | 490 } |
529 | 491 |
530 base::FilePath StoragePartitionImpl::GetPath() { | 492 base::FilePath StoragePartitionImpl::GetPath() { |
531 return partition_path_; | 493 return partition_path_; |
532 } | 494 } |
533 | 495 |
534 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() { | 496 net::URLRequestContextGetter* StoragePartitionImpl::GetURLRequestContext() { |
535 return url_request_context_.get(); | 497 return url_request_context_.get(); |
536 } | 498 } |
537 | 499 |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
913 void StoragePartitionImpl::SetURLRequestContext( | 875 void StoragePartitionImpl::SetURLRequestContext( |
914 net::URLRequestContextGetter* url_request_context) { | 876 net::URLRequestContextGetter* url_request_context) { |
915 url_request_context_ = url_request_context; | 877 url_request_context_ = url_request_context; |
916 } | 878 } |
917 | 879 |
918 void StoragePartitionImpl::SetMediaURLRequestContext( | 880 void StoragePartitionImpl::SetMediaURLRequestContext( |
919 net::URLRequestContextGetter* media_url_request_context) { | 881 net::URLRequestContextGetter* media_url_request_context) { |
920 media_url_request_context_ = media_url_request_context; | 882 media_url_request_context_ = media_url_request_context; |
921 } | 883 } |
922 | 884 |
885 void StoragePartitionImpl::GetQuotaSettings( | |
886 const base::FilePath& parition_path, | |
jsbell
2016/11/09 00:12:04
Typo: "parition" -> "partition"
michaeln
2016/11/11 02:31:53
Done.
| |
887 bool is_incognito, | |
888 const storage::OptionalQuotaSettingsCallback& callback) { | |
889 GetContentClient()->browser()->GetQuotaSettings( | |
jsbell
2016/11/09 00:12:04
This should be able to:
DCHECK_EQ(is_incognito, b
michaeln
2016/11/11 02:31:53
Done, i also changed the content public api to
Ge
| |
890 browser_context_, parition_path, is_incognito, callback); | |
891 } | |
892 | |
923 } // namespace content | 893 } // namespace content |
OLD | NEW |