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

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

Issue 10444082: Refresh drive file system metadata for entries in search results. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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 2188 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 params.get_file_callback, 2199 params.get_file_callback,
2200 params.get_download_data_callback))); 2200 params.get_download_data_callback)));
2201 } 2201 }
2202 2202
2203 void GDataFileSystem::OnGetDocumentEntry(const FilePath& cache_file_path, 2203 void GDataFileSystem::OnGetDocumentEntry(const FilePath& cache_file_path,
2204 const GetFileFromCacheParams& params, 2204 const GetFileFromCacheParams& params,
2205 GDataErrorCode status, 2205 GDataErrorCode status,
2206 scoped_ptr<base::Value> data) { 2206 scoped_ptr<base::Value> data) {
2207 base::PlatformFileError error = GDataToPlatformError(status); 2207 base::PlatformFileError error = GDataToPlatformError(status);
2208 2208
2209 GDataEntry* fresh_entry = NULL; 2209 scoped_ptr<GDataEntry> fresh_entry;
2210 if (error == base::PLATFORM_FILE_OK) { 2210 if (error == base::PLATFORM_FILE_OK) {
2211 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); 2211 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data));
2212 if (doc_entry.get()) { 2212 if (doc_entry.get()) {
2213 fresh_entry = 2213 fresh_entry.reset(
2214 GDataEntry::FromDocumentEntry(NULL, doc_entry.get(), root_.get()); 2214 GDataEntry::FromDocumentEntry(NULL, doc_entry.get(), root_.get()));
2215 } 2215 }
2216 if (!fresh_entry || !fresh_entry->AsGDataFile()) { 2216 if (!fresh_entry.get() || !fresh_entry->AsGDataFile()) {
2217 LOG(ERROR) << "Got invalid entry from server for " << params.resource_id; 2217 LOG(ERROR) << "Got invalid entry from server for " << params.resource_id;
2218 error = base::PLATFORM_FILE_ERROR_FAILED; 2218 error = base::PLATFORM_FILE_ERROR_FAILED;
2219 } 2219 }
2220 } 2220 }
2221 2221
2222 if (error != base::PLATFORM_FILE_OK) { 2222 if (error != base::PLATFORM_FILE_OK) {
2223 if (!params.get_file_callback.is_null()) { 2223 if (!params.get_file_callback.is_null()) {
2224 params.get_file_callback.Run(error, 2224 params.get_file_callback.Run(error,
2225 cache_file_path, 2225 cache_file_path,
2226 params.mime_type, 2226 params.mime_type,
2227 REGULAR_FILE); 2227 REGULAR_FILE);
2228 } 2228 }
2229 return; 2229 return;
2230 } 2230 }
2231 2231
2232 GURL content_url = fresh_entry->content_url(); 2232 GURL content_url = fresh_entry->content_url();
2233 int64 file_size = fresh_entry->file_info().size; 2233 int64 file_size = fresh_entry->file_info().size;
2234 2234
2235 { 2235 {
2236 base::AutoLock lock(lock_); // We're accessing the root. 2236 base::AutoLock lock(lock_); // We're accessing the root.
2237 GDataEntry* old_entry = root_->GetEntryByResourceId(params.resource_id); 2237 DCHECK_EQ(params.resource_id, fresh_entry->resource_id());
2238 GDataDirectory* entry_parent = old_entry ? old_entry->parent() : NULL; 2238 scoped_ptr<GDataFile> fresh_entry_as_file(
2239 2239 fresh_entry.release()->AsGDataFile());
2240 if (entry_parent) { 2240 root_->RefreshFile(fresh_entry_as_file.Pass());
2241 DCHECK_EQ(fresh_entry->resource_id(), old_entry->resource_id());
2242 DCHECK(fresh_entry->AsGDataFile());
2243 DCHECK(old_entry->AsGDataFile());
2244
2245 entry_parent->RemoveEntry(old_entry);
2246 entry_parent->AddEntry(fresh_entry);
2247 }
2248 } 2241 }
2249 2242
2250 bool* has_enough_space = new bool(false); 2243 bool* has_enough_space = new bool(false);
2251 PostBlockingPoolSequencedTaskAndReply( 2244 PostBlockingPoolSequencedTaskAndReply(
2252 FROM_HERE, 2245 FROM_HERE,
2253 base::Bind(&GDataFileSystem::FreeDiskSpaceIfNeededFor, 2246 base::Bind(&GDataFileSystem::FreeDiskSpaceIfNeededFor,
2254 base::Unretained(this), 2247 base::Unretained(this),
2255 file_size, 2248 file_size,
2256 has_enough_space), 2249 has_enough_space),
2257 base::Bind(&GDataFileSystem::StartDownloadFileIfEnoughSpace, 2250 base::Bind(&GDataFileSystem::StartDownloadFileIfEnoughSpace,
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
2897 2890
2898 if (!params.callback.is_null()) { 2891 if (!params.callback.is_null()) {
2899 // Finally done with the create request. 2892 // Finally done with the create request.
2900 params.callback.Run(base::PLATFORM_FILE_OK); 2893 params.callback.Run(base::PLATFORM_FILE_OK);
2901 } 2894 }
2902 } 2895 }
2903 2896
2904 void GDataFileSystem::OnSearch(const ReadDirectoryCallback& callback, 2897 void GDataFileSystem::OnSearch(const ReadDirectoryCallback& callback,
2905 GetDocumentsParams* params, 2898 GetDocumentsParams* params,
2906 base::PlatformFileError error) { 2899 base::PlatformFileError error) {
2900 if (error != base::PLATFORM_FILE_OK) {
2901 if (!callback.is_null())
2902 callback.Run(error, scoped_ptr<GDataDirectoryProto>());
2903 return;
2904 }
2905
2906 // We will refresh values in root for entries received in the feed.
2907 base::AutoLock lock(lock_);
2908
2907 // The search results will be returned using virtual directory. 2909 // The search results will be returned using virtual directory.
2908 // The directory is not really part of the file system, so it has no parent or 2910 // The directory is not really part of the file system, so it has no parent or
2909 // root. 2911 // root.
2910 scoped_ptr<GDataDirectory> search_dir(new GDataDirectory(NULL, NULL)); 2912 scoped_ptr<GDataDirectory> search_dir(new GDataDirectory(NULL, NULL));
2911 2913
2912 base::AutoLock lock(lock_); 2914 DCHECK_EQ(1u, params->feed_list->size());
2915 DocumentFeed* feed = params->feed_list->at(0);
2913 2916
2914 int delta_feed_changestamp = 0; 2917 // Go through all entires generated by the feed and add them to the search
2915 int num_regular_files = 0; 2918 // result directory.
2916 int num_hosted_documents = 0; 2919 for (size_t i = 0; i < feed->entries().size(); ++i){
2917 FileResourceIdMap file_map; 2920 DocumentEntry* doc = feed->entries()->at(i);
2918 if (error == base::PLATFORM_FILE_OK) { 2921 GDataEntry* entry = GDataEntry::FromDocumentEntry(NULL, doc, root_.get());
2919 error = FeedToFileResourceMap(*params->feed_list,
2920 &file_map,
2921 &delta_feed_changestamp,
2922 &num_regular_files,
2923 &num_hosted_documents);
2924 }
2925 2922
2926 if (error == base::PLATFORM_FILE_OK) { 2923 if (!entry)
2927 std::set<FilePath> ignored; 2924 continue;
2928 2925
2929 // Go through all entires generated by the feed and add them to the search 2926 DCHECK_EQ(doc->resource_id(), entry->resource_id());
2930 // result directory. 2927 DCHECK(!entry->is_deleted());
2931 for (FileResourceIdMap::const_iterator it = file_map.begin();
2932 it != file_map.end(); ++it) {
2933 scoped_ptr<GDataEntry> entry(it->second);
2934 DCHECK_EQ(it->first, entry->resource_id());
2935 DCHECK(!entry->is_deleted());
2936 2928
2937 entry->set_title(entry->resource_id() + "." + entry->title()); 2929 if (entry->AsGDataFile()) {
2930 // We have to make a new copy of the entry because |search_dir| will later
2931 // take ownership of |entry|.
2932 GDataEntry* entry_to_save =
2933 GDataEntry::FromDocumentEntry(NULL, doc, root_.get());
2934 DCHECK(entry_to_save && entry_to_save->AsGDataFile());
2935 DCHECK_EQ(entry->resource_id(), entry_to_save->resource_id());
2936 scoped_ptr<GDataFile>entry_to_save_as_file(entry_to_save->AsGDataFile());
2937 root_->RefreshFile(entry_to_save_as_file.Pass());
2938 }
2938 2939
2939 search_dir->AddEntry(entry.release()); 2940 entry->set_title(entry->resource_id() + "." + entry->title());
2940 } 2941
2942 search_dir->AddEntry(entry);
2941 } 2943 }
2942 2944
2943 scoped_ptr<GDataDirectoryProto> directory_proto(new GDataDirectoryProto); 2945 scoped_ptr<GDataDirectoryProto> directory_proto(new GDataDirectoryProto);
2944 search_dir->ToProto(directory_proto.get()); 2946 search_dir->ToProto(directory_proto.get());
2945 2947
2946 if (!callback.is_null()) { 2948 if (!callback.is_null())
2947 callback.Run(error, directory_proto.Pass()); 2949 callback.Run(error, directory_proto.Pass());
2948 }
2949 } 2950 }
2950 2951
2951 void GDataFileSystem::SearchAsync(const std::string& search_query, 2952 void GDataFileSystem::SearchAsync(const std::string& search_query,
2952 const ReadDirectoryCallback& callback) { 2953 const ReadDirectoryCallback& callback) {
2953 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2954 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2954 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2955 BrowserThread::CurrentlyOn(BrowserThread::IO));
2955 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread, 2956 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread,
2956 ui_weak_ptr_, 2957 ui_weak_ptr_,
2957 search_query, 2958 search_query,
2958 CreateRelayCallback(callback))); 2959 CreateRelayCallback(callback)));
(...skipping 2140 matching lines...) Expand 10 before | Expand all | Expand 10 after
5099 pref_registrar_->Init(profile_->GetPrefs()); 5100 pref_registrar_->Init(profile_->GetPrefs());
5100 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 5101 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
5101 } 5102 }
5102 5103
5103 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 5104 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
5104 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 5105 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
5105 global_free_disk_getter_for_testing = getter; 5106 global_free_disk_getter_for_testing = getter;
5106 } 5107 }
5107 5108
5108 } // namespace gdata 5109 } // namespace gdata
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/gdata/gdata_files.h » ('j') | chrome/browser/chromeos/gdata/gdata_files_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698