| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 enabled_(false), | 181 enabled_(false), |
| 182 cache_root_directory_(!test_cache_root.empty() ? | 182 cache_root_directory_(!test_cache_root.empty() ? |
| 183 test_cache_root : util::GetCacheRootPath(profile)), | 183 test_cache_root : util::GetCacheRootPath(profile)), |
| 184 weak_ptr_factory_(this) { | 184 weak_ptr_factory_(this) { |
| 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 186 | 186 |
| 187 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); | 187 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); |
| 188 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( | 188 blocking_task_runner_ = blocking_pool->GetSequencedTaskRunner( |
| 189 blocking_pool->GetSequenceToken()); | 189 blocking_pool->GetSequenceToken()); |
| 190 | 190 |
| 191 OAuth2TokenService* oauth_service = | 191 ProfileOAuth2TokenService* oauth_service = |
| 192 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 192 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 193 | 193 |
| 194 if (test_drive_service) { | 194 if (test_drive_service) { |
| 195 drive_service_.reset(test_drive_service); | 195 drive_service_.reset(test_drive_service); |
| 196 } else if (util::IsDriveV2ApiEnabled()) { | 196 } else if (util::IsDriveV2ApiEnabled()) { |
| 197 drive_service_.reset(new DriveAPIService( | 197 drive_service_.reset(new DriveAPIService( |
| 198 oauth_service, | 198 oauth_service, |
| 199 g_browser_process->system_request_context(), | 199 g_browser_process->system_request_context(), |
| 200 blocking_task_runner_.get(), | 200 blocking_task_runner_.get(), |
| 201 GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction), | 201 GURL(google_apis::DriveApiUrlGenerator::kBaseUrlForProduction), |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 util::GetDriveMountPointPath().BaseName().AsUTF8Unsafe()); | 414 util::GetDriveMountPointPath().BaseName().AsUTF8Unsafe()); |
| 415 util::Log(logging::LOG_INFO, "Drive mount point is removed"); | 415 util::Log(logging::LOG_INFO, "Drive mount point is removed"); |
| 416 } | 416 } |
| 417 | 417 |
| 418 void DriveIntegrationService::Initialize() { | 418 void DriveIntegrationService::Initialize() { |
| 419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 420 DCHECK_EQ(NOT_INITIALIZED, state_); | 420 DCHECK_EQ(NOT_INITIALIZED, state_); |
| 421 DCHECK(enabled_); | 421 DCHECK(enabled_); |
| 422 | 422 |
| 423 state_ = INITIALIZING; | 423 state_ = INITIALIZING; |
| 424 drive_service_->Initialize(); | |
| 425 | 424 |
| 426 base::PostTaskAndReplyWithResult( | 425 base::PostTaskAndReplyWithResult( |
| 427 blocking_task_runner_.get(), | 426 blocking_task_runner_.get(), |
| 428 FROM_HERE, | 427 FROM_HERE, |
| 429 base::Bind(&InitializeMetadata, | 428 base::Bind(&InitializeMetadata, |
| 430 cache_root_directory_, | 429 cache_root_directory_, |
| 431 metadata_storage_.get(), | 430 metadata_storage_.get(), |
| 432 cache_.get(), | 431 cache_.get(), |
| 433 resource_metadata_.get(), | 432 resource_metadata_.get(), |
| 434 drive_service_->GetResourceIdCanonicalizer()), | 433 drive_service_->GetResourceIdCanonicalizer()), |
| 435 base::Bind(&DriveIntegrationService::InitializeAfterMetadataInitialized, | 434 base::Bind(&DriveIntegrationService::InitializeAfterMetadataInitialized, |
| 436 weak_ptr_factory_.GetWeakPtr())); | 435 weak_ptr_factory_.GetWeakPtr())); |
| 437 } | 436 } |
| 438 | 437 |
| 439 void DriveIntegrationService::InitializeAfterMetadataInitialized( | 438 void DriveIntegrationService::InitializeAfterMetadataInitialized( |
| 440 FileError error) { | 439 FileError error) { |
| 441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 442 DCHECK_EQ(INITIALIZING, state_); | 441 DCHECK_EQ(INITIALIZING, state_); |
| 443 | 442 |
| 443 drive_service_->Initialize( |
| 444 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
| 445 GetPrimaryAccountId()); |
| 446 |
| 444 if (error != FILE_ERROR_OK) { | 447 if (error != FILE_ERROR_OK) { |
| 445 LOG(WARNING) << "Failed to initialize: " << FileErrorToString(error); | 448 LOG(WARNING) << "Failed to initialize: " << FileErrorToString(error); |
| 446 | 449 |
| 447 // Change the download directory to the default value if the download | 450 // Change the download directory to the default value if the download |
| 448 // destination is set to under Drive mount point. | 451 // destination is set to under Drive mount point. |
| 449 PrefService* pref_service = profile_->GetPrefs(); | 452 PrefService* pref_service = profile_->GetPrefs(); |
| 450 if (util::IsUnderDriveMountPoint( | 453 if (util::IsUnderDriveMountPoint( |
| 451 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory))) { | 454 pref_service->GetFilePath(prefs::kDownloadDefaultDirectory))) { |
| 452 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, | 455 pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, |
| 453 DownloadPrefs::GetDefaultDownloadDirectory()); | 456 DownloadPrefs::GetDefaultDownloadDirectory()); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 NULL, base::FilePath(), NULL); | 563 NULL, base::FilePath(), NULL); |
| 561 } else { | 564 } else { |
| 562 service = factory_for_test_.Run(profile); | 565 service = factory_for_test_.Run(profile); |
| 563 } | 566 } |
| 564 | 567 |
| 565 service->SetEnabled(drive::util::IsDriveEnabledForProfile(profile)); | 568 service->SetEnabled(drive::util::IsDriveEnabledForProfile(profile)); |
| 566 return service; | 569 return service; |
| 567 } | 570 } |
| 568 | 571 |
| 569 } // namespace drive | 572 } // namespace drive |
| OLD | NEW |