Chromium Code Reviews| 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_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 1990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2001 scoped_ptr<GDataEntry> entry(it->second); | 2001 scoped_ptr<GDataEntry> entry(it->second); |
| 2002 // Skip if it's not a file (i.e. directory). | 2002 // Skip if it's not a file (i.e. directory). |
| 2003 if (!entry->AsGDataFile()) | 2003 if (!entry->AsGDataFile()) |
| 2004 continue; | 2004 continue; |
| 2005 directory->AddEntry(entry.release()); | 2005 directory->AddEntry(entry.release()); |
| 2006 } | 2006 } |
| 2007 | 2007 |
| 2008 // Note that there may be no change in the directory, but it's expensive to | 2008 // Note that there may be no change in the directory, but it's expensive to |
| 2009 // check if the new metadata matches the existing one, so we just always | 2009 // check if the new metadata matches the existing one, so we just always |
| 2010 // notify that the directory is changed. | 2010 // notify that the directory is changed. |
| 2011 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, | 2011 OnDirectoryChanged(directory_path); |
| 2012 observers_, OnDirectoryChanged(directory_path)); | |
| 2013 DVLOG(1) << "Directory refreshed: " << directory_path.value(); | 2012 DVLOG(1) << "Directory refreshed: " << directory_path.value(); |
| 2014 } | 2013 } |
| 2015 | 2014 |
| 2016 void GDataFileSystem::UpdateFileByResourceId( | 2015 void GDataFileSystem::UpdateFileByResourceId( |
| 2017 const std::string& resource_id, | 2016 const std::string& resource_id, |
| 2018 const FileOperationCallback& callback) { | 2017 const FileOperationCallback& callback) { |
| 2019 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2018 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 2020 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2019 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2021 RunTaskOnUIThread( | 2020 RunTaskOnUIThread( |
| 2022 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, | 2021 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2407 } | 2406 } |
| 2408 | 2407 |
| 2409 void GDataFileSystem::OnRenameResourceCompleted( | 2408 void GDataFileSystem::OnRenameResourceCompleted( |
| 2410 const FilePath& file_path, | 2409 const FilePath& file_path, |
| 2411 const FilePath::StringType& new_name, | 2410 const FilePath::StringType& new_name, |
| 2412 const FilePathUpdateCallback& callback, | 2411 const FilePathUpdateCallback& callback, |
| 2413 GDataErrorCode status, | 2412 GDataErrorCode status, |
| 2414 const GURL& document_url) { | 2413 const GURL& document_url) { |
| 2415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2416 | 2415 |
| 2417 FilePath updated_file_path; | 2416 if (util::GDataToGDataFileError(status) == GDATA_FILE_OK) |
|
satorux1
2012/08/08 16:04:10
Previously, |callback| was called if != GDATA_FILE
achuithb
2012/08/08 22:08:41
Thank you for catching this. I made this error in
| |
| 2418 GDataFileError error = util::GDataToGDataFileError(status); | 2417 RenameFileOnFilesystem(file_path, new_name, callback); |
| 2419 if (error == GDATA_FILE_OK) | |
| 2420 error = RenameFileOnFilesystem(file_path, new_name, &updated_file_path); | |
| 2421 | |
| 2422 if (!callback.is_null()) | |
| 2423 callback.Run(error, updated_file_path); | |
| 2424 } | 2418 } |
| 2425 | 2419 |
| 2426 void GDataFileSystem::OnCopyDocumentCompleted( | 2420 void GDataFileSystem::OnCopyDocumentCompleted( |
| 2427 const FilePath& dir_path, | 2421 const FilePath& dir_path, |
| 2428 const FileOperationCallback& callback, | 2422 const FileOperationCallback& callback, |
| 2429 GDataErrorCode status, | 2423 GDataErrorCode status, |
| 2430 scoped_ptr<base::Value> data) { | 2424 scoped_ptr<base::Value> data) { |
| 2431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2432 | 2426 |
| 2433 GDataFileError error = util::GDataToGDataFileError(status); | 2427 GDataFileError error = util::GDataToGDataFileError(status); |
| 2434 if (error != GDATA_FILE_OK) { | 2428 if (error != GDATA_FILE_OK) { |
| 2435 if (!callback.is_null()) | 2429 if (!callback.is_null()) |
| 2436 callback.Run(error); | 2430 callback.Run(error); |
| 2437 | 2431 |
| 2438 return; | 2432 return; |
| 2439 } | 2433 } |
| 2440 | 2434 |
| 2441 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); | 2435 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); |
| 2442 if (!doc_entry.get()) { | 2436 if (!doc_entry.get()) { |
| 2443 if (!callback.is_null()) | 2437 if (!callback.is_null()) |
| 2444 callback.Run(GDATA_FILE_ERROR_FAILED); | 2438 callback.Run(GDATA_FILE_ERROR_FAILED); |
| 2445 | 2439 |
| 2446 return; | 2440 return; |
| 2447 } | 2441 } |
| 2448 | 2442 |
| 2449 GDataEntry* entry = GDataEntry::FromDocumentEntry( | 2443 GDataEntry* entry = GDataEntry::FromDocumentEntry( |
| 2450 directory_service_->root(), doc_entry.get(), directory_service_.get()); | 2444 NULL, doc_entry.get(), directory_service_.get()); |
| 2451 if (!entry) { | 2445 if (!entry) { |
| 2452 if (!callback.is_null()) | 2446 if (!callback.is_null()) |
| 2453 callback.Run(GDATA_FILE_ERROR_FAILED); | 2447 callback.Run(GDATA_FILE_ERROR_FAILED); |
| 2454 | 2448 |
| 2455 return; | 2449 return; |
| 2456 } | 2450 } |
| 2457 | 2451 |
| 2458 // |entry| was added in the root directory on the server, so we should | 2452 // |entry| was added in the root directory on the server, so we should |
| 2459 // first add it to |root_| to mirror the state and then move it to the | 2453 // first add it to |root_| to mirror the state and then move it to the |
| 2460 // destination directory by AddEntryToDirectory(). | 2454 // destination directory by AddEntryToDirectory(). |
| 2461 directory_service_->root()->AddEntry(entry); | 2455 directory_service_->root()->AddEntry(entry); |
| 2462 AddEntryToDirectory(dir_path, callback, GDATA_FILE_OK, entry->GetFilePath()); | 2456 AddEntryToDirectory(dir_path, callback, GDATA_FILE_OK, entry->GetFilePath()); |
| 2463 } | 2457 } |
| 2464 | 2458 |
| 2465 void GDataFileSystem::OnAddEntryToDirectoryCompleted( | 2459 void GDataFileSystem::OnAddEntryToDirectoryCompleted( |
| 2466 const FileOperationCallback& callback, | 2460 const FileOperationCallback& callback, |
| 2467 const FilePath& file_path, | 2461 const FilePath& file_path, |
| 2468 const FilePath& dir_path, | 2462 const FilePath& dir_path, |
| 2469 GDataErrorCode status, | 2463 GDataErrorCode status, |
| 2470 const GURL& document_url) { | 2464 const GURL& document_url) { |
| 2471 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2465 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2472 | 2466 |
| 2473 GDataFileError error = util::GDataToGDataFileError(status); | 2467 GDataFileError error = util::GDataToGDataFileError(status); |
| 2474 if (error == GDATA_FILE_OK) { | 2468 if (error == GDATA_FILE_OK) { |
| 2475 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); | 2469 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
| 2476 if (entry) { | 2470 if (entry) { |
| 2477 DCHECK_EQ(directory_service_->root(), entry->parent()); | 2471 DCHECK_EQ(directory_service_->root(), entry->parent()); |
| 2478 error = AddEntryToDirectoryOnFilesystem(entry, dir_path); | 2472 directory_service_->AddEntryToDirectory(dir_path, entry, |
| 2473 base::Bind(&GDataFileSystem::OnAddEntryToDirectory2, ui_weak_ptr_, | |
| 2474 callback)); | |
| 2475 return; | |
| 2479 } else { | 2476 } else { |
| 2480 error = GDATA_FILE_ERROR_NOT_FOUND; | 2477 error = GDATA_FILE_ERROR_NOT_FOUND; |
| 2481 } | 2478 } |
| 2482 } | 2479 } |
| 2483 | 2480 |
| 2484 if (!callback.is_null()) | 2481 if (!callback.is_null()) |
| 2485 callback.Run(error); | 2482 callback.Run(error); |
| 2486 } | 2483 } |
| 2487 | 2484 |
| 2488 void GDataFileSystem::OnRemoveEntryFromDirectoryCompleted( | 2485 void GDataFileSystem::OnRemoveEntryFromDirectoryCompleted( |
| 2489 const FilePathUpdateCallback& callback, | 2486 const FilePathUpdateCallback& callback, |
| 2490 const FilePath& file_path, | 2487 const FilePath& file_path, |
| 2491 const FilePath& dir_path, | 2488 const FilePath& dir_path, |
| 2492 GDataErrorCode status, | 2489 GDataErrorCode status, |
| 2493 const GURL& document_url) { | 2490 const GURL& document_url) { |
| 2494 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2491 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2495 | 2492 |
| 2496 FilePath updated_file_path = file_path; | 2493 if (util::GDataToGDataFileError(status) == GDATA_FILE_OK) |
| 2497 GDataFileError error = util::GDataToGDataFileError(status); | 2494 RemoveEntryFromDirectoryOnFilesystem(file_path, callback); |
| 2498 if (error == GDATA_FILE_OK) | |
| 2499 error = RemoveEntryFromDirectoryOnFilesystem(file_path, dir_path, | |
| 2500 &updated_file_path); | |
| 2501 | |
| 2502 if (!callback.is_null()) | |
| 2503 callback.Run(error, updated_file_path); | |
| 2504 } | 2495 } |
| 2505 | 2496 |
| 2506 void GDataFileSystem::OnRemovedDocument( | 2497 void GDataFileSystem::OnRemovedDocument( |
| 2507 const FileOperationCallback& callback, | 2498 const FileOperationCallback& callback, |
| 2508 const FilePath& file_path, | 2499 const FilePath& file_path, |
| 2509 GDataErrorCode status, | 2500 GDataErrorCode status, |
| 2510 const GURL& document_url) { | 2501 const GURL& document_url) { |
| 2511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2512 | 2503 |
| 2513 GDataFileError error = util::GDataToGDataFileError(status); | 2504 GDataFileError error = util::GDataToGDataFileError(status); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2619 } | 2610 } |
| 2620 } | 2611 } |
| 2621 | 2612 |
| 2622 void GDataFileSystem::OnDownloadStoredToCache(GDataFileError error, | 2613 void GDataFileSystem::OnDownloadStoredToCache(GDataFileError error, |
| 2623 const std::string& resource_id, | 2614 const std::string& resource_id, |
| 2624 const std::string& md5) { | 2615 const std::string& md5) { |
| 2625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2616 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2626 // Nothing much to do here for now. | 2617 // Nothing much to do here for now. |
| 2627 } | 2618 } |
| 2628 | 2619 |
| 2629 GDataFileError GDataFileSystem::RenameFileOnFilesystem( | 2620 void GDataFileSystem::RenameFileOnFilesystem( |
|
satorux1
2012/08/08 16:04:10
Filesystem -> FileSystem. could you rename while y
achuithb
2012/08/08 22:08:41
Done.
| |
| 2630 const FilePath& file_path, | 2621 const FilePath& file_path, |
| 2631 const FilePath::StringType& new_name, | 2622 const FilePath::StringType& new_name, |
| 2632 FilePath* updated_file_path) { | 2623 const FilePathUpdateCallback& callback) { |
| 2633 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2624 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2634 DCHECK(updated_file_path); | |
| 2635 | 2625 |
| 2636 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); | 2626 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
| 2637 if (!entry) | 2627 if (!entry) { |
| 2638 return GDATA_FILE_ERROR_NOT_FOUND; | 2628 if (!callback.is_null()) |
| 2629 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); | |
| 2630 return; | |
| 2631 } | |
| 2639 | 2632 |
| 2640 DCHECK(entry->parent()); | 2633 DCHECK(entry->parent()); |
| 2641 entry->set_title(new_name); | 2634 entry->set_title(new_name); |
| 2642 // After changing the title of the entry, call TakeFile() to remove the | 2635 // After changing the title of the entry, call AddEntryToDirectory() to remove |
| 2643 // entry from its parent directory and then add it back in order to go | 2636 // the entry from its parent directory and then add it back in order to go |
| 2644 // through the file name de-duplication. | 2637 // through the file name de-duplication. |
| 2645 // TODO(achuith/satorux/zel): This code is fragile. The title has been | 2638 // TODO(achuith/satorux/zel): This code is fragile. The title has been |
| 2646 // changed, but not the file_name. TakeEntry removes the child based on the | 2639 // changed, but not the file_name. AddEntryToDirectory calls RemoveChild to |
| 2647 // old file_name, and then re-adds the child by first assigning the new title | 2640 // remove the child based on the old file_name, and then re-adds the child by |
| 2648 // to file_name. http://crbug.com/30157 | 2641 // first assigning the new title to file_name. http://crbug.com/30157 |
| 2649 if (!entry->parent()->TakeEntry(entry)) | 2642 directory_service_->AddEntryToDirectory(entry->parent()->GetFilePath(), entry, |
| 2650 return GDATA_FILE_ERROR_FAILED; | 2643 base::Bind(&GDataFileSystem::OnAddEntryToDirectory, |
| 2651 | 2644 ui_weak_ptr_, |
| 2652 *updated_file_path = entry->GetFilePath(); | 2645 callback)); |
| 2653 | |
| 2654 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | |
| 2655 OnDirectoryChanged(updated_file_path->DirName())); | |
| 2656 return GDATA_FILE_OK; | |
| 2657 } | 2646 } |
| 2658 | 2647 |
| 2659 GDataFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( | 2648 void GDataFileSystem::RemoveEntryFromDirectoryOnFilesystem( |
| 2660 GDataEntry* entry, const FilePath& dir_path) { | 2649 const FilePath& file_path, |
| 2650 const FilePathUpdateCallback& callback) { | |
| 2661 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2662 DCHECK(entry); | |
| 2663 | 2652 |
| 2664 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path); | 2653 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
| 2665 if (!dir_entry) | 2654 if (!entry) { |
| 2666 return GDATA_FILE_ERROR_NOT_FOUND; | 2655 if (!callback.is_null()) |
| 2656 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); | |
| 2657 return; | |
| 2658 } | |
| 2667 | 2659 |
| 2668 GDataDirectory* dir = dir_entry->AsGDataDirectory(); | 2660 directory_service_->AddEntryToDirectory( |
| 2669 if (!dir) | 2661 directory_service_->root()->GetFilePath(), entry, |
| 2670 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 2662 base::Bind(&GDataFileSystem::OnAddEntryToDirectory, |
| 2671 | 2663 ui_weak_ptr_, callback)); |
| 2672 if (!dir->TakeEntry(entry)) | |
| 2673 return GDATA_FILE_ERROR_FAILED; | |
| 2674 | |
| 2675 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | |
| 2676 OnDirectoryChanged(dir_path)); | |
| 2677 return GDATA_FILE_OK; | |
| 2678 } | 2664 } |
| 2679 | 2665 |
| 2680 GDataFileError GDataFileSystem::RemoveEntryFromDirectoryOnFilesystem( | 2666 void GDataFileSystem::OnAddEntryToDirectory( |
| 2681 const FilePath& file_path, const FilePath& dir_path, | 2667 const FilePathUpdateCallback& callback, |
| 2682 FilePath* updated_file_path) { | 2668 GDataFileError error, |
| 2683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2669 const FilePath& updated_file_path) { |
| 2684 DCHECK(updated_file_path); | 2670 if (error == GDATA_FILE_OK) |
| 2671 OnDirectoryChanged(updated_file_path.DirName()); | |
| 2685 | 2672 |
| 2686 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); | 2673 if (!callback.is_null()) |
| 2687 if (!entry) | 2674 callback.Run(error, updated_file_path); |
| 2688 return GDATA_FILE_ERROR_NOT_FOUND; | 2675 } |
| 2689 | 2676 |
| 2690 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path); | 2677 void GDataFileSystem::OnAddEntryToDirectory2( |
| 2691 if (!dir) | 2678 const FileOperationCallback& callback, |
| 2692 return GDATA_FILE_ERROR_NOT_FOUND; | 2679 GDataFileError error, |
| 2680 const FilePath& updated_file_path) { | |
| 2681 if (error == GDATA_FILE_OK) | |
| 2682 OnDirectoryChanged(updated_file_path.DirName()); | |
| 2693 | 2683 |
| 2694 if (!dir->AsGDataDirectory()) | 2684 if (!callback.is_null()) |
| 2695 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 2685 callback.Run(error); |
| 2696 | |
| 2697 DCHECK_EQ(dir->AsGDataDirectory(), entry->parent()); | |
| 2698 | |
| 2699 if (!directory_service_->root()->TakeEntry(entry)) | |
| 2700 return GDATA_FILE_ERROR_FAILED; | |
| 2701 | |
| 2702 *updated_file_path = entry->GetFilePath(); | |
| 2703 | |
| 2704 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | |
| 2705 OnDirectoryChanged(updated_file_path->DirName())); | |
| 2706 return GDATA_FILE_OK; | |
| 2707 } | 2686 } |
| 2708 | 2687 |
| 2709 GDataFileError GDataFileSystem::RemoveEntryFromFileSystem( | 2688 GDataFileError GDataFileSystem::RemoveEntryFromFileSystem( |
| 2710 const FilePath& file_path) { | 2689 const FilePath& file_path) { |
| 2711 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2690 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2712 | 2691 |
| 2713 std::string resource_id; | 2692 std::string resource_id; |
| 2714 GDataFileError error = RemoveEntryFromGData(file_path, &resource_id); | 2693 GDataFileError error = RemoveEntryFromGData(file_path, &resource_id); |
| 2715 if (error != GDATA_FILE_OK) | 2694 if (error != GDATA_FILE_OK) |
| 2716 return error; | 2695 return error; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2787 return GDATA_FILE_ERROR_FAILED; | 2766 return GDATA_FILE_ERROR_FAILED; |
| 2788 | 2767 |
| 2789 // Check if parent is a directory since in theory since this is a callback | 2768 // Check if parent is a directory since in theory since this is a callback |
| 2790 // something could in the meantime have nuked the parent dir and created a | 2769 // something could in the meantime have nuked the parent dir and created a |
| 2791 // file with the exact same name. | 2770 // file with the exact same name. |
| 2792 GDataDirectory* parent_dir = entry->AsGDataDirectory(); | 2771 GDataDirectory* parent_dir = entry->AsGDataDirectory(); |
| 2793 if (!parent_dir) | 2772 if (!parent_dir) |
| 2794 return GDATA_FILE_ERROR_FAILED; | 2773 return GDATA_FILE_ERROR_FAILED; |
| 2795 | 2774 |
| 2796 GDataEntry* new_entry = GDataEntry::FromDocumentEntry( | 2775 GDataEntry* new_entry = GDataEntry::FromDocumentEntry( |
| 2797 parent_dir, doc_entry.get(), directory_service_.get()); | 2776 NULL, doc_entry.get(), directory_service_.get()); |
| 2798 if (!new_entry) | 2777 if (!new_entry) |
| 2799 return GDATA_FILE_ERROR_FAILED; | 2778 return GDATA_FILE_ERROR_FAILED; |
| 2800 | 2779 |
| 2801 parent_dir->AddEntry(new_entry); | 2780 parent_dir->AddEntry(new_entry); |
| 2802 | 2781 |
| 2803 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2782 OnDirectoryChanged(directory_path); |
| 2804 OnDirectoryChanged(directory_path)); | |
| 2805 return GDATA_FILE_OK; | 2783 return GDATA_FILE_OK; |
| 2806 } | 2784 } |
| 2807 | 2785 |
| 2808 GDataFileSystem::FindMissingDirectoryResult | 2786 GDataFileSystem::FindMissingDirectoryResult |
| 2809 GDataFileSystem::FindFirstMissingParentDirectory( | 2787 GDataFileSystem::FindFirstMissingParentDirectory( |
| 2810 const FilePath& directory_path, | 2788 const FilePath& directory_path, |
| 2811 GURL* last_dir_content_url, | 2789 GURL* last_dir_content_url, |
| 2812 FilePath* first_missing_parent_path) { | 2790 FilePath* first_missing_parent_path) { |
| 2813 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2791 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2814 | 2792 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2855 return GDATA_FILE_ERROR_ACCESS_DENIED; | 2833 return GDATA_FILE_ERROR_ACCESS_DENIED; |
| 2856 | 2834 |
| 2857 // If it's a file (only files have resource id), get its resource id so that | 2835 // If it's a file (only files have resource id), get its resource id so that |
| 2858 // we can remove it after releasing the auto lock. | 2836 // we can remove it after releasing the auto lock. |
| 2859 if (entry->AsGDataFile()) | 2837 if (entry->AsGDataFile()) |
| 2860 *resource_id = entry->AsGDataFile()->resource_id(); | 2838 *resource_id = entry->AsGDataFile()->resource_id(); |
| 2861 | 2839 |
| 2862 GDataDirectory* parent_dir = entry->parent(); | 2840 GDataDirectory* parent_dir = entry->parent(); |
| 2863 parent_dir->RemoveEntry(entry); | 2841 parent_dir->RemoveEntry(entry); |
| 2864 | 2842 |
| 2865 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2843 OnDirectoryChanged(parent_dir->GetFilePath()); |
| 2866 OnDirectoryChanged(parent_dir->GetFilePath())); | |
| 2867 return GDATA_FILE_OK; | 2844 return GDATA_FILE_OK; |
| 2868 } | 2845 } |
| 2869 | 2846 |
| 2870 void GDataFileSystem::AddUploadedFile( | 2847 void GDataFileSystem::AddUploadedFile( |
| 2871 UploadMode upload_mode, | 2848 UploadMode upload_mode, |
| 2872 const FilePath& virtual_dir_path, | 2849 const FilePath& virtual_dir_path, |
| 2873 scoped_ptr<DocumentEntry> entry, | 2850 scoped_ptr<DocumentEntry> entry, |
| 2874 const FilePath& file_content_path, | 2851 const FilePath& file_content_path, |
| 2875 GDataCache::FileOperationType cache_operation, | 2852 GDataCache::FileOperationType cache_operation, |
| 2876 const base::Closure& callback) { | 2853 const base::Closure& callback) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2912 virtual_dir_path); | 2889 virtual_dir_path); |
| 2913 if (!dir_entry) | 2890 if (!dir_entry) |
| 2914 return; | 2891 return; |
| 2915 | 2892 |
| 2916 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); | 2893 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); |
| 2917 if (!parent_dir) | 2894 if (!parent_dir) |
| 2918 return; | 2895 return; |
| 2919 | 2896 |
| 2920 scoped_ptr<GDataEntry> new_entry( | 2897 scoped_ptr<GDataEntry> new_entry( |
| 2921 GDataEntry::FromDocumentEntry( | 2898 GDataEntry::FromDocumentEntry( |
| 2922 parent_dir, entry.get(), directory_service_.get())); | 2899 NULL, entry.get(), directory_service_.get())); |
| 2923 if (!new_entry.get()) | 2900 if (!new_entry.get()) |
| 2924 return; | 2901 return; |
| 2925 | 2902 |
| 2926 if (upload_mode == UPLOAD_EXISTING_FILE) { | 2903 if (upload_mode == UPLOAD_EXISTING_FILE) { |
| 2927 // Remove an existing entry, which should be present. | 2904 // Remove an existing entry, which should be present. |
| 2928 const std::string& resource_id = new_entry->resource_id(); | 2905 const std::string& resource_id = new_entry->resource_id(); |
| 2929 directory_service_->GetEntryByResourceIdAsync(resource_id, | 2906 directory_service_->GetEntryByResourceIdAsync(resource_id, |
| 2930 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); | 2907 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); |
| 2931 } | 2908 } |
| 2932 | 2909 |
| 2933 GDataFile* file = new_entry->AsGDataFile(); | 2910 GDataFile* file = new_entry->AsGDataFile(); |
| 2934 DCHECK(file); | 2911 DCHECK(file); |
| 2935 const std::string& resource_id = file->resource_id(); | 2912 const std::string& resource_id = file->resource_id(); |
| 2936 const std::string& md5 = file->file_md5(); | 2913 const std::string& md5 = file->file_md5(); |
| 2937 parent_dir->AddEntry(new_entry.release()); | 2914 parent_dir->AddEntry(new_entry.release()); |
| 2938 | 2915 |
| 2939 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2916 OnDirectoryChanged(virtual_dir_path); |
| 2940 OnDirectoryChanged(virtual_dir_path)); | |
| 2941 | 2917 |
| 2942 if (upload_mode == UPLOAD_NEW_FILE) { | 2918 if (upload_mode == UPLOAD_NEW_FILE) { |
| 2943 // Add the file to the cache if we have uploaded a new file. | 2919 // Add the file to the cache if we have uploaded a new file. |
| 2944 cache_->StoreOnUIThread(resource_id, | 2920 cache_->StoreOnUIThread(resource_id, |
| 2945 md5, | 2921 md5, |
| 2946 file_content_path, | 2922 file_content_path, |
| 2947 cache_operation, | 2923 cache_operation, |
| 2948 base::Bind(&OnCacheUpdatedForAddUploadedFile, | 2924 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
| 2949 callback_runner.Release())); | 2925 callback_runner.Release())); |
| 2950 } else if (upload_mode == UPLOAD_EXISTING_FILE) { | 2926 } else if (upload_mode == UPLOAD_EXISTING_FILE) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2961 void GDataFileSystem::Observe(int type, | 2937 void GDataFileSystem::Observe(int type, |
| 2962 const content::NotificationSource& source, | 2938 const content::NotificationSource& source, |
| 2963 const content::NotificationDetails& details) { | 2939 const content::NotificationDetails& details) { |
| 2964 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2940 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2965 | 2941 |
| 2966 if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 2942 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 2967 std::string* pref_name = content::Details<std::string>(details).ptr(); | 2943 std::string* pref_name = content::Details<std::string>(details).ptr(); |
| 2968 if (*pref_name == prefs::kDisableGDataHostedFiles) { | 2944 if (*pref_name == prefs::kDisableGDataHostedFiles) { |
| 2969 const FilePath root_path = directory_service_->root()->GetFilePath(); | 2945 const FilePath root_path = directory_service_->root()->GetFilePath(); |
| 2970 // Kick off directory refresh when this setting changes. | 2946 // Kick off directory refresh when this setting changes. |
| 2971 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2947 OnDirectoryChanged(root_path); |
| 2972 OnDirectoryChanged(root_path)); | |
| 2973 } | 2948 } |
| 2974 } else { | 2949 } else { |
| 2975 NOTREACHED(); | 2950 NOTREACHED(); |
| 2976 } | 2951 } |
| 2977 } | 2952 } |
| 2978 | 2953 |
| 2979 //============= GDataFileSystem: internal helper functions ===================== | 2954 //============= GDataFileSystem: internal helper functions ===================== |
| 2980 | 2955 |
| 2981 void GDataFileSystem::InitializePreferenceObserver() { | 2956 void GDataFileSystem::InitializePreferenceObserver() { |
| 2982 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2957 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3405 } | 3380 } |
| 3406 | 3381 |
| 3407 PlatformFileInfoProto entry_file_info; | 3382 PlatformFileInfoProto entry_file_info; |
| 3408 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3383 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 3409 *entry_proto->mutable_file_info() = entry_file_info; | 3384 *entry_proto->mutable_file_info() = entry_file_info; |
| 3410 if (!callback.is_null()) | 3385 if (!callback.is_null()) |
| 3411 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3386 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
| 3412 } | 3387 } |
| 3413 | 3388 |
| 3414 } // namespace gdata | 3389 } // namespace gdata |
| OLD | NEW |