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

Side by Side Diff: chrome/browser/chromeos/drive/drive_integration_service.cc

Issue 118043003: Fix app_shell shutdown crash due to BrowserContextKeyedServices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix FileSystem tests (shutdown_crash) Created 6 years, 11 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
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 "chrome/browser/chromeos/drive/drive_integration_service.h" 5 #include "chrome/browser/chromeos/drive/drive_integration_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/prefs/pref_change_registrar.h" 9 #include "base/prefs/pref_change_registrar.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 if (util::IsUnderDriveMountPoint( 533 if (util::IsUnderDriveMountPoint(
534 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory))) { 534 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory))) {
535 pref_service->SetFilePath( 535 pref_service->SetFilePath(
536 prefs::kDownloadDefaultDirectory, 536 prefs::kDownloadDefaultDirectory,
537 file_manager::util::GetDownloadsFolderForProfile(profile_)); 537 file_manager::util::GetDownloadsFolderForProfile(profile_));
538 } 538 }
539 } 539 }
540 540
541 //===================== DriveIntegrationServiceFactory ======================= 541 //===================== DriveIntegrationServiceFactory =======================
542 542
543 DriveIntegrationServiceFactory::FactoryFunction*
544 DriveIntegrationServiceFactory::factory_function_for_test_ = NULL;
545 void* DriveIntegrationServiceFactory::factory_data_for_test_ = NULL;
546
543 // static 547 // static
544 DriveIntegrationService* DriveIntegrationServiceFactory::GetForProfile( 548 DriveIntegrationService* DriveIntegrationServiceFactory::GetForProfile(
545 Profile* profile) { 549 Profile* profile) {
546 return GetForProfileRegardlessOfStates(profile); 550 return GetForProfileRegardlessOfStates(profile);
547 } 551 }
548 552
549 // static 553 // static
550 DriveIntegrationService* 554 DriveIntegrationService*
551 DriveIntegrationServiceFactory::GetForProfileRegardlessOfStates( 555 DriveIntegrationServiceFactory::GetForProfileRegardlessOfStates(
552 Profile* profile) { 556 Profile* profile) {
(...skipping 15 matching lines...) Expand all
568 GetInstance()->GetServiceForBrowserContext(profile, false)); 572 GetInstance()->GetServiceForBrowserContext(profile, false));
569 } 573 }
570 574
571 // static 575 // static
572 DriveIntegrationServiceFactory* DriveIntegrationServiceFactory::GetInstance() { 576 DriveIntegrationServiceFactory* DriveIntegrationServiceFactory::GetInstance() {
573 return Singleton<DriveIntegrationServiceFactory>::get(); 577 return Singleton<DriveIntegrationServiceFactory>::get();
574 } 578 }
575 579
576 // static 580 // static
577 void DriveIntegrationServiceFactory::SetFactoryForTest( 581 void DriveIntegrationServiceFactory::SetFactoryForTest(
578 const FactoryCallback& factory_for_test) { 582 FactoryFunction* factory_for_test, void* data) {
579 GetInstance()->factory_for_test_ = factory_for_test; 583 factory_function_for_test_ = factory_for_test;
584 factory_data_for_test_ = data;
580 } 585 }
581 586
582 DriveIntegrationServiceFactory::DriveIntegrationServiceFactory() 587 DriveIntegrationServiceFactory::DriveIntegrationServiceFactory()
583 : BrowserContextKeyedServiceFactory( 588 : BrowserContextKeyedServiceFactory(
584 "DriveIntegrationService", 589 "DriveIntegrationService",
585 BrowserContextDependencyManager::GetInstance()) { 590 BrowserContextDependencyManager::GetInstance()) {
586 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); 591 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
587 DependsOn(DriveNotificationManagerFactory::GetInstance()); 592 DependsOn(DriveNotificationManagerFactory::GetInstance());
588 DependsOn(DownloadServiceFactory::GetInstance()); 593 DependsOn(DownloadServiceFactory::GetInstance());
589 } 594 }
590 595
591 DriveIntegrationServiceFactory::~DriveIntegrationServiceFactory() { 596 DriveIntegrationServiceFactory::~DriveIntegrationServiceFactory() {
592 } 597 }
593 598
594 BrowserContextKeyedService* 599 BrowserContextKeyedService*
595 DriveIntegrationServiceFactory::BuildServiceInstanceFor( 600 DriveIntegrationServiceFactory::BuildServiceInstanceFor(
596 content::BrowserContext* context) const { 601 content::BrowserContext* context) const {
597 Profile* profile = Profile::FromBrowserContext(context); 602 Profile* profile = Profile::FromBrowserContext(context);
598 603
599 DriveIntegrationService* service = NULL; 604 DriveIntegrationService* service = NULL;
600 if (factory_for_test_.is_null()) { 605 if (!factory_function_for_test_) {
601 DriveIntegrationService::PreferenceWatcher* preference_watcher = NULL; 606 DriveIntegrationService::PreferenceWatcher* preference_watcher = NULL;
602 if (chromeos::IsProfileAssociatedWithGaiaAccount(profile)) { 607 if (chromeos::IsProfileAssociatedWithGaiaAccount(profile)) {
603 // Drive File System can be enabled. 608 // Drive File System can be enabled.
604 preference_watcher = 609 preference_watcher =
605 new DriveIntegrationService::PreferenceWatcher(profile->GetPrefs()); 610 new DriveIntegrationService::PreferenceWatcher(profile->GetPrefs());
606 } 611 }
607 612
608 service = new DriveIntegrationService(profile, preference_watcher, 613 service = new DriveIntegrationService(profile, preference_watcher,
609 NULL, base::FilePath(), NULL); 614 NULL, base::FilePath(), NULL);
610 } else { 615 } else {
611 service = factory_for_test_.Run(profile); 616 service = factory_function_for_test_(profile, factory_data_for_test_);
612 } 617 }
613 618
614 return service; 619 return service;
615 } 620 }
616 621
617 } // namespace drive 622 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698