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

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

Issue 10826006: gdata: File info of dirty files should be get from the cached file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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 <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 base::SequencedTaskRunner* blocking_task_runner, 585 base::SequencedTaskRunner* blocking_task_runner,
586 const base::Closure& request_task, 586 const base::Closure& request_task,
587 const base::Closure& reply_task) { 587 const base::Closure& reply_task) {
588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
589 589
590 const bool posted = blocking_task_runner->PostTaskAndReply( 590 const bool posted = blocking_task_runner->PostTaskAndReply(
591 from_here, request_task, reply_task); 591 from_here, request_task, reply_task);
592 DCHECK(posted); 592 DCHECK(posted);
593 } 593 }
594 594
595 // Helper function for binding |path| to GetEntryInfoWithFilePathCallback and
596 // create GetEntryInfoCallback.
597 void RunGetEntryInfoWithFilePathCallback(
598 const GetEntryInfoWithFilePathCallback& callback,
599 const FilePath& path,
600 GDataFileError error,
601 scoped_ptr<GDataEntryProto> entry_proto) {
602 if (!callback.is_null())
603 callback.Run(error, path, entry_proto.Pass());
604 }
605
595 } // namespace 606 } // namespace
596 607
597 // GDataFileSystem::GetDocumentsParams struct implementation. 608 // GDataFileSystem::GetDocumentsParams struct implementation.
598 struct GDataFileSystem::GetDocumentsParams { 609 struct GDataFileSystem::GetDocumentsParams {
599 GetDocumentsParams(int start_changestamp, 610 GetDocumentsParams(int start_changestamp,
600 int root_feed_changestamp, 611 int root_feed_changestamp,
601 std::vector<DocumentFeed*>* feed_list, 612 std::vector<DocumentFeed*>* feed_list,
602 bool should_fetch_multiple_feeds, 613 bool should_fetch_multiple_feeds,
603 const FilePath& search_file_path, 614 const FilePath& search_file_path,
604 const std::string& search_query, 615 const std::string& search_query,
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 } 898 }
888 899
889 void GDataFileSystem::GetEntryInfoByEntryOnUIThread( 900 void GDataFileSystem::GetEntryInfoByEntryOnUIThread(
890 const GetEntryInfoWithFilePathCallback& callback, 901 const GetEntryInfoWithFilePathCallback& callback,
891 GDataEntry* entry) { 902 GDataEntry* entry) {
892 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 903 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
893 904
894 if (entry) { 905 if (entry) {
895 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto); 906 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto);
896 entry->ToProtoFull(entry_proto.get()); 907 entry->ToProtoFull(entry_proto.get());
897 callback.Run(GDATA_FILE_OK, entry->GetFilePath(), entry_proto.Pass()); 908 ReflectLocalModificationToGDataEntryProto(
909 base::Bind(&RunGetEntryInfoWithFilePathCallback,
910 callback, entry->GetFilePath()),
911 entry_proto.Pass());
898 } else { 912 } else {
899 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, 913 callback.Run(GDATA_FILE_ERROR_NOT_FOUND,
900 FilePath(), 914 FilePath(),
901 scoped_ptr<GDataEntryProto>()); 915 scoped_ptr<GDataEntryProto>());
902 } 916 }
903 } 917 }
904 918
905 void GDataFileSystem::FindEntryByPathAsyncOnUIThread( 919 void GDataFileSystem::FindEntryByPathAsyncOnUIThread(
906 const FilePath& search_file_path, 920 const FilePath& search_file_path,
907 const FindEntryCallback& callback) { 921 const FindEntryCallback& callback) {
(...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after
2241 if (error != GDATA_FILE_OK) { 2255 if (error != GDATA_FILE_OK) {
2242 if (!callback.is_null()) 2256 if (!callback.is_null())
2243 callback.Run(error, scoped_ptr<GDataEntryProto>()); 2257 callback.Run(error, scoped_ptr<GDataEntryProto>());
2244 return; 2258 return;
2245 } 2259 }
2246 DCHECK(entry); 2260 DCHECK(entry);
2247 2261
2248 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto); 2262 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto);
2249 entry->ToProtoFull(entry_proto.get()); 2263 entry->ToProtoFull(entry_proto.get());
2250 2264
2251 if (!callback.is_null()) 2265 ReflectLocalModificationToGDataEntryProto(callback, entry_proto.Pass());
2252 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
2253 } 2266 }
2254 2267
2255 void GDataFileSystem::ReadDirectoryByPath( 2268 void GDataFileSystem::ReadDirectoryByPath(
2256 const FilePath& file_path, 2269 const FilePath& file_path,
2257 const ReadDirectoryCallback& callback) { 2270 const ReadDirectoryCallback& callback) {
2258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2259 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2272 BrowserThread::CurrentlyOn(BrowserThread::IO));
2260 RunTaskOnUIThread( 2273 RunTaskOnUIThread(
2261 base::Bind(&GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread, 2274 base::Bind(&GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread,
2262 ui_weak_ptr_, 2275 ui_weak_ptr_,
(...skipping 1847 matching lines...) Expand 10 before | Expand all | Expand 10 after
4110 // All the invocation of |callback| from operations initiated from CloseFile 4123 // All the invocation of |callback| from operations initiated from CloseFile
4111 // must go through here. Removes the |file_path| from the remembered set so 4124 // must go through here. Removes the |file_path| from the remembered set so
4112 // that subsequent operations can open the file again. 4125 // that subsequent operations can open the file again.
4113 open_files_.erase(file_path); 4126 open_files_.erase(file_path);
4114 4127
4115 // Then invokes the user-supplied callback function. 4128 // Then invokes the user-supplied callback function.
4116 if (!callback.is_null()) 4129 if (!callback.is_null())
4117 callback.Run(result); 4130 callback.Run(result);
4118 } 4131 }
4119 4132
4133 void GDataFileSystem::ReflectLocalModificationToGDataEntryProto(
satorux1 2012/07/25 19:28:45 maybe CheckLocalModificationAndRun() would describ
kinaba 2012/07/26 03:17:53 Done.
4134 const GetEntryInfoCallback& callback,
4135 scoped_ptr<GDataEntryProto> entry_proto) {
satorux1 2012/07/25 19:28:45 I'd swap these parameters with the new function na
kinaba 2012/07/26 03:17:53 Done.
4136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
satorux1 2012/07/25 19:28:45 DCHECK(entry_proto.get()); This should be guarante
kinaba 2012/07/26 03:17:53 Yes. Done.
4137
4138 // For entries that will never be cached, use the original entry info as is.
4139 if (!entry_proto.get() || !entry_proto->has_file_specific_info() ||
satorux1 2012/07/25 19:28:45 I'd remove !entry_proto.get()
kinaba 2012/07/26 03:17:53 Done.
4140 entry_proto->file_specific_info().file_md5().empty() ||
satorux1 2012/07/25 19:28:45 I think we can remove this line.
kinaba 2012/07/26 03:17:53 Done.
4141 entry_proto->file_specific_info().is_hosted_document()) {
4142 if (!callback.is_null())
4143 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
4144 return;
4145 }
4146
4147 // Checks if the file is cached and modified locally.
4148 const std::string resource_id = entry_proto->resource_id();
4149 const std::string md5 = entry_proto->file_specific_info().file_md5();
4150 cache_->GetCacheEntryOnUIThread(
4151 resource_id,
4152 md5,
4153 base::Bind(&GDataFileSystem::OnGetCacheEntryForReflectLocalModification,
4154 ui_weak_ptr_, callback, base::Passed(&entry_proto)));
4155 }
4156
4157 void GDataFileSystem::OnGetCacheEntryForReflectLocalModification(
satorux1 2012/07/25 19:28:45 ReflectLocalModificationAfterGetCacheEntry() may b
kinaba 2012/07/26 03:17:53 Done.
4158 const GetEntryInfoCallback& callback,
4159 scoped_ptr<GDataEntryProto> entry_proto,
4160 bool success,
4161 const GDataCacheEntry& cache_entry) {
4162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
4163
4164 // When no dirty cache is found, use the original entry info as is.
4165 if (!success || !cache_entry.is_dirty()) {
4166 if (!callback.is_null())
4167 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
4168 return;
4169 }
4170
4171 // Gets the cache file path.
4172 const std::string resource_id = entry_proto->resource_id();
4173 const std::string md5 = entry_proto->file_specific_info().file_md5();
satorux1 2012/07/25 19:28:45 make them const reference?
kinaba 2012/07/26 03:17:53 Done.
4174 cache_->GetFileOnUIThread(
4175 resource_id,
4176 md5,
4177 base::Bind(&GDataFileSystem::OnGetCacheFileForReflectLocalModification,
4178 ui_weak_ptr_, callback, base::Passed(&entry_proto)));
4179 }
4180
4181 void GDataFileSystem::OnGetCacheFileForReflectLocalModification(
4182 const GetEntryInfoCallback& callback,
4183 scoped_ptr<GDataEntryProto> entry_proto,
4184 GDataFileError error,
4185 const std::string& resource_id,
4186 const std::string& md5,
4187 const FilePath& local_cache_path) {
4188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
4189
4190 // When no dirty cache is found, use the original entry info as is.
4191 if (error != GDATA_FILE_OK) {
4192 if (!callback.is_null())
4193 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
4194 return;
4195 }
4196
4197 // If the cache is dirty, obtain the file info from the cache file itself.
4198 base::PlatformFileInfo* file_info = new base::PlatformFileInfo;
4199 bool* get_file_info_result = new bool(false);
4200 PostBlockingPoolSequencedTaskAndReply(
4201 FROM_HERE,
4202 blocking_task_runner_,
4203 base::Bind(&GetFileInfoOnBlockingPool,
4204 local_cache_path,
4205 base::Unretained(file_info),
4206 base::Unretained(get_file_info_result)),
4207 base::Bind(&GDataFileSystem::OnGetFileInfoForReflectLocalModification,
4208 ui_weak_ptr_,
4209 callback,
4210 base::Passed(&entry_proto),
4211 base::Owned(file_info),
4212 base::Owned(get_file_info_result)));
4213 }
4214
4215 void GDataFileSystem::OnGetFileInfoForReflectLocalModification(
4216 const GetEntryInfoCallback& callback,
4217 scoped_ptr<GDataEntryProto> entry_proto,
4218 base::PlatformFileInfo* file_info,
4219 bool* get_file_info_result) {
4220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
4221
4222 if (*get_file_info_result) {
4223 PlatformFileInfoProto entry_file_info;
4224 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
4225 *entry_proto->mutable_file_info() = entry_file_info;
4226 }
4227 if (!callback.is_null())
4228 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
satorux1 2012/07/25 19:28:45 This looks wrong. The error code should be GDATA_F
kinaba 2012/07/26 03:17:53 Done.
4229 }
4230
4120 } // namespace gdata 4231 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698