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

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: a nit 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 root_->RefreshFile(fresh_entry.Pass());
2239
2240 if (entry_parent) {
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 } 2239 }
2249 2240
2250 bool* has_enough_space = new bool(false); 2241 bool* has_enough_space = new bool(false);
2251 PostBlockingPoolSequencedTaskAndReply( 2242 PostBlockingPoolSequencedTaskAndReply(
2252 FROM_HERE, 2243 FROM_HERE,
2253 base::Bind(&GDataFileSystem::FreeDiskSpaceIfNeededFor, 2244 base::Bind(&GDataFileSystem::FreeDiskSpaceIfNeededFor,
2254 base::Unretained(this), 2245 base::Unretained(this),
2255 file_size, 2246 file_size,
2256 has_enough_space), 2247 has_enough_space),
2257 base::Bind(&GDataFileSystem::StartDownloadFileIfEnoughSpace, 2248 base::Bind(&GDataFileSystem::StartDownloadFileIfEnoughSpace,
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
2897 2888
2898 if (!params.callback.is_null()) { 2889 if (!params.callback.is_null()) {
2899 // Finally done with the create request. 2890 // Finally done with the create request.
2900 params.callback.Run(base::PLATFORM_FILE_OK); 2891 params.callback.Run(base::PLATFORM_FILE_OK);
2901 } 2892 }
2902 } 2893 }
2903 2894
2904 void GDataFileSystem::OnSearch(const ReadDirectoryCallback& callback, 2895 void GDataFileSystem::OnSearch(const ReadDirectoryCallback& callback,
2905 GetDocumentsParams* params, 2896 GetDocumentsParams* params,
2906 base::PlatformFileError error) { 2897 base::PlatformFileError error) {
2898 if (error != base::PLATFORM_FILE_OK) {
2899 if (!callback.is_null())
2900 callback.Run(error, scoped_ptr<GDataDirectoryProto>());
2901 return;
2902 }
2903
2904 // We will refresh values in root for entries received in the feed.
2905 base::AutoLock lock(lock_);
2906
2907 // The search results will be returned using virtual directory. 2907 // 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 2908 // The directory is not really part of the file system, so it has no parent or
2909 // root. 2909 // root.
2910 scoped_ptr<GDataDirectory> search_dir(new GDataDirectory(NULL, NULL)); 2910 scoped_ptr<GDataDirectory> search_dir(new GDataDirectory(NULL, NULL));
2911 2911
2912 base::AutoLock lock(lock_); 2912 DCHECK_EQ(1u, params->feed_list->size());
2913 DocumentFeed* feed = params->feed_list->at(0);
2913 2914
2914 int delta_feed_changestamp = 0; 2915 // Go through all entires generated by the feed and add them to the search
2915 int num_regular_files = 0; 2916 // result directory.
2916 int num_hosted_documents = 0; 2917 for (size_t i = 0; i < feed->entries().size(); ++i){
2917 FileResourceIdMap file_map; 2918 DocumentEntry* doc = feed->entries()->at(i);
2918 if (error == base::PLATFORM_FILE_OK) { 2919 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 2920
2926 if (error == base::PLATFORM_FILE_OK) { 2921 if (!entry)
2927 std::set<FilePath> ignored; 2922 continue;
2928 2923
2929 // Go through all entires generated by the feed and add them to the search 2924 DCHECK_EQ(doc->resource_id(), entry->resource_id());
2930 // result directory. 2925 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 2926
2937 entry->set_title(entry->resource_id() + "." + entry->title()); 2927 if (entry->AsGDataFile()) {
2928 // We have to make a new copy of the entry because |search_dir| will later
2929 // take ownership of |entry|.
2930 scoped_ptr<GDataEntry> entry_to_save(
2931 GDataEntry::FromDocumentEntry(NULL, doc, root_.get()));
2932 DCHECK(entry_to_save.get());
2933 DCHECK_EQ(entry->resource_id(), entry_to_save->resource_id());
2934 root_->RefreshFile(entry_to_save.Pass());
2935 }
2938 2936
2939 search_dir->AddEntry(entry.release()); 2937 entry->set_title(entry->resource_id() + "." + entry->title());
2940 } 2938
2939 search_dir->AddEntry(entry);
2941 } 2940 }
2942 2941
2943 scoped_ptr<GDataDirectoryProto> directory_proto(new GDataDirectoryProto); 2942 scoped_ptr<GDataDirectoryProto> directory_proto(new GDataDirectoryProto);
2944 search_dir->ToProto(directory_proto.get()); 2943 search_dir->ToProto(directory_proto.get());
2945 2944
2946 if (!callback.is_null()) { 2945 if (!callback.is_null())
2947 callback.Run(error, directory_proto.Pass()); 2946 callback.Run(error, directory_proto.Pass());
2948 }
2949 } 2947 }
2950 2948
2951 void GDataFileSystem::SearchAsync(const std::string& search_query, 2949 void GDataFileSystem::SearchAsync(const std::string& search_query,
2952 const ReadDirectoryCallback& callback) { 2950 const ReadDirectoryCallback& callback) {
2953 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2951 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2954 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2952 BrowserThread::CurrentlyOn(BrowserThread::IO));
2955 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread, 2953 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread,
2956 ui_weak_ptr_, 2954 ui_weak_ptr_,
2957 search_query, 2955 search_query,
2958 CreateRelayCallback(callback))); 2956 CreateRelayCallback(callback)));
(...skipping 2140 matching lines...) Expand 10 before | Expand all | Expand 10 after
5099 pref_registrar_->Init(profile_->GetPrefs()); 5097 pref_registrar_->Init(profile_->GetPrefs());
5100 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 5098 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
5101 } 5099 }
5102 5100
5103 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 5101 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
5104 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 5102 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
5105 global_free_disk_getter_for_testing = getter; 5103 global_free_disk_getter_for_testing = getter;
5106 } 5104 }
5107 5105
5108 } // namespace gdata 5106 } // 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.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698