| 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 "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 Loading... |
| 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::FactoryCallback* |
| 544 DriveIntegrationServiceFactory::factory_for_test_ = NULL; |
| 545 |
| 546 DriveIntegrationServiceFactory::ScopedFactoryForTest::ScopedFactoryForTest( |
| 547 FactoryCallback* factory_for_test) { |
| 548 factory_for_test_ = factory_for_test; |
| 549 } |
| 550 |
| 551 DriveIntegrationServiceFactory::ScopedFactoryForTest::~ScopedFactoryForTest() { |
| 552 factory_for_test_ = NULL; |
| 553 } |
| 554 |
| 543 // static | 555 // static |
| 544 DriveIntegrationService* DriveIntegrationServiceFactory::GetForProfile( | 556 DriveIntegrationService* DriveIntegrationServiceFactory::GetForProfile( |
| 545 Profile* profile) { | 557 Profile* profile) { |
| 546 return GetForProfileRegardlessOfStates(profile); | 558 return GetForProfileRegardlessOfStates(profile); |
| 547 } | 559 } |
| 548 | 560 |
| 549 // static | 561 // static |
| 550 DriveIntegrationService* | 562 DriveIntegrationService* |
| 551 DriveIntegrationServiceFactory::GetForProfileRegardlessOfStates( | 563 DriveIntegrationServiceFactory::GetForProfileRegardlessOfStates( |
| 552 Profile* profile) { | 564 Profile* profile) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 566 Profile* profile) { | 578 Profile* profile) { |
| 567 return static_cast<DriveIntegrationService*>( | 579 return static_cast<DriveIntegrationService*>( |
| 568 GetInstance()->GetServiceForBrowserContext(profile, false)); | 580 GetInstance()->GetServiceForBrowserContext(profile, false)); |
| 569 } | 581 } |
| 570 | 582 |
| 571 // static | 583 // static |
| 572 DriveIntegrationServiceFactory* DriveIntegrationServiceFactory::GetInstance() { | 584 DriveIntegrationServiceFactory* DriveIntegrationServiceFactory::GetInstance() { |
| 573 return Singleton<DriveIntegrationServiceFactory>::get(); | 585 return Singleton<DriveIntegrationServiceFactory>::get(); |
| 574 } | 586 } |
| 575 | 587 |
| 576 // static | |
| 577 void DriveIntegrationServiceFactory::SetFactoryForTest( | |
| 578 const FactoryCallback& factory_for_test) { | |
| 579 GetInstance()->factory_for_test_ = factory_for_test; | |
| 580 } | |
| 581 | |
| 582 DriveIntegrationServiceFactory::DriveIntegrationServiceFactory() | 588 DriveIntegrationServiceFactory::DriveIntegrationServiceFactory() |
| 583 : BrowserContextKeyedServiceFactory( | 589 : BrowserContextKeyedServiceFactory( |
| 584 "DriveIntegrationService", | 590 "DriveIntegrationService", |
| 585 BrowserContextDependencyManager::GetInstance()) { | 591 BrowserContextDependencyManager::GetInstance()) { |
| 586 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | 592 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
| 587 DependsOn(DriveNotificationManagerFactory::GetInstance()); | 593 DependsOn(DriveNotificationManagerFactory::GetInstance()); |
| 588 DependsOn(DownloadServiceFactory::GetInstance()); | 594 DependsOn(DownloadServiceFactory::GetInstance()); |
| 589 } | 595 } |
| 590 | 596 |
| 591 DriveIntegrationServiceFactory::~DriveIntegrationServiceFactory() { | 597 DriveIntegrationServiceFactory::~DriveIntegrationServiceFactory() { |
| 592 } | 598 } |
| 593 | 599 |
| 594 BrowserContextKeyedService* | 600 BrowserContextKeyedService* |
| 595 DriveIntegrationServiceFactory::BuildServiceInstanceFor( | 601 DriveIntegrationServiceFactory::BuildServiceInstanceFor( |
| 596 content::BrowserContext* context) const { | 602 content::BrowserContext* context) const { |
| 597 Profile* profile = Profile::FromBrowserContext(context); | 603 Profile* profile = Profile::FromBrowserContext(context); |
| 598 | 604 |
| 599 DriveIntegrationService* service = NULL; | 605 DriveIntegrationService* service = NULL; |
| 600 if (factory_for_test_.is_null()) { | 606 if (!factory_for_test_) { |
| 601 DriveIntegrationService::PreferenceWatcher* preference_watcher = NULL; | 607 DriveIntegrationService::PreferenceWatcher* preference_watcher = NULL; |
| 602 if (chromeos::IsProfileAssociatedWithGaiaAccount(profile)) { | 608 if (chromeos::IsProfileAssociatedWithGaiaAccount(profile)) { |
| 603 // Drive File System can be enabled. | 609 // Drive File System can be enabled. |
| 604 preference_watcher = | 610 preference_watcher = |
| 605 new DriveIntegrationService::PreferenceWatcher(profile->GetPrefs()); | 611 new DriveIntegrationService::PreferenceWatcher(profile->GetPrefs()); |
| 606 } | 612 } |
| 607 | 613 |
| 608 service = new DriveIntegrationService(profile, preference_watcher, | 614 service = new DriveIntegrationService(profile, preference_watcher, |
| 609 NULL, base::FilePath(), NULL); | 615 NULL, base::FilePath(), NULL); |
| 610 } else { | 616 } else { |
| 611 service = factory_for_test_.Run(profile); | 617 service = factory_for_test_->Run(profile); |
| 612 } | 618 } |
| 613 | 619 |
| 614 return service; | 620 return service; |
| 615 } | 621 } |
| 616 | 622 |
| 617 } // namespace drive | 623 } // namespace drive |
| OLD | NEW |