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/gdata/gdata_sync_client.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_sync_client.h" |
6 | 6 |
7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 file_system_->GetEntryInfoByResourceId( | 314 file_system_->GetEntryInfoByResourceId( |
315 resource_id, | 315 resource_id, |
316 base::Bind(&GDataSyncClient::OnGetEntryInfoByResourceId, | 316 base::Bind(&GDataSyncClient::OnGetEntryInfoByResourceId, |
317 weak_ptr_factory_.GetWeakPtr(), | 317 weak_ptr_factory_.GetWeakPtr(), |
318 resource_id)); | 318 resource_id)); |
319 } | 319 } |
320 } | 320 } |
321 | 321 |
322 void GDataSyncClient::OnGetEntryInfoByResourceId( | 322 void GDataSyncClient::OnGetEntryInfoByResourceId( |
323 const std::string& resource_id, | 323 const std::string& resource_id, |
324 GDataFileError error, | 324 DriveFileError error, |
325 const FilePath& /* gdata_file_path */, | 325 const FilePath& /* gdata_file_path */, |
326 scoped_ptr<DriveEntryProto> entry_proto) { | 326 scoped_ptr<DriveEntryProto> entry_proto) { |
327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
328 | 328 |
329 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 329 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
330 error = GDATA_FILE_ERROR_NOT_FOUND; | 330 error = DRIVE_FILE_ERROR_NOT_FOUND; |
331 | 331 |
332 if (error != GDATA_FILE_OK) { | 332 if (error != DRIVE_FILE_OK) { |
333 LOG(WARNING) << "Entry not found: " << resource_id; | 333 LOG(WARNING) << "Entry not found: " << resource_id; |
334 return; | 334 return; |
335 } | 335 } |
336 | 336 |
337 cache_->GetCacheEntryOnUIThread( | 337 cache_->GetCacheEntryOnUIThread( |
338 resource_id, | 338 resource_id, |
339 "" /* don't check MD5 */, | 339 "" /* don't check MD5 */, |
340 base::Bind(&GDataSyncClient::OnGetCacheEntry, | 340 base::Bind(&GDataSyncClient::OnGetCacheEntry, |
341 weak_ptr_factory_.GetWeakPtr(), | 341 weak_ptr_factory_.GetWeakPtr(), |
342 resource_id, | 342 resource_id, |
(...skipping 16 matching lines...) Expand all Loading... |
359 // the file is dirty (the MD5 is "local"). We should never re-fetch the | 359 // the file is dirty (the MD5 is "local"). We should never re-fetch the |
360 // file when we have a locally modified version. | 360 // file when we have a locally modified version. |
361 if (latest_md5 != cache_entry.md5() && !cache_entry.is_dirty()) { | 361 if (latest_md5 != cache_entry.md5() && !cache_entry.is_dirty()) { |
362 cache_->RemoveOnUIThread( | 362 cache_->RemoveOnUIThread( |
363 resource_id, | 363 resource_id, |
364 base::Bind(&GDataSyncClient::OnRemove, | 364 base::Bind(&GDataSyncClient::OnRemove, |
365 weak_ptr_factory_.GetWeakPtr())); | 365 weak_ptr_factory_.GetWeakPtr())); |
366 } | 366 } |
367 } | 367 } |
368 | 368 |
369 void GDataSyncClient::OnRemove(GDataFileError error, | 369 void GDataSyncClient::OnRemove(DriveFileError error, |
370 const std::string& resource_id, | 370 const std::string& resource_id, |
371 const std::string& md5) { | 371 const std::string& md5) { |
372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
373 | 373 |
374 if (error != GDATA_FILE_OK) { | 374 if (error != DRIVE_FILE_OK) { |
375 LOG(WARNING) << "Failed to remove cache entry: " << resource_id; | 375 LOG(WARNING) << "Failed to remove cache entry: " << resource_id; |
376 return; | 376 return; |
377 } | 377 } |
378 | 378 |
379 // Before fetching, we should pin this file again, so that the fetched file | 379 // Before fetching, we should pin this file again, so that the fetched file |
380 // is downloaded properly to the persistent directory and marked pinned. | 380 // is downloaded properly to the persistent directory and marked pinned. |
381 cache_->PinOnUIThread(resource_id, | 381 cache_->PinOnUIThread(resource_id, |
382 md5, | 382 md5, |
383 base::Bind(&GDataSyncClient::OnPinned, | 383 base::Bind(&GDataSyncClient::OnPinned, |
384 weak_ptr_factory_.GetWeakPtr())); | 384 weak_ptr_factory_.GetWeakPtr())); |
385 } | 385 } |
386 | 386 |
387 void GDataSyncClient::OnPinned(GDataFileError error, | 387 void GDataSyncClient::OnPinned(DriveFileError error, |
388 const std::string& resource_id, | 388 const std::string& resource_id, |
389 const std::string& /* md5 */) { | 389 const std::string& /* md5 */) { |
390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
391 | 391 |
392 if (error != GDATA_FILE_OK) { | 392 if (error != DRIVE_FILE_OK) { |
393 LOG(WARNING) << "Failed to pin cache entry: " << resource_id; | 393 LOG(WARNING) << "Failed to pin cache entry: " << resource_id; |
394 return; | 394 return; |
395 } | 395 } |
396 | 396 |
397 // Finally, adding to the queue. | 397 // Finally, adding to the queue. |
398 AddTaskToQueue(SyncTask(FETCH, resource_id, base::Time::Now())); | 398 AddTaskToQueue(SyncTask(FETCH, resource_id, base::Time::Now())); |
399 StartSyncLoop(); | 399 StartSyncLoop(); |
400 } | 400 } |
401 | 401 |
402 void GDataSyncClient::OnFetchFileComplete(const SyncTask& sync_task, | 402 void GDataSyncClient::OnFetchFileComplete(const SyncTask& sync_task, |
403 GDataFileError error, | 403 DriveFileError error, |
404 const FilePath& local_path, | 404 const FilePath& local_path, |
405 const std::string& ununsed_mime_type, | 405 const std::string& ununsed_mime_type, |
406 DriveFileType file_type) { | 406 DriveFileType file_type) { |
407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
408 | 408 |
409 if (error == GDATA_FILE_OK) { | 409 if (error == DRIVE_FILE_OK) { |
410 DVLOG(1) << "Fetched " << sync_task.resource_id << ": " | 410 DVLOG(1) << "Fetched " << sync_task.resource_id << ": " |
411 << local_path.value(); | 411 << local_path.value(); |
412 } else { | 412 } else { |
413 switch (error) { | 413 switch (error) { |
414 case GDATA_FILE_ERROR_NO_CONNECTION: | 414 case DRIVE_FILE_ERROR_NO_CONNECTION: |
415 // Re-queue the task so that we'll retry once the connection is back. | 415 // Re-queue the task so that we'll retry once the connection is back. |
416 queue_.push_front(sync_task); | 416 queue_.push_front(sync_task); |
417 break; | 417 break; |
418 default: | 418 default: |
419 LOG(WARNING) << "Failed to fetch " << sync_task.resource_id | 419 LOG(WARNING) << "Failed to fetch " << sync_task.resource_id |
420 << ": " << error; | 420 << ": " << error; |
421 } | 421 } |
422 } | 422 } |
423 | 423 |
424 // Continue the loop. | 424 // Continue the loop. |
425 DoSyncLoop(); | 425 DoSyncLoop(); |
426 } | 426 } |
427 | 427 |
428 void GDataSyncClient::OnUploadFileComplete(const std::string& resource_id, | 428 void GDataSyncClient::OnUploadFileComplete(const std::string& resource_id, |
429 GDataFileError error) { | 429 DriveFileError error) { |
430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
431 | 431 |
432 if (error == GDATA_FILE_OK) { | 432 if (error == DRIVE_FILE_OK) { |
433 DVLOG(1) << "Uploaded " << resource_id; | 433 DVLOG(1) << "Uploaded " << resource_id; |
434 } else { | 434 } else { |
435 // TODO(satorux): We should re-queue if the error is recoverable. | 435 // TODO(satorux): We should re-queue if the error is recoverable. |
436 LOG(WARNING) << "Failed to upload " << resource_id << ": " << error; | 436 LOG(WARNING) << "Failed to upload " << resource_id << ": " << error; |
437 } | 437 } |
438 | 438 |
439 // Continue the loop. | 439 // Continue the loop. |
440 DoSyncLoop(); | 440 DoSyncLoop(); |
441 } | 441 } |
442 | 442 |
(...skipping 14 matching lines...) Expand all Loading... |
457 const content::NotificationDetails& details) { | 457 const content::NotificationDetails& details) { |
458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
459 | 459 |
460 // Resume the sync loop if gdata preferences are changed. Note that we | 460 // Resume the sync loop if gdata preferences are changed. Note that we |
461 // don't need to check the new values here as these will be checked in | 461 // don't need to check the new values here as these will be checked in |
462 // ShouldStopSyncLoop() as soon as the loop is resumed. | 462 // ShouldStopSyncLoop() as soon as the loop is resumed. |
463 StartSyncLoop(); | 463 StartSyncLoop(); |
464 } | 464 } |
465 | 465 |
466 } // namespace gdata | 466 } // namespace gdata |
OLD | NEW |