| 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_sync_client.h" | 5 #include "chrome/browser/chromeos/drive/drive_sync_client.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/message_loop_proxy.h" | 11 #include "base/message_loop_proxy.h" |
| 12 #include "chrome/browser/api/prefs/pref_change_registrar.h" | 12 #include "chrome/browser/api/prefs/pref_change_registrar.h" |
| 13 #include "chrome/browser/chromeos/drive/drive.pb.h" | 13 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 14 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" | 14 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" |
| 15 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 15 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
| 16 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 | 20 |
| 21 using content::BrowserThread; | 21 using content::BrowserThread; |
| 22 | 22 |
| 23 namespace gdata { | 23 namespace drive { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 // The delay constant is used to delay processing a SyncTask in | 27 // The delay constant is used to delay processing a SyncTask in |
| 28 // DoSyncLoop(). We should not process SyncTasks immediately for the | 28 // DoSyncLoop(). We should not process SyncTasks immediately for the |
| 29 // following reasons: | 29 // following reasons: |
| 30 // | 30 // |
| 31 // 1) For fetching, the user may accidentally click on "Make available | 31 // 1) For fetching, the user may accidentally click on "Make available |
| 32 // offline" checkbox on a file, and immediately cancel it in a second. | 32 // offline" checkbox on a file, and immediately cancel it in a second. |
| 33 // It's a waste to fetch the file in this case. | 33 // It's a waste to fetch the file in this case. |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 } | 162 } |
| 163 | 163 |
| 164 queue_.pop_front(); | 164 queue_.pop_front(); |
| 165 if (sync_task.sync_type == FETCH) { | 165 if (sync_task.sync_type == FETCH) { |
| 166 DVLOG(1) << "Fetching " << sync_task.resource_id; | 166 DVLOG(1) << "Fetching " << sync_task.resource_id; |
| 167 file_system_->GetFileByResourceId( | 167 file_system_->GetFileByResourceId( |
| 168 sync_task.resource_id, | 168 sync_task.resource_id, |
| 169 base::Bind(&DriveSyncClient::OnFetchFileComplete, | 169 base::Bind(&DriveSyncClient::OnFetchFileComplete, |
| 170 weak_ptr_factory_.GetWeakPtr(), | 170 weak_ptr_factory_.GetWeakPtr(), |
| 171 sync_task), | 171 sync_task), |
| 172 GetContentCallback()); | 172 gdata::GetContentCallback()); |
| 173 } else if (sync_task.sync_type == UPLOAD) { | 173 } else if (sync_task.sync_type == UPLOAD) { |
| 174 DVLOG(1) << "Uploading " << sync_task.resource_id; | 174 DVLOG(1) << "Uploading " << sync_task.resource_id; |
| 175 file_system_->UpdateFileByResourceId( | 175 file_system_->UpdateFileByResourceId( |
| 176 sync_task.resource_id, | 176 sync_task.resource_id, |
| 177 base::Bind(&DriveSyncClient::OnUploadFileComplete, | 177 base::Bind(&DriveSyncClient::OnUploadFileComplete, |
| 178 weak_ptr_factory_.GetWeakPtr(), | 178 weak_ptr_factory_.GetWeakPtr(), |
| 179 sync_task.resource_id)); | 179 sync_task.resource_id)); |
| 180 } else { | 180 } else { |
| 181 NOTREACHED() << ": Unexpected sync type: " << sync_task.sync_type; | 181 NOTREACHED() << ": Unexpected sync type: " << sync_task.sync_type; |
| 182 } | 182 } |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 net::NetworkChangeNotifier::ConnectionType type) { | 428 net::NetworkChangeNotifier::ConnectionType type) { |
| 429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 430 | 430 |
| 431 // Resume the sync loop if the network is back online. Note that we don't | 431 // Resume the sync loop if the network is back online. Note that we don't |
| 432 // need to check the type of the network as it will be checked in | 432 // need to check the type of the network as it will be checked in |
| 433 // ShouldStopSyncLoop() as soon as the loop is resumed. | 433 // ShouldStopSyncLoop() as soon as the loop is resumed. |
| 434 if (!net::NetworkChangeNotifier::IsOffline()) | 434 if (!net::NetworkChangeNotifier::IsOffline()) |
| 435 StartSyncLoop(); | 435 StartSyncLoop(); |
| 436 } | 436 } |
| 437 | 437 |
| 438 } // namespace gdata | 438 } // namespace drive |
| OLD | NEW |