Chromium Code Reviews| Index: chrome/browser/chromeos/drive/drive_sync_client.cc |
| diff --git a/chrome/browser/chromeos/drive/drive_sync_client.cc b/chrome/browser/chromeos/drive/drive_sync_client.cc |
| index 09dd15c8830c4a662912367432c2f8a0d6869600..d185ac9b445a59533e26786264de498f42410ded 100644 |
| --- a/chrome/browser/chromeos/drive/drive_sync_client.cc |
| +++ b/chrome/browser/chromeos/drive/drive_sync_client.cc |
| @@ -104,7 +104,7 @@ DriveSyncClient::~DriveSyncClient() { |
| file_system_->RemoveObserver(this); |
| if (cache_) |
| cache_->RemoveObserver(this); |
| - net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| + net::NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| } |
| void DriveSyncClient::Initialize() { |
| @@ -113,7 +113,7 @@ void DriveSyncClient::Initialize() { |
| file_system_->AddObserver(this); |
| cache_->AddObserver(this); |
| - net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
| + net::NetworkChangeNotifier::AddNetworkChangeObserver(this); |
| registrar_->Init(profile_->GetPrefs()); |
| base::Closure callback = base::Bind( |
| @@ -154,15 +154,15 @@ std::vector<std::string> DriveSyncClient::GetResourceIdsForTesting( |
| return resource_ids; |
| } |
| -void DriveSyncClient::StartSyncLoop() { |
| +void DriveSyncClient::StartSyncLoop(bool force_offline) { |
| if (!sync_loop_is_running_) |
| - DoSyncLoop(); |
| + DoSyncLoop(force_offline); |
| } |
| -void DriveSyncClient::DoSyncLoop() { |
| +void DriveSyncClient::DoSyncLoop(bool force_offline) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| - if (ShouldStopSyncLoop()) { |
| + if (ShouldStopSyncLoop(force_offline)) { |
| // Note that |queue_| is not cleared so the sync loop can resume. |
| sync_loop_is_running_ = false; |
| FOR_EACH_OBSERVER(DriveSyncClientObserver, observers_, |
| @@ -186,7 +186,8 @@ void DriveSyncClient::DoSyncLoop() { |
| const bool posted = base::MessageLoopProxy::current()->PostDelayedTask( |
| FROM_HERE, |
| base::Bind(&DriveSyncClient::DoSyncLoop, |
| - weak_ptr_factory_.GetWeakPtr()), |
| + weak_ptr_factory_.GetWeakPtr(), |
| + force_offline), |
|
szym
2013/01/20 06:52:08
I was concerned that, because it's using PostDelay
|
| delay_); |
| DCHECK(posted); |
| return; |
| @@ -215,14 +216,14 @@ void DriveSyncClient::DoSyncLoop() { |
| } |
| } |
| -bool DriveSyncClient::ShouldStopSyncLoop() { |
| +bool DriveSyncClient::ShouldStopSyncLoop(bool force_offline) { |
| // Should stop if the drive feature was disabled while running the fetch |
| // loop. |
| if (profile_->GetPrefs()->GetBoolean(prefs::kDisableDrive)) |
| return true; |
| // Should stop if the network is not online. |
| - if (net::NetworkChangeNotifier::IsOffline()) |
| + if (force_offline || net::NetworkChangeNotifier::IsOffline()) |
| return true; |
| // Should stop if the current connection is on cellular network, and |
| @@ -253,7 +254,7 @@ void DriveSyncClient::OnCachePinned(const std::string& resource_id, |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| AddTaskToQueue(SyncTask(FETCH, resource_id, base::Time::Now())); |
| - StartSyncLoop(); |
| + StartSyncLoop(false); |
| } |
| void DriveSyncClient::OnCacheUnpinned(const std::string& resource_id, |
| @@ -273,7 +274,7 @@ void DriveSyncClient::OnCacheCommitted(const std::string& resource_id) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| AddTaskToQueue(SyncTask(UPLOAD, resource_id, base::Time::Now())); |
| - StartSyncLoop(); |
| + StartSyncLoop(false); |
| } |
| void DriveSyncClient::AddObserver(DriveSyncClientObserver* observer) { |
| @@ -318,7 +319,7 @@ void DriveSyncClient::OnGetResourceIdsOfBacklog( |
| AddTaskToQueue(SyncTask(FETCH, resource_id, base::Time::Now())); |
| } |
| - StartSyncLoop(); |
| + StartSyncLoop(false); |
| } |
| void DriveSyncClient::OnGetResourceIdOfExistingPinnedFile( |
| @@ -393,7 +394,7 @@ void DriveSyncClient::OnPinned(const std::string& resource_id, |
| // Finally, adding to the queue. |
| AddTaskToQueue(SyncTask(FETCH, resource_id, base::Time::Now())); |
| - StartSyncLoop(); |
| + StartSyncLoop(false); |
| } |
| void DriveSyncClient::OnFetchFileComplete(const SyncTask& sync_task, |
| @@ -419,7 +420,7 @@ void DriveSyncClient::OnFetchFileComplete(const SyncTask& sync_task, |
| } |
| // Continue the loop. |
| - DoSyncLoop(); |
| + DoSyncLoop(false); |
| } |
| void DriveSyncClient::OnUploadFileComplete(const std::string& resource_id, |
| @@ -434,7 +435,7 @@ void DriveSyncClient::OnUploadFileComplete(const std::string& resource_id, |
| } |
| // Continue the loop. |
| - DoSyncLoop(); |
| + DoSyncLoop(false); |
| } |
| void DriveSyncClient::OnDriveSyncPreferenceChanged() { |
| @@ -443,17 +444,17 @@ void DriveSyncClient::OnDriveSyncPreferenceChanged() { |
| // Resume the sync loop if gdata preferences are changed. Note that we |
| // don't need to check the new values here as these will be checked in |
| // ShouldStopSyncLoop() as soon as the loop is resumed. |
| - StartSyncLoop(); |
| + StartSyncLoop(false); |
| } |
| -void DriveSyncClient::OnConnectionTypeChanged( |
| +void DriveSyncClient::OnNetworkChanged( |
| net::NetworkChangeNotifier::ConnectionType type) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| // Resume the sync loop if the network is changed. Note that we don't need to |
| // check the type of the network as it will be checked in ShouldStopSyncLoop() |
| // as soon as the loop is resumed. |
| - StartSyncLoop(); |
| + StartSyncLoop(type == net::NetworkChangeNotifier::CONNECTION_NONE); |
|
szym
2013/01/20 06:52:08
Consider the result of |StartSyncLoop(true)|.
Cas
|
| } |
| } // namespace drive |