Chromium Code Reviews| Index: chrome/browser/chromeos/drive/drive_integration_service.cc |
| diff --git a/chrome/browser/chromeos/drive/drive_integration_service.cc b/chrome/browser/chromeos/drive/drive_integration_service.cc |
| index 9ea18aa4a526ab817859a2c3495a7fdbbfb196e5..3d16655d3030e47b695cc6387d0ab870abab0d3c 100644 |
| --- a/chrome/browser/chromeos/drive/drive_integration_service.cc |
| +++ b/chrome/browser/chromeos/drive/drive_integration_service.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/strings/stringprintf.h" |
| #include "base/threading/sequenced_worker_pool.h" |
| #include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/chromeos/drive/debug_info_collector.h" |
| #include "chrome/browser/chromeos/drive/download_handler.h" |
| #include "chrome/browser/chromeos/drive/file_cache.h" |
| @@ -30,6 +31,7 @@ |
| #include "chrome/browser/drive/drive_notification_manager.h" |
| #include "chrome/browser/drive/drive_notification_manager_factory.h" |
| #include "chrome/browser/drive/event_logger.h" |
| +#include "chrome/browser/profiles/incognito_helpers.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| #include "chrome/browser/signin/signin_manager_factory.h" |
| @@ -40,6 +42,7 @@ |
| #include "components/signin/core/browser/signin_manager.h" |
| #include "content/public/browser/browser_context.h" |
| #include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/notification_service.h" |
| #include "content/public/common/user_agent.h" |
| #include "google_apis/drive/auth_service.h" |
| #include "google_apis/drive/gdata_wapi_url_generator.h" |
| @@ -221,6 +224,7 @@ DriveIntegrationService::DriveIntegrationService( |
| test_cache_root : util::GetCacheRootPath(profile)), |
| weak_ptr_factory_(this) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + DCHECK(profile && !profile->IsOffTheRecord()); |
| logger_.reset(new EventLogger); |
| base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); |
| @@ -508,6 +512,7 @@ void DriveIntegrationService::InitializeAfterMetadataInitialized( |
| return; |
| } |
| + // Initialize Download Handler for hooking downloads to the Drive folder. |
| content::DownloadManager* download_manager = |
| g_browser_process->download_status_updater() ? |
| BrowserContext::GetDownloadManager(profile_) : NULL; |
| @@ -515,6 +520,21 @@ void DriveIntegrationService::InitializeAfterMetadataInitialized( |
| download_manager, |
| cache_root_directory_.Append(kTemporaryFileDirectory)); |
| + // Installs the handler also to incognito profile. |
|
hashimoto
2014/06/03 06:10:32
nit-picking-nit: s/Installs/Install/
kinaba
2014/06/03 06:50:32
Done.
|
| + if (g_browser_process->download_status_updater()) { |
| + if (profile_->HasOffTheRecordProfile()) { |
| + download_handler_->ObserveIncognitoDownloadManager( |
| + BrowserContext::GetDownloadManager( |
| + profile_->GetOffTheRecordProfile())); |
| + } else { |
| + profile_notification_registrar_.reset(new content::NotificationRegistrar); |
| + profile_notification_registrar_->Add( |
| + this, |
| + chrome::NOTIFICATION_PROFILE_CREATED, |
| + content::NotificationService::AllSources()); |
| + } |
| + } |
| + |
| // Register for Google Drive invalidation notifications. |
| DriveNotificationManager* drive_notification_manager = |
| DriveNotificationManagerFactory::GetForBrowserContext(profile_); |
| @@ -548,6 +568,24 @@ void DriveIntegrationService::AvoidDriveAsDownloadDirecotryPreference() { |
| } |
| } |
| +void DriveIntegrationService::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + if (type == chrome::NOTIFICATION_PROFILE_CREATED) { |
| + Profile* created_profile = content::Source<Profile>(source).ptr(); |
| + if (created_profile->IsOffTheRecord() && |
| + created_profile->IsSameProfile(profile_)) { |
| + download_handler_->ObserveIncognitoDownloadManager( |
| + BrowserContext::GetDownloadManager(created_profile)); |
| + profile_notification_registrar_->Remove( |
| + this, |
| + chrome::NOTIFICATION_PROFILE_CREATED, |
| + content::NotificationService::AllSources()); |
| + } |
| + } |
| +} |
| + |
| //===================== DriveIntegrationServiceFactory ======================= |
| DriveIntegrationServiceFactory::FactoryCallback* |
| @@ -607,6 +645,11 @@ DriveIntegrationServiceFactory::DriveIntegrationServiceFactory() |
| DriveIntegrationServiceFactory::~DriveIntegrationServiceFactory() { |
| } |
| +content::BrowserContext* DriveIntegrationServiceFactory::GetBrowserContextToUse( |
| + content::BrowserContext* context) const { |
| + return chrome::GetBrowserContextRedirectedInIncognito(context); |
| +} |
| + |
| KeyedService* DriveIntegrationServiceFactory::BuildServiceInstanceFor( |
| content::BrowserContext* context) const { |
| Profile* profile = Profile::FromBrowserContext(context); |