Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10386226: gdata: Add requestDirectoryRefresh to file_browser_private. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 GDataEntry* entry = GetGDataEntryByPath(file_path);
2576 if (!entry) {
tbarzic 2012/05/18 22:51:12 we may want to check that entry is really a direct
satorux1 2012/05/18 23:42:19 Done.
2577 LOG(ERROR) << "Directory entry not found: " << file_path.value();
2578 return;
2579 }
2580
2581 base::AutoLock lock(lock_); // To access root_.
2582 LoadFeedFromServer(root_->origin(),
2583 0, // Not delta feed.
2584 0, // Not used.
2585 true, // multiple feeds
2586 file_path,
2587 std::string(), // No search query
2588 entry->resource_id(),
2589 FindEntryCallback(), // Not used.
2590 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh,
2591 ui_weak_ptr_));
2592 }
2593
2594 void GDataFileSystem::OnRequestDirectoryRefresh(
2595 GetDocumentsParams* params,
2596 base::PlatformFileError error) {
2597 DCHECK(params);
2598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2599
2600 const FilePath& directory_path = params->search_file_path;
2601 if (error != base::PLATFORM_FILE_OK) {
2602 LOG(ERROR) << "Failed to refresh directory: " << directory_path.value()
2603 << ": " << error;
2604 return;
2605 }
2606
2607 int unused_delta_feed_changestamp = 0;
2608 int unused_num_regular_files = 0;
2609 int unused_num_hosted_documents = 0;
2610 FileResourceIdMap file_map;
2611 error = FeedToFileResourceMap(*params->feed_list,
2612 &file_map,
2613 &unused_delta_feed_changestamp,
2614 &unused_num_regular_files,
2615 &unused_num_hosted_documents);
2616 if (error != base::PLATFORM_FILE_OK) {
2617 LOG(ERROR) << "Failed to convert feed: " << directory_path.value()
2618 << ": " << error;
2619 return;
2620 }
2621
2622 base::AutoLock lock(lock_); // To access root_.
2623
2624 GDataEntry* directory_entry = root_->GetEntryByResourceId(
2625 params->directory_resource_id);
2626 if (!directory_entry || !directory_entry->AsGDataDirectory()) {
2627 LOG(ERROR) << "Directory entry is gone: " << directory_path.value()
2628 << ": " << params->directory_resource_id;
2629 return;
2630 }
2631 GDataDirectory* directory = directory_entry->AsGDataDirectory();
2632
2633 // Remove the existing files.
2634 directory->RemoveChildFiles();
2635 // Go through all entires generated by the feed and add files.
2636 for (FileResourceIdMap::const_iterator it = file_map.begin();
2637 it != file_map.end(); ++it) {
2638 scoped_ptr<GDataEntry> entry(it->second);
2639 // Skip if it's not a file (i.e. directory).
2640 if (!entry->AsGDataFile())
2641 continue;
2642 directory->AddEntry(entry.release());
2643 }
2644
2645 NotifyDirectoryChanged(directory_path);
2646 DVLOG(1) << "Directory refreshed: " << directory_path.value();
2647 }
2648
2554 bool GDataFileSystem::GetFileInfoByPath( 2649 bool GDataFileSystem::GetFileInfoByPath(
2555 const FilePath& file_path, GDataFileProperties* properties) { 2650 const FilePath& file_path, GDataFileProperties* properties) {
2556 DCHECK(properties); 2651 DCHECK(properties);
2557 base::AutoLock lock(lock_); 2652 base::AutoLock lock(lock_);
2558 GDataEntry* entry = GetGDataEntryByPath(file_path); 2653 GDataEntry* entry = GetGDataEntryByPath(file_path);
2559 if (!entry) 2654 if (!entry)
2560 return false; 2655 return false;
2561 2656
2562 properties->file_info = entry->file_info(); 2657 properties->file_info = entry->file_info();
2563 properties->resource_id = entry->resource_id(); 2658 properties->resource_id = entry->resource_id();
(...skipping 2585 matching lines...) Expand 10 before | Expand all | Expand 10 after
5149 pref_registrar_->Init(profile_->GetPrefs()); 5244 pref_registrar_->Init(profile_->GetPrefs());
5150 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 5245 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
5151 } 5246 }
5152 5247
5153 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 5248 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
5154 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 5249 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
5155 global_free_disk_getter_for_testing = getter; 5250 global_free_disk_getter_for_testing = getter;
5156 } 5251 }
5157 5252
5158 } // namespace gdata 5253 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698