| 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" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/chromeos/drive/debug_info_collector.h" | 15 #include "chrome/browser/chromeos/drive/debug_info_collector.h" |
| 15 #include "chrome/browser/chromeos/drive/download_handler.h" | 16 #include "chrome/browser/chromeos/drive/download_handler.h" |
| 16 #include "chrome/browser/chromeos/drive/file_cache.h" | 17 #include "chrome/browser/chromeos/drive/file_cache.h" |
| 17 #include "chrome/browser/chromeos/drive/file_system.h" | 18 #include "chrome/browser/chromeos/drive/file_system.h" |
| 18 #include "chrome/browser/chromeos/drive/file_system_util.h" | 19 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 19 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 20 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 20 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 21 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
| 21 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" | 22 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" |
| 22 #include "chrome/browser/chromeos/file_manager/path_util.h" | 23 #include "chrome/browser/chromeos/file_manager/path_util.h" |
| 23 #include "chrome/browser/chromeos/profiles/profile_util.h" | 24 #include "chrome/browser/chromeos/profiles/profile_util.h" |
| 24 #include "chrome/browser/download/download_prefs.h" | 25 #include "chrome/browser/download/download_prefs.h" |
| 25 #include "chrome/browser/download/download_service.h" | 26 #include "chrome/browser/download/download_service.h" |
| 26 #include "chrome/browser/download/download_service_factory.h" | 27 #include "chrome/browser/download/download_service_factory.h" |
| 27 #include "chrome/browser/drive/drive_api_service.h" | 28 #include "chrome/browser/drive/drive_api_service.h" |
| 28 #include "chrome/browser/drive/drive_api_util.h" | 29 #include "chrome/browser/drive/drive_api_util.h" |
| 29 #include "chrome/browser/drive/drive_app_registry.h" | 30 #include "chrome/browser/drive/drive_app_registry.h" |
| 30 #include "chrome/browser/drive/drive_notification_manager.h" | 31 #include "chrome/browser/drive/drive_notification_manager.h" |
| 31 #include "chrome/browser/drive/drive_notification_manager_factory.h" | 32 #include "chrome/browser/drive/drive_notification_manager_factory.h" |
| 32 #include "chrome/browser/drive/event_logger.h" | 33 #include "chrome/browser/drive/event_logger.h" |
| 34 #include "chrome/browser/profiles/incognito_helpers.h" |
| 33 #include "chrome/browser/profiles/profile.h" | 35 #include "chrome/browser/profiles/profile.h" |
| 34 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 36 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 35 #include "chrome/browser/signin/signin_manager_factory.h" | 37 #include "chrome/browser/signin/signin_manager_factory.h" |
| 36 #include "chrome/common/chrome_version_info.h" | 38 #include "chrome/common/chrome_version_info.h" |
| 37 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
| 38 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 40 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 39 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 41 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 40 #include "components/signin/core/browser/signin_manager.h" | 42 #include "components/signin/core/browser/signin_manager.h" |
| 41 #include "content/public/browser/browser_context.h" | 43 #include "content/public/browser/browser_context.h" |
| 42 #include "content/public/browser/browser_thread.h" | 44 #include "content/public/browser/browser_thread.h" |
| 45 #include "content/public/browser/notification_service.h" |
| 43 #include "content/public/common/user_agent.h" | 46 #include "content/public/common/user_agent.h" |
| 44 #include "google_apis/drive/auth_service.h" | 47 #include "google_apis/drive/auth_service.h" |
| 45 #include "google_apis/drive/gdata_wapi_url_generator.h" | 48 #include "google_apis/drive/gdata_wapi_url_generator.h" |
| 46 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
| 47 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
| 48 #include "webkit/browser/fileapi/external_mount_points.h" | 51 #include "webkit/browser/fileapi/external_mount_points.h" |
| 49 | 52 |
| 50 using content::BrowserContext; | 53 using content::BrowserContext; |
| 51 using content::BrowserThread; | 54 using content::BrowserThread; |
| 52 | 55 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 const base::FilePath& test_cache_root, | 217 const base::FilePath& test_cache_root, |
| 215 FileSystemInterface* test_file_system) | 218 FileSystemInterface* test_file_system) |
| 216 : profile_(profile), | 219 : profile_(profile), |
| 217 state_(NOT_INITIALIZED), | 220 state_(NOT_INITIALIZED), |
| 218 enabled_(false), | 221 enabled_(false), |
| 219 mount_point_name_(test_mount_point_name), | 222 mount_point_name_(test_mount_point_name), |
| 220 cache_root_directory_(!test_cache_root.empty() ? | 223 cache_root_directory_(!test_cache_root.empty() ? |
| 221 test_cache_root : util::GetCacheRootPath(profile)), | 224 test_cache_root : util::GetCacheRootPath(profile)), |
| 222 weak_ptr_factory_(this) { | 225 weak_ptr_factory_(this) { |
| 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 227 DCHECK(profile && !profile->IsOffTheRecord()); |
| 224 | 228 |
| 225 logger_.reset(new EventLogger); | 229 logger_.reset(new EventLogger); |
| 226 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); | 230 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); |
| 227 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( | 231 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( |
| 228 blocking_pool->GetSequenceToken()); | 232 blocking_pool->GetSequenceToken()); |
| 229 | 233 |
| 230 ProfileOAuth2TokenService* oauth_service = | 234 ProfileOAuth2TokenService* oauth_service = |
| 231 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 235 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 232 | 236 |
| 233 if (test_drive_service) { | 237 if (test_drive_service) { |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 | 505 |
| 502 // Cannot used Drive. Set the download destination preference out of Drive. | 506 // Cannot used Drive. Set the download destination preference out of Drive. |
| 503 AvoidDriveAsDownloadDirecotryPreference(); | 507 AvoidDriveAsDownloadDirecotryPreference(); |
| 504 | 508 |
| 505 // Back to NOT_INITIALIZED state. Then, re-running Initialize() should | 509 // Back to NOT_INITIALIZED state. Then, re-running Initialize() should |
| 506 // work if the error is recoverable manually (such as out of disk space). | 510 // work if the error is recoverable manually (such as out of disk space). |
| 507 state_ = NOT_INITIALIZED; | 511 state_ = NOT_INITIALIZED; |
| 508 return; | 512 return; |
| 509 } | 513 } |
| 510 | 514 |
| 515 // Initialize Download Handler for hooking downloads to the Drive folder. |
| 511 content::DownloadManager* download_manager = | 516 content::DownloadManager* download_manager = |
| 512 g_browser_process->download_status_updater() ? | 517 g_browser_process->download_status_updater() ? |
| 513 BrowserContext::GetDownloadManager(profile_) : NULL; | 518 BrowserContext::GetDownloadManager(profile_) : NULL; |
| 514 download_handler_->Initialize( | 519 download_handler_->Initialize( |
| 515 download_manager, | 520 download_manager, |
| 516 cache_root_directory_.Append(kTemporaryFileDirectory)); | 521 cache_root_directory_.Append(kTemporaryFileDirectory)); |
| 517 | 522 |
| 523 // Install the handler also to incognito profile. |
| 524 if (g_browser_process->download_status_updater()) { |
| 525 if (profile_->HasOffTheRecordProfile()) { |
| 526 download_handler_->ObserveIncognitoDownloadManager( |
| 527 BrowserContext::GetDownloadManager( |
| 528 profile_->GetOffTheRecordProfile())); |
| 529 } else { |
| 530 profile_notification_registrar_.reset(new content::NotificationRegistrar); |
| 531 profile_notification_registrar_->Add( |
| 532 this, |
| 533 chrome::NOTIFICATION_PROFILE_CREATED, |
| 534 content::NotificationService::AllSources()); |
| 535 } |
| 536 } |
| 537 |
| 518 // Register for Google Drive invalidation notifications. | 538 // Register for Google Drive invalidation notifications. |
| 519 DriveNotificationManager* drive_notification_manager = | 539 DriveNotificationManager* drive_notification_manager = |
| 520 DriveNotificationManagerFactory::GetForBrowserContext(profile_); | 540 DriveNotificationManagerFactory::GetForBrowserContext(profile_); |
| 521 if (drive_notification_manager) { | 541 if (drive_notification_manager) { |
| 522 drive_notification_manager->AddObserver(this); | 542 drive_notification_manager->AddObserver(this); |
| 523 const bool registered = | 543 const bool registered = |
| 524 drive_notification_manager->push_notification_registered(); | 544 drive_notification_manager->push_notification_registered(); |
| 525 const char* status = (registered ? "registered" : "not registered"); | 545 const char* status = (registered ? "registered" : "not registered"); |
| 526 logger_->Log(logging::LOG_INFO, "Push notification is %s", status); | 546 logger_->Log(logging::LOG_INFO, "Push notification is %s", status); |
| 527 | 547 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 541 void DriveIntegrationService::AvoidDriveAsDownloadDirecotryPreference() { | 561 void DriveIntegrationService::AvoidDriveAsDownloadDirecotryPreference() { |
| 542 PrefService* pref_service = profile_->GetPrefs(); | 562 PrefService* pref_service = profile_->GetPrefs(); |
| 543 if (util::IsUnderDriveMountPoint( | 563 if (util::IsUnderDriveMountPoint( |
| 544 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory))) { | 564 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory))) { |
| 545 pref_service->SetFilePath( | 565 pref_service->SetFilePath( |
| 546 prefs::kDownloadDefaultDirectory, | 566 prefs::kDownloadDefaultDirectory, |
| 547 file_manager::util::GetDownloadsFolderForProfile(profile_)); | 567 file_manager::util::GetDownloadsFolderForProfile(profile_)); |
| 548 } | 568 } |
| 549 } | 569 } |
| 550 | 570 |
| 571 void DriveIntegrationService::Observe( |
| 572 int type, |
| 573 const content::NotificationSource& source, |
| 574 const content::NotificationDetails& details) { |
| 575 if (type == chrome::NOTIFICATION_PROFILE_CREATED) { |
| 576 Profile* created_profile = content::Source<Profile>(source).ptr(); |
| 577 if (created_profile->IsOffTheRecord() && |
| 578 created_profile->IsSameProfile(profile_)) { |
| 579 download_handler_->ObserveIncognitoDownloadManager( |
| 580 BrowserContext::GetDownloadManager(created_profile)); |
| 581 profile_notification_registrar_->Remove( |
| 582 this, |
| 583 chrome::NOTIFICATION_PROFILE_CREATED, |
| 584 content::NotificationService::AllSources()); |
| 585 } |
| 586 } |
| 587 } |
| 588 |
| 551 //===================== DriveIntegrationServiceFactory ======================= | 589 //===================== DriveIntegrationServiceFactory ======================= |
| 552 | 590 |
| 553 DriveIntegrationServiceFactory::FactoryCallback* | 591 DriveIntegrationServiceFactory::FactoryCallback* |
| 554 DriveIntegrationServiceFactory::factory_for_test_ = NULL; | 592 DriveIntegrationServiceFactory::factory_for_test_ = NULL; |
| 555 | 593 |
| 556 DriveIntegrationServiceFactory::ScopedFactoryForTest::ScopedFactoryForTest( | 594 DriveIntegrationServiceFactory::ScopedFactoryForTest::ScopedFactoryForTest( |
| 557 FactoryCallback* factory_for_test) { | 595 FactoryCallback* factory_for_test) { |
| 558 factory_for_test_ = factory_for_test; | 596 factory_for_test_ = factory_for_test; |
| 559 } | 597 } |
| 560 | 598 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 "DriveIntegrationService", | 638 "DriveIntegrationService", |
| 601 BrowserContextDependencyManager::GetInstance()) { | 639 BrowserContextDependencyManager::GetInstance()) { |
| 602 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | 640 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
| 603 DependsOn(DriveNotificationManagerFactory::GetInstance()); | 641 DependsOn(DriveNotificationManagerFactory::GetInstance()); |
| 604 DependsOn(DownloadServiceFactory::GetInstance()); | 642 DependsOn(DownloadServiceFactory::GetInstance()); |
| 605 } | 643 } |
| 606 | 644 |
| 607 DriveIntegrationServiceFactory::~DriveIntegrationServiceFactory() { | 645 DriveIntegrationServiceFactory::~DriveIntegrationServiceFactory() { |
| 608 } | 646 } |
| 609 | 647 |
| 648 content::BrowserContext* DriveIntegrationServiceFactory::GetBrowserContextToUse( |
| 649 content::BrowserContext* context) const { |
| 650 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 651 } |
| 652 |
| 610 KeyedService* DriveIntegrationServiceFactory::BuildServiceInstanceFor( | 653 KeyedService* DriveIntegrationServiceFactory::BuildServiceInstanceFor( |
| 611 content::BrowserContext* context) const { | 654 content::BrowserContext* context) const { |
| 612 Profile* profile = Profile::FromBrowserContext(context); | 655 Profile* profile = Profile::FromBrowserContext(context); |
| 613 | 656 |
| 614 DriveIntegrationService* service = NULL; | 657 DriveIntegrationService* service = NULL; |
| 615 if (!factory_for_test_) { | 658 if (!factory_for_test_) { |
| 616 DriveIntegrationService::PreferenceWatcher* preference_watcher = NULL; | 659 DriveIntegrationService::PreferenceWatcher* preference_watcher = NULL; |
| 617 if (chromeos::IsProfileAssociatedWithGaiaAccount(profile)) { | 660 if (chromeos::IsProfileAssociatedWithGaiaAccount(profile)) { |
| 618 // Drive File System can be enabled. | 661 // Drive File System can be enabled. |
| 619 preference_watcher = | 662 preference_watcher = |
| 620 new DriveIntegrationService::PreferenceWatcher(profile->GetPrefs()); | 663 new DriveIntegrationService::PreferenceWatcher(profile->GetPrefs()); |
| 621 } | 664 } |
| 622 | 665 |
| 623 service = new DriveIntegrationService( | 666 service = new DriveIntegrationService( |
| 624 profile, preference_watcher, | 667 profile, preference_watcher, |
| 625 NULL, std::string(), base::FilePath(), NULL); | 668 NULL, std::string(), base::FilePath(), NULL); |
| 626 } else { | 669 } else { |
| 627 service = factory_for_test_->Run(profile); | 670 service = factory_for_test_->Run(profile); |
| 628 } | 671 } |
| 629 | 672 |
| 630 return service; | 673 return service; |
| 631 } | 674 } |
| 632 | 675 |
| 633 } // namespace drive | 676 } // namespace drive |
| OLD | NEW |