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 <errno.h> | 7 #include <errno.h> |
8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
(...skipping 2533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2544 return; | 2544 return; |
2545 } | 2545 } |
2546 | 2546 |
2547 scoped_ptr<GDataDirectoryProto> directory_proto(new GDataDirectoryProto); | 2547 scoped_ptr<GDataDirectoryProto> directory_proto(new GDataDirectoryProto); |
2548 directory->ToProto(directory_proto.get()); | 2548 directory->ToProto(directory_proto.get()); |
2549 | 2549 |
2550 if (!callback.is_null()) | 2550 if (!callback.is_null()) |
2551 callback.Run(base::PLATFORM_FILE_OK, directory_proto.Pass()); | 2551 callback.Run(base::PLATFORM_FILE_OK, directory_proto.Pass()); |
2552 } | 2552 } |
2553 | 2553 |
| 2554 void GDataFileSystem::RequestDirectoryRefresh( |
| 2555 const FilePath& file_path) { |
| 2556 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 2557 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2558 const bool posted = BrowserThread::PostTask( |
| 2559 BrowserThread::UI, |
| 2560 FROM_HERE, |
| 2561 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, |
| 2562 ui_weak_ptr_, |
| 2563 file_path)); |
| 2564 DCHECK(posted); |
| 2565 return; |
| 2566 } |
| 2567 |
| 2568 RequestDirectoryRefreshOnUIThread(file_path); |
| 2569 } |
| 2570 |
| 2571 void GDataFileSystem::RequestDirectoryRefreshOnUIThread( |
| 2572 const FilePath& file_path) { |
| 2573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2574 |
| 2575 base::AutoLock lock(lock_); // To use GetGDataEntryByPath() and root_. |
| 2576 GDataEntry* entry = GetGDataEntryByPath(file_path); |
| 2577 if (!entry || !entry->AsGDataDirectory()) { |
| 2578 LOG(ERROR) << "Directory entry not found: " << file_path.value(); |
| 2579 return; |
| 2580 } |
| 2581 |
| 2582 if (entry->resource_id().empty()) { |
| 2583 // This can happen if the directory is a virtual directory for search. |
| 2584 LOG(ERROR) << "Resource ID not found: " << file_path.value(); |
| 2585 return; |
| 2586 } |
| 2587 |
| 2588 LoadFeedFromServer(root_->origin(), |
| 2589 0, // Not delta feed. |
| 2590 0, // Not used. |
| 2591 true, // multiple feeds |
| 2592 file_path, |
| 2593 std::string(), // No search query |
| 2594 entry->resource_id(), |
| 2595 FindEntryCallback(), // Not used. |
| 2596 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, |
| 2597 ui_weak_ptr_)); |
| 2598 } |
| 2599 |
| 2600 void GDataFileSystem::OnRequestDirectoryRefresh( |
| 2601 GetDocumentsParams* params, |
| 2602 base::PlatformFileError error) { |
| 2603 DCHECK(params); |
| 2604 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2605 |
| 2606 const FilePath& directory_path = params->search_file_path; |
| 2607 if (error != base::PLATFORM_FILE_OK) { |
| 2608 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value() |
| 2609 << ": " << error; |
| 2610 return; |
| 2611 } |
| 2612 |
| 2613 base::AutoLock lock(lock_); // To use FeedToFileResourceMap() and root_. |
| 2614 |
| 2615 int unused_delta_feed_changestamp = 0; |
| 2616 int unused_num_regular_files = 0; |
| 2617 int unused_num_hosted_documents = 0; |
| 2618 FileResourceIdMap file_map; |
| 2619 error = FeedToFileResourceMap(*params->feed_list, |
| 2620 &file_map, |
| 2621 &unused_delta_feed_changestamp, |
| 2622 &unused_num_regular_files, |
| 2623 &unused_num_hosted_documents); |
| 2624 if (error != base::PLATFORM_FILE_OK) { |
| 2625 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() |
| 2626 << ": " << error; |
| 2627 return; |
| 2628 } |
| 2629 |
| 2630 GDataEntry* directory_entry = root_->GetEntryByResourceId( |
| 2631 params->directory_resource_id); |
| 2632 if (!directory_entry || !directory_entry->AsGDataDirectory()) { |
| 2633 LOG(ERROR) << "Directory entry is gone: " << directory_path.value() |
| 2634 << ": " << params->directory_resource_id; |
| 2635 return; |
| 2636 } |
| 2637 GDataDirectory* directory = directory_entry->AsGDataDirectory(); |
| 2638 |
| 2639 // Remove the existing files. |
| 2640 directory->RemoveChildFiles(); |
| 2641 // Go through all entires generated by the feed and add files. |
| 2642 for (FileResourceIdMap::const_iterator it = file_map.begin(); |
| 2643 it != file_map.end(); ++it) { |
| 2644 scoped_ptr<GDataEntry> entry(it->second); |
| 2645 // Skip if it's not a file (i.e. directory). |
| 2646 if (!entry->AsGDataFile()) |
| 2647 continue; |
| 2648 directory->AddEntry(entry.release()); |
| 2649 } |
| 2650 |
| 2651 // Note that there may be no change in the directory, but it's expensive to |
| 2652 // check if the new metadata matches the existing one, so we just always |
| 2653 // notify that the directory is changed. |
| 2654 NotifyDirectoryChanged(directory_path); |
| 2655 DVLOG(1) << "Directory refreshed: " << directory_path.value(); |
| 2656 } |
| 2657 |
2554 bool GDataFileSystem::GetFileInfoByPath( | 2658 bool GDataFileSystem::GetFileInfoByPath( |
2555 const FilePath& file_path, GDataFileProperties* properties) { | 2659 const FilePath& file_path, GDataFileProperties* properties) { |
2556 DCHECK(properties); | 2660 DCHECK(properties); |
2557 base::AutoLock lock(lock_); | 2661 base::AutoLock lock(lock_); |
2558 GDataEntry* entry = GetGDataEntryByPath(file_path); | 2662 GDataEntry* entry = GetGDataEntryByPath(file_path); |
2559 if (!entry) | 2663 if (!entry) |
2560 return false; | 2664 return false; |
2561 | 2665 |
2562 properties->file_info = entry->file_info(); | 2666 properties->file_info = entry->file_info(); |
2563 properties->resource_id = entry->resource_id(); | 2667 properties->resource_id = entry->resource_id(); |
(...skipping 2585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5149 pref_registrar_->Init(profile_->GetPrefs()); | 5253 pref_registrar_->Init(profile_->GetPrefs()); |
5150 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 5254 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
5151 } | 5255 } |
5152 | 5256 |
5153 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 5257 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
5154 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 5258 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
5155 global_free_disk_getter_for_testing = getter; | 5259 global_free_disk_getter_for_testing = getter; |
5156 } | 5260 } |
5157 | 5261 |
5158 } // namespace gdata | 5262 } // namespace gdata |
OLD | NEW |