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

Side by Side Diff: chrome/test/testing_profile.cc

Issue 7464029: Adding QuotaManager logic to TestingProfile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Uglay. Created 9 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/testing_profile.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/test/testing_profile.h" 5 #include "chrome/test/testing_profile.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include "base/base_paths.h" 9 #include "base/base_paths.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "chrome/browser/ui/find_bar/find_bar_state.h" 44 #include "chrome/browser/ui/find_bar/find_bar_state.h"
45 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 45 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
46 #include "chrome/common/chrome_constants.h" 46 #include "chrome/common/chrome_constants.h"
47 #include "chrome/common/chrome_notification_types.h" 47 #include "chrome/common/chrome_notification_types.h"
48 #include "chrome/common/url_constants.h" 48 #include "chrome/common/url_constants.h"
49 #include "chrome/test/bookmark_load_observer.h" 49 #include "chrome/test/bookmark_load_observer.h"
50 #include "chrome/test/test_url_request_context_getter.h" 50 #include "chrome/test/test_url_request_context_getter.h"
51 #include "chrome/test/testing_pref_service.h" 51 #include "chrome/test/testing_pref_service.h"
52 #include "chrome/test/ui_test_utils.h" 52 #include "chrome/test/ui_test_utils.h"
53 #include "content/browser/browser_thread.h" 53 #include "content/browser/browser_thread.h"
54 #include "content/browser/file_system/browser_file_system_helper.h"
54 #include "content/browser/in_process_webkit/webkit_context.h" 55 #include "content/browser/in_process_webkit/webkit_context.h"
55 #include "content/browser/mock_resource_context.h" 56 #include "content/browser/mock_resource_context.h"
56 #include "content/common/notification_service.h" 57 #include "content/common/notification_service.h"
57 #include "net/base/cookie_monster.h" 58 #include "net/base/cookie_monster.h"
58 #include "net/url_request/url_request_context.h" 59 #include "net/url_request/url_request_context.h"
59 #include "net/url_request/url_request_context_getter.h" 60 #include "net/url_request/url_request_context_getter.h"
60 #include "net/url_request/url_request_test_util.h" 61 #include "net/url_request/url_request_test_util.h"
61 #include "testing/gmock/include/gmock/gmock.h" 62 #include "testing/gmock/include/gmock/gmock.h"
62 #include "webkit/database/database_tracker.h" 63 #include "webkit/database/database_tracker.h"
63 #include "webkit/fileapi/file_system_context.h" 64 #include "webkit/fileapi/file_system_context.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 115 }
115 116
116 private: 117 private:
117 scoped_refptr<net::URLRequestContext> context_; 118 scoped_refptr<net::URLRequestContext> context_;
118 }; 119 };
119 120
120 ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) { 121 ProfileKeyedService* CreateTestDesktopNotificationService(Profile* profile) {
121 return new DesktopNotificationService(profile, NULL); 122 return new DesktopNotificationService(profile, NULL);
122 } 123 }
123 124
125 void CreateResourceContextOnIOThread() {
126 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
127 content::MockResourceContext::GetInstance();
128 };
129
124 } // namespace 130 } // namespace
125 131
126 TestingProfile::TestingProfile() 132 TestingProfile::TestingProfile()
127 : start_time_(Time::Now()), 133 : start_time_(Time::Now()),
128 testing_prefs_(NULL), 134 testing_prefs_(NULL),
129 incognito_(false), 135 incognito_(false),
130 last_session_exited_cleanly_(true), 136 last_session_exited_cleanly_(true),
137 appcache_service_init_finished_(false),
131 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) { 138 profile_dependency_manager_(ProfileDependencyManager::GetInstance()) {
132 #ifndef NDEBUG 139 #ifndef NDEBUG
133 profile_dependency_manager_->ProfileNowExists(this); 140 profile_dependency_manager_->ProfileNowExists(this);
134 #endif 141 #endif
135 142
136 if (!temp_dir_.CreateUniqueTempDir()) { 143 if (!temp_dir_.CreateUniqueTempDir()) {
137 LOG(ERROR) << "Failed to create unique temporary directory."; 144 LOG(ERROR) << "Failed to create unique temporary directory.";
138 145
139 // Fallback logic in case we fail to create unique temporary directory. 146 // Fallback logic in case we fail to create unique temporary directory.
140 FilePath system_tmp_dir; 147 FilePath system_tmp_dir;
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 392 }
386 393
387 bool TestingProfile::HasOffTheRecordProfile() { 394 bool TestingProfile::HasOffTheRecordProfile() {
388 return incognito_profile_.get() != NULL; 395 return incognito_profile_.get() != NULL;
389 } 396 }
390 397
391 Profile* TestingProfile::GetOriginalProfile() { 398 Profile* TestingProfile::GetOriginalProfile() {
392 return this; 399 return this;
393 } 400 }
394 401
395 void TestingProfile::SetAppCacheService( 402 ChromeAppCacheService* TestingProfile::GetAppCacheService() {
396 ChromeAppCacheService* appcache_service) { 403 CreateQuotaManagerAndClients();
397 appcache_service_ = appcache_service; 404 if (!appcache_service_init_finished_) {
398 } 405 // Ensure that this is posted before GetResourceContext() is called below,
406 // otherwise it's entirely possible that things will be exploded.
407 BrowserThread::PostTask(
408 BrowserThread::IO, FROM_HERE,
409 NewRunnableFunction(&CreateResourceContextOnIOThread));
399 410
400 ChromeAppCacheService* TestingProfile::GetAppCacheService() { 411 BrowserThread::PostTask(
412 BrowserThread::IO, FROM_HERE,
413 NewRunnableMethod(
414 appcache_service_.get(),
415 &ChromeAppCacheService::InitializeOnIOThread,
416 IsOffTheRecord()
417 ? FilePath() : GetPath().Append(chrome::kAppCacheDirname),
418 &GetResourceContext(),
419 make_scoped_refptr(GetExtensionSpecialStoragePolicy()),
420 false));
421
422 appcache_service_init_finished_ = true;
423 }
401 return appcache_service_.get(); 424 return appcache_service_.get();
402 } 425 }
403 426
404 webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() { 427 webkit_database::DatabaseTracker* TestingProfile::GetDatabaseTracker() {
405 if (!db_tracker_) { 428 CreateQuotaManagerAndClients();
406 db_tracker_ = new webkit_database::DatabaseTracker(
407 GetPath(), false, false, GetExtensionSpecialStoragePolicy(),
408 NULL, NULL);
409 }
410 return db_tracker_; 429 return db_tracker_;
411 } 430 }
412 431
413 VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() { 432 VisitedLinkMaster* TestingProfile::GetVisitedLinkMaster() {
414 return NULL; 433 return NULL;
415 } 434 }
416 435
417 ExtensionService* TestingProfile::GetExtensionService() { 436 ExtensionService* TestingProfile::GetExtensionService() {
418 return extension_service_.get(); 437 return extension_service_.get();
419 } 438 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 546
528 DownloadManager* TestingProfile::GetDownloadManager() { 547 DownloadManager* TestingProfile::GetDownloadManager() {
529 return NULL; 548 return NULL;
530 } 549 }
531 550
532 PersonalDataManager* TestingProfile::GetPersonalDataManager() { 551 PersonalDataManager* TestingProfile::GetPersonalDataManager() {
533 return NULL; 552 return NULL;
534 } 553 }
535 554
536 fileapi::FileSystemContext* TestingProfile::GetFileSystemContext() { 555 fileapi::FileSystemContext* TestingProfile::GetFileSystemContext() {
537 if (!file_system_context_) { 556 CreateQuotaManagerAndClients();
538 file_system_context_ = new fileapi::FileSystemContext(
539 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
540 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
541 GetExtensionSpecialStoragePolicy(),
542 NULL,
543 GetPath(),
544 IsOffTheRecord(),
545 true, // Allow file access from files.
546 true, // Unlimited quota.
547 NULL);
548 }
549 return file_system_context_.get(); 557 return file_system_context_.get();
550 } 558 }
551 559
552 quota::QuotaManager* TestingProfile::GetQuotaManager() { 560 quota::QuotaManager* TestingProfile::GetQuotaManager() {
553 return NULL; 561 CreateQuotaManagerAndClients();
562 return quota_manager_.get();
563 }
564
565 void TestingProfile::CreateQuotaManagerAndClients() {
566 if (quota_manager_.get()) {
567 DCHECK(appcache_service_.get());
568 DCHECK(db_tracker_.get());
569 DCHECK(file_system_context_.get());
570 DCHECK(webkit_context_.get());
571 return;
572 }
573
574 // All the clients have to be created and registered with the
575 // quota manager prior to the manager being used. So, we do them
576 // all together here prior to handing our a reference to anything
577 // that uses the quota manager.
578 quota_manager_ = new quota::QuotaManager(
579 IsOffTheRecord(),
580 GetPath(),
581 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO),
582 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
583 GetExtensionSpecialStoragePolicy());
584
585 // Each consumer is responsible for registering its QuotaClient during
586 // its construction.
587 file_system_context_ = CreateFileSystemContext(
588 GetPath(), IsOffTheRecord(),
589 GetExtensionSpecialStoragePolicy(),
590 quota_manager_->proxy());
591 db_tracker_ = new webkit_database::DatabaseTracker(
592 GetPath(), IsOffTheRecord(), false,
593 GetExtensionSpecialStoragePolicy(),
594 quota_manager_->proxy(),
595 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
596 webkit_context_ = new WebKitContext(
597 IsOffTheRecord(), GetPath(), GetExtensionSpecialStoragePolicy(),
598 false, quota_manager_->proxy(),
599 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::WEBKIT));
600 appcache_service_ = new ChromeAppCacheService(quota_manager_->proxy());
554 } 601 }
555 602
556 BrowserSignin* TestingProfile::GetBrowserSignin() { 603 BrowserSignin* TestingProfile::GetBrowserSignin() {
557 return NULL; 604 return NULL;
558 } 605 }
559 606
560 bool TestingProfile::HasCreatedDownloadManager() const { 607 bool TestingProfile::HasCreatedDownloadManager() const {
561 return false; 608 return false;
562 } 609 }
563 610
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 732
686 ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() { 733 ProtocolHandlerRegistry* TestingProfile::GetProtocolHandlerRegistry() {
687 return protocol_handler_registry_.get(); 734 return protocol_handler_registry_.get();
688 } 735 }
689 736
690 SpellCheckHost* TestingProfile::GetSpellCheckHost() { 737 SpellCheckHost* TestingProfile::GetSpellCheckHost() {
691 return NULL; 738 return NULL;
692 } 739 }
693 740
694 WebKitContext* TestingProfile::GetWebKitContext() { 741 WebKitContext* TestingProfile::GetWebKitContext() {
695 if (webkit_context_ == NULL) { 742 CreateQuotaManagerAndClients();
696 webkit_context_ = new WebKitContext(
697 IsOffTheRecord(), GetPath(),
698 GetExtensionSpecialStoragePolicy(),
699 false, NULL, NULL);
700 }
701 return webkit_context_; 743 return webkit_context_;
702 } 744 }
703 745
704 WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() { 746 WebKitContext* TestingProfile::GetOffTheRecordWebKitContext() {
705 return NULL; 747 return NULL;
706 } 748 }
707 749
708 FilePath TestingProfile::last_selected_directory() { 750 FilePath TestingProfile::last_selected_directory() {
709 return last_selected_directory_; 751 return last_selected_directory_;
710 } 752 }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() { 835 quota::SpecialStoragePolicy* TestingProfile::GetSpecialStoragePolicy() {
794 return GetExtensionSpecialStoragePolicy(); 836 return GetExtensionSpecialStoragePolicy();
795 } 837 }
796 838
797 void TestingProfile::DestroyWebDataService() { 839 void TestingProfile::DestroyWebDataService() {
798 if (!web_data_service_.get()) 840 if (!web_data_service_.get())
799 return; 841 return;
800 842
801 web_data_service_->Shutdown(); 843 web_data_service_->Shutdown();
802 } 844 }
OLDNEW
« no previous file with comments | « chrome/test/testing_profile.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698