diff options
6 files changed, 20 insertions, 16 deletions
diff --git a/chrome/browser/sync_file_system/drive_backend/drive_service_on_worker.cc b/chrome/browser/sync_file_system/drive_backend/drive_service_on_worker.cc index 935a351..8fc92d7 100644 --- a/chrome/browser/sync_file_system/drive_backend/drive_service_on_worker.cc +++ b/chrome/browser/sync_file_system/drive_backend/drive_service_on_worker.cc @@ -93,7 +93,6 @@ google_apis::CancelCallback DriveServiceOnWorker::DownloadFile( return google_apis::CancelCallback(); } - google_apis::CancelCallback DriveServiceOnWorker::GetAboutResource( const google_apis::AboutResourceCallback& callback) { ui_task_runner_->PostTask( @@ -108,7 +107,6 @@ google_apis::CancelCallback DriveServiceOnWorker::GetAboutResource( return google_apis::CancelCallback(); } - google_apis::CancelCallback DriveServiceOnWorker::GetChangeList( int64 start_changestamp, const google_apis::ChangeListCallback& callback) { @@ -233,10 +231,8 @@ google_apis::CancelCallback DriveServiceOnWorker::SearchByTitle( } bool DriveServiceOnWorker::HasRefreshToken() const { - // TODO(peria): Cache the state and returns it directly, before migration of - // SyncWorker to a worker thread. - DCHECK(wrapper_); - return wrapper_->HasRefreshToken(); + NOTREACHED(); + return false; } void DriveServiceOnWorker::Initialize(const std::string& account_id) { diff --git a/chrome/browser/sync_file_system/drive_backend/drive_service_wrapper.cc b/chrome/browser/sync_file_system/drive_backend/drive_service_wrapper.cc index 7a65400..24c328f 100644 --- a/chrome/browser/sync_file_system/drive_backend/drive_service_wrapper.cc +++ b/chrome/browser/sync_file_system/drive_backend/drive_service_wrapper.cc @@ -86,10 +86,6 @@ void DriveServiceWrapper::GetFileListInDirectory( drive_service_->GetFileListInDirectory(directory_resource_id, callback); } -bool DriveServiceWrapper::HasRefreshToken() const { - return drive_service_->HasRefreshToken(); -} - void DriveServiceWrapper::RemoveResourceFromDirectory( const std::string& parent_resource_id, const std::string& resource_id, diff --git a/chrome/browser/sync_file_system/drive_backend/drive_service_wrapper.h b/chrome/browser/sync_file_system/drive_backend/drive_service_wrapper.h index 760d8c3..ce15950 100644 --- a/chrome/browser/sync_file_system/drive_backend/drive_service_wrapper.h +++ b/chrome/browser/sync_file_system/drive_backend/drive_service_wrapper.h @@ -60,8 +60,6 @@ class DriveServiceWrapper : public base::SupportsWeakPtr<DriveServiceWrapper> { const std::string& directory_resource_id, const google_apis::FileListCallback& callback); - bool HasRefreshToken() const; - void RemoveResourceFromDirectory( const std::string& parent_resource_id, const std::string& resource_id, diff --git a/chrome/browser/sync_file_system/drive_backend/sync_engine_unittest.cc b/chrome/browser/sync_file_system/drive_backend/sync_engine_unittest.cc index 88cc072..5c353a3 100644 --- a/chrome/browser/sync_file_system/drive_backend/sync_engine_unittest.cc +++ b/chrome/browser/sync_file_system/drive_backend/sync_engine_unittest.cc @@ -152,7 +152,11 @@ class SyncEngineTest } MetadataDatabase* metadata_database() { - return sync_engine()->sync_worker_->GetMetadataDatabase(); + return sync_engine_->sync_worker_->GetMetadataDatabase(); + } + + void SetHasRefreshToken(bool has_refresh_token) { + sync_engine_->sync_worker_->has_refresh_token_ = has_refresh_token; } private: @@ -281,6 +285,8 @@ TEST_F(SyncEngineTest, GetOriginStatusMap) { TEST_F(SyncEngineTest, UpdateServiceState) { EXPECT_EQ(REMOTE_SERVICE_OK, sync_engine()->GetCurrentState()); + SetHasRefreshToken(true); + GetSyncEngineTaskManager()->ScheduleTask( FROM_HERE, base::Bind(&EmptyTask, SYNC_STATUS_AUTHENTICATION_FAILED), diff --git a/chrome/browser/sync_file_system/drive_backend/sync_worker.cc b/chrome/browser/sync_file_system/drive_backend/sync_worker.cc index 8841989..6a95d61 100644 --- a/chrome/browser/sync_file_system/drive_backend/sync_worker.cc +++ b/chrome/browser/sync_file_system/drive_backend/sync_worker.cc @@ -102,6 +102,7 @@ SyncWorker::SyncWorker( network_available_(false), extension_service_(extension_service), context_(sync_engine_context.Pass()), + has_refresh_token_(false), weak_ptr_factory_(this) {} SyncWorker::~SyncWorker() {} @@ -124,7 +125,7 @@ void SyncWorker::Initialize() { void SyncWorker::RegisterOrigin( const GURL& origin, const SyncStatusCallback& callback) { - if (!GetMetadataDatabase() && GetDriveService()->HasRefreshToken()) + if (!GetMetadataDatabase() && has_refresh_token_) PostInitializeTask(); scoped_ptr<RegisterAppTask> task( @@ -346,6 +347,7 @@ void SyncWorker::OnNotificationReceived() { } void SyncWorker::OnReadyToSendRequests(const std::string& account_id) { + has_refresh_token_ = true; if (service_state_ == REMOTE_SERVICE_OK) return; UpdateServiceState(REMOTE_SERVICE_OK, "Authenticated"); @@ -361,6 +363,8 @@ void SyncWorker::OnReadyToSendRequests(const std::string& account_id) { } void SyncWorker::OnRefreshTokenInvalid() { + has_refresh_token_ = false; + UpdateServiceState( REMOTE_SERVICE_AUTHENTICATION_REQUIRED, "Found invalid refresh token."); @@ -442,7 +446,7 @@ void SyncWorker::PostInitializeTask() { void SyncWorker::DidInitialize(SyncEngineInitializer* initializer, SyncStatusCode status) { if (status != SYNC_STATUS_OK) { - if (GetDriveService()->HasRefreshToken()) { + if (has_refresh_token_) { UpdateServiceState(REMOTE_SERVICE_TEMPORARY_UNAVAILABLE, "Could not initialize remote service"); } else { @@ -671,7 +675,7 @@ void SyncWorker::UpdateServiceStateFromSyncStatusCode( case SYNC_STATUS_NETWORK_ERROR: case SYNC_STATUS_ABORT: case SYNC_STATUS_FAILED: - if (GetDriveService()->HasRefreshToken()) { + if (has_refresh_token_) { UpdateServiceState(REMOTE_SERVICE_TEMPORARY_UNAVAILABLE, "Network or temporary service error."); } else { diff --git a/chrome/browser/sync_file_system/drive_backend/sync_worker.h b/chrome/browser/sync_file_system/drive_backend/sync_worker.h index 55ce551..64f0312 100644 --- a/chrome/browser/sync_file_system/drive_backend/sync_worker.h +++ b/chrome/browser/sync_file_system/drive_backend/sync_worker.h @@ -138,6 +138,8 @@ class SyncWorker : public SyncTaskManager::Client { void AddObserver(Observer* observer); private: + friend class SyncEngineTest; + void DoDisableApp(const std::string& app_id, const SyncStatusCallback& callback); void DoEnableApp(const std::string& app_id, @@ -188,6 +190,8 @@ class SyncWorker : public SyncTaskManager::Client { scoped_ptr<SyncEngineContext> context_; ObserverList<Observer> observers_; + bool has_refresh_token_; + base::WeakPtrFactory<SyncWorker> weak_ptr_factory_; DISALLOW_COPY_AND_ASSIGN(SyncWorker); }; |