Chromium Code Reviews| 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 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 802 // Ditto for SetMountedStateCallback. | 802 // Ditto for SetMountedStateCallback. |
| 803 void RelaySetMountedStateCallback( | 803 void RelaySetMountedStateCallback( |
| 804 scoped_refptr<base::MessageLoopProxy> relay_proxy, | 804 scoped_refptr<base::MessageLoopProxy> relay_proxy, |
| 805 const SetMountedStateCallback& callback, | 805 const SetMountedStateCallback& callback, |
| 806 base::PlatformFileError error, | 806 base::PlatformFileError error, |
| 807 const FilePath& file_path) { | 807 const FilePath& file_path) { |
| 808 relay_proxy->PostTask(FROM_HERE, | 808 relay_proxy->PostTask(FROM_HERE, |
| 809 base::Bind(callback, error, file_path)); | 809 base::Bind(callback, error, file_path)); |
| 810 } | 810 } |
| 811 | 811 |
| 812 // Ditto for GetEntryInfoCallback. | |
| 813 void RelayGetEntryInfoCallback( | |
| 814 scoped_refptr<base::MessageLoopProxy> relay_proxy, | |
| 815 const GetEntryInfoCallback& callback, | |
| 816 base::PlatformFileError error, | |
| 817 scoped_ptr<GDataEntryProto> entry_proto) { | |
| 818 relay_proxy->PostTask( | |
| 819 FROM_HERE, | |
| 820 base::Bind(callback, error, base::Passed(&entry_proto))); | |
| 821 } | |
| 822 | |
| 812 // Ditto for GetFileInfoCallback. | 823 // Ditto for GetFileInfoCallback. |
| 813 void RelayGetFileInfoCallback( | 824 void RelayGetFileInfoCallback( |
| 814 scoped_refptr<base::MessageLoopProxy> relay_proxy, | 825 scoped_refptr<base::MessageLoopProxy> relay_proxy, |
| 815 const GetFileInfoCallback& callback, | 826 const GetFileInfoCallback& callback, |
| 816 base::PlatformFileError error, | 827 base::PlatformFileError error, |
| 817 scoped_ptr<GDataFileProto> file_proto) { | 828 scoped_ptr<GDataFileProto> file_proto) { |
| 818 relay_proxy->PostTask( | 829 relay_proxy->PostTask( |
| 819 FROM_HERE, | 830 FROM_HERE, |
| 820 base::Bind(callback, error, base::Passed(&file_proto))); | 831 base::Bind(callback, error, base::Passed(&file_proto))); |
| 821 } | 832 } |
| (...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2120 } | 2131 } |
| 2121 | 2132 |
| 2122 void GDataFileSystem::ResumeUpload( | 2133 void GDataFileSystem::ResumeUpload( |
| 2123 const ResumeUploadParams& params, | 2134 const ResumeUploadParams& params, |
| 2124 const ResumeFileUploadCallback& callback) { | 2135 const ResumeFileUploadCallback& callback) { |
| 2125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2126 | 2137 |
| 2127 documents_service_->ResumeUpload(params, callback); | 2138 documents_service_->ResumeUpload(params, callback); |
| 2128 } | 2139 } |
| 2129 | 2140 |
| 2141 void GDataFileSystem::GetEntryInfoByPathAsync( | |
|
achuithb
2012/05/01 09:27:09
This is a lot of boiler plate copy and paste. Is t
satorux1
2012/05/01 16:50:41
I totally agree with you that the code is overly r
| |
| 2142 const FilePath& file_path, | |
| 2143 const GetEntryInfoCallback& callback) { | |
| 2144 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | |
| 2145 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 2146 const bool posted = BrowserThread::PostTask( | |
| 2147 BrowserThread::UI, | |
| 2148 FROM_HERE, | |
| 2149 base::Bind(&GDataFileSystem::GetEntryInfoByPathAsyncOnUIThread, | |
| 2150 ui_weak_ptr_, | |
| 2151 file_path, | |
| 2152 base::Bind(&RelayGetEntryInfoCallback, | |
| 2153 base::MessageLoopProxy::current(), | |
| 2154 callback))); | |
| 2155 DCHECK(posted); | |
| 2156 return; | |
| 2157 } | |
| 2158 | |
| 2159 GetEntryInfoByPathAsyncOnUIThread(file_path, callback); | |
| 2160 } | |
| 2161 | |
| 2162 void GDataFileSystem::GetEntryInfoByPathAsyncOnUIThread( | |
| 2163 const FilePath& file_path, | |
| 2164 const GetEntryInfoCallback& callback) { | |
| 2165 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 2166 | |
| 2167 FindEntryByPathAsyncOnUIThread( | |
| 2168 file_path, | |
| 2169 base::Bind(&GDataFileSystem::OnGetEntryInfo, | |
| 2170 ui_weak_ptr_, | |
| 2171 callback)); | |
| 2172 } | |
| 2173 | |
| 2174 void GDataFileSystem::OnGetEntryInfo(const GetEntryInfoCallback& callback, | |
| 2175 base::PlatformFileError error, | |
| 2176 const FilePath& directory_path, | |
| 2177 GDataEntry* entry) { | |
| 2178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 2179 | |
| 2180 if (error != base::PLATFORM_FILE_OK) { | |
| 2181 if (!callback.is_null()) | |
| 2182 callback.Run(error, scoped_ptr<GDataEntryProto>()); | |
| 2183 return; | |
| 2184 } | |
| 2185 DCHECK(entry); | |
| 2186 | |
| 2187 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto); | |
| 2188 entry->ToProto(entry_proto.get()); | |
| 2189 | |
| 2190 if (!callback.is_null()) | |
| 2191 callback.Run(base::PLATFORM_FILE_OK, entry_proto.Pass()); | |
| 2192 } | |
| 2193 | |
| 2130 void GDataFileSystem::GetFileInfoByPathAsync( | 2194 void GDataFileSystem::GetFileInfoByPathAsync( |
| 2131 const FilePath& file_path, | 2195 const FilePath& file_path, |
| 2132 const GetFileInfoCallback& callback) { | 2196 const GetFileInfoCallback& callback) { |
| 2133 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 2197 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 2134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2135 const bool posted = BrowserThread::PostTask( | 2199 const bool posted = BrowserThread::PostTask( |
| 2136 BrowserThread::UI, | 2200 BrowserThread::UI, |
| 2137 FROM_HERE, | 2201 FROM_HERE, |
| 2138 base::Bind(&GDataFileSystem::GetFileInfoByPathAsyncOnUIThread, | 2202 base::Bind(&GDataFileSystem::GetFileInfoByPathAsyncOnUIThread, |
| 2139 ui_weak_ptr_, | 2203 ui_weak_ptr_, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2164 base::PlatformFileError error, | 2228 base::PlatformFileError error, |
| 2165 const FilePath& directory_path, | 2229 const FilePath& directory_path, |
| 2166 GDataEntry* entry) { | 2230 GDataEntry* entry) { |
| 2167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2168 | 2232 |
| 2169 if (error != base::PLATFORM_FILE_OK) { | 2233 if (error != base::PLATFORM_FILE_OK) { |
| 2170 if (!callback.is_null()) | 2234 if (!callback.is_null()) |
| 2171 callback.Run(error, scoped_ptr<GDataFileProto>()); | 2235 callback.Run(error, scoped_ptr<GDataFileProto>()); |
| 2172 return; | 2236 return; |
| 2173 } | 2237 } |
| 2238 DCHECK(entry); | |
| 2174 | 2239 |
| 2175 GDataFile* file = entry->AsGDataFile(); | 2240 GDataFile* file = entry->AsGDataFile(); |
| 2176 if (!file) { | 2241 if (!file) { |
| 2177 if (!callback.is_null()) | 2242 if (!callback.is_null()) |
| 2178 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 2243 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 2179 scoped_ptr<GDataFileProto>()); | 2244 scoped_ptr<GDataFileProto>()); |
| 2180 return; | 2245 return; |
| 2181 } | 2246 } |
| 2182 | 2247 |
| 2183 scoped_ptr<GDataFileProto> file_proto(new GDataFileProto); | 2248 scoped_ptr<GDataFileProto> file_proto(new GDataFileProto); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2224 base::PlatformFileError error, | 2289 base::PlatformFileError error, |
| 2225 const FilePath& directory_path, | 2290 const FilePath& directory_path, |
| 2226 GDataEntry* entry) { | 2291 GDataEntry* entry) { |
| 2227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2228 | 2293 |
| 2229 if (error != base::PLATFORM_FILE_OK) { | 2294 if (error != base::PLATFORM_FILE_OK) { |
| 2230 if (!callback.is_null()) | 2295 if (!callback.is_null()) |
| 2231 callback.Run(error, scoped_ptr<GDataDirectoryProto>()); | 2296 callback.Run(error, scoped_ptr<GDataDirectoryProto>()); |
| 2232 return; | 2297 return; |
| 2233 } | 2298 } |
| 2299 DCHECK(entry); | |
| 2234 | 2300 |
| 2235 GDataDirectory* directory = entry->AsGDataDirectory(); | 2301 GDataDirectory* directory = entry->AsGDataDirectory(); |
| 2236 if (!directory) { | 2302 if (!directory) { |
| 2237 if (!callback.is_null()) | 2303 if (!callback.is_null()) |
| 2238 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 2304 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 2239 scoped_ptr<GDataDirectoryProto>()); | 2305 scoped_ptr<GDataDirectoryProto>()); |
| 2240 return; | 2306 return; |
| 2241 } | 2307 } |
| 2242 | 2308 |
| 2243 scoped_ptr<GDataDirectoryProto> directory_proto(new GDataDirectoryProto); | 2309 scoped_ptr<GDataDirectoryProto> directory_proto(new GDataDirectoryProto); |
| (...skipping 2471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4715 pref_registrar_->Init(profile_->GetPrefs()); | 4781 pref_registrar_->Init(profile_->GetPrefs()); |
| 4716 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 4782 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
| 4717 } | 4783 } |
| 4718 | 4784 |
| 4719 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 4785 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
| 4720 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 4786 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
| 4721 global_free_disk_getter_for_testing = getter; | 4787 global_free_disk_getter_for_testing = getter; |
| 4722 } | 4788 } |
| 4723 | 4789 |
| 4724 } // namespace gdata | 4790 } // namespace gdata |
| OLD | NEW |