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 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 void RelayGetFileInfoCallback( | 813 void RelayGetFileInfoCallback( |
814 scoped_refptr<base::MessageLoopProxy> relay_proxy, | 814 scoped_refptr<base::MessageLoopProxy> relay_proxy, |
815 const GetFileInfoCallback& callback, | 815 const GetFileInfoCallback& callback, |
816 base::PlatformFileError error, | 816 base::PlatformFileError error, |
817 scoped_ptr<GDataFileProto> file_proto) { | 817 scoped_ptr<GDataFileProto> file_proto) { |
818 relay_proxy->PostTask( | 818 relay_proxy->PostTask( |
819 FROM_HERE, | 819 FROM_HERE, |
820 base::Bind(callback, error, base::Passed(&file_proto))); | 820 base::Bind(callback, error, base::Passed(&file_proto))); |
821 } | 821 } |
822 | 822 |
| 823 // Ditto for ReadDirectoryCallback. |
| 824 void RelayReadDirectoryCallback( |
| 825 scoped_refptr<base::MessageLoopProxy> relay_proxy, |
| 826 const ReadDirectoryCallback& callback, |
| 827 base::PlatformFileError error, |
| 828 scoped_ptr<GDataDirectoryProto> directory_proto) { |
| 829 relay_proxy->PostTask( |
| 830 FROM_HERE, |
| 831 base::Bind(callback, error, base::Passed(&directory_proto))); |
| 832 } |
| 833 |
823 } // namespace | 834 } // namespace |
824 | 835 |
825 // GDataFileProperties struct implementation. | 836 // GDataFileProperties struct implementation. |
826 | 837 |
827 GDataFileProperties::GDataFileProperties() : is_hosted_document(false) { | 838 GDataFileProperties::GDataFileProperties() : is_hosted_document(false) { |
828 } | 839 } |
829 | 840 |
830 GDataFileProperties::~GDataFileProperties() { | 841 GDataFileProperties::~GDataFileProperties() { |
831 } | 842 } |
832 | 843 |
(...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2117 } | 2128 } |
2118 | 2129 |
2119 void GDataFileSystem::GetFileInfoByPathAsync( | 2130 void GDataFileSystem::GetFileInfoByPathAsync( |
2120 const FilePath& file_path, | 2131 const FilePath& file_path, |
2121 const GetFileInfoCallback& callback) { | 2132 const GetFileInfoCallback& callback) { |
2122 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 2133 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
2123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2124 const bool posted = BrowserThread::PostTask( | 2135 const bool posted = BrowserThread::PostTask( |
2125 BrowserThread::UI, | 2136 BrowserThread::UI, |
2126 FROM_HERE, | 2137 FROM_HERE, |
2127 base::Bind(&GDataFileSystem::GetFileInfoByPathAsync, | 2138 base::Bind(&GDataFileSystem::GetFileInfoByPathAsyncOnUIThread, |
2128 ui_weak_ptr_, | 2139 ui_weak_ptr_, |
2129 file_path, | 2140 file_path, |
2130 base::Bind(&RelayGetFileInfoCallback, | 2141 base::Bind(&RelayGetFileInfoCallback, |
2131 base::MessageLoopProxy::current(), | 2142 base::MessageLoopProxy::current(), |
2132 callback))); | 2143 callback))); |
2133 DCHECK(posted); | 2144 DCHECK(posted); |
2134 return; | 2145 return; |
2135 } | 2146 } |
2136 | 2147 |
2137 GetFileInfoByPathAsyncOnUIThread(file_path, callback); | 2148 GetFileInfoByPathAsyncOnUIThread(file_path, callback); |
2138 } | 2149 } |
2139 | 2150 |
2140 void GDataFileSystem::GetFileInfoByPathAsyncOnUIThread( | 2151 void GDataFileSystem::GetFileInfoByPathAsyncOnUIThread( |
2141 const FilePath& file_path, | 2152 const FilePath& file_path, |
2142 const GetFileInfoCallback& callback) { | 2153 const GetFileInfoCallback& callback) { |
2143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2144 | 2155 |
2145 FindEntryByPathAsyncOnUIThread( | 2156 FindEntryByPathAsyncOnUIThread( |
2146 file_path, | 2157 file_path, |
2147 base::Bind(&GDataFileSystem::OnEntryFound, | 2158 base::Bind(&GDataFileSystem::OnGetFileInfo, |
2148 ui_weak_ptr_, | 2159 ui_weak_ptr_, |
2149 callback)); | 2160 callback)); |
2150 } | 2161 } |
2151 | 2162 |
2152 void GDataFileSystem::OnEntryFound(const GetFileInfoCallback& callback, | 2163 void GDataFileSystem::OnGetFileInfo(const GetFileInfoCallback& callback, |
2153 base::PlatformFileError error, | 2164 base::PlatformFileError error, |
2154 const FilePath& directory_path, | 2165 const FilePath& directory_path, |
2155 GDataEntry* entry) { | 2166 GDataEntry* entry) { |
2156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2167 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2157 | 2168 |
2158 if (error != base::PLATFORM_FILE_OK) { | 2169 if (error != base::PLATFORM_FILE_OK) { |
2159 if (!callback.is_null()) | 2170 if (!callback.is_null()) |
2160 callback.Run(error, scoped_ptr<GDataFileProto>()); | 2171 callback.Run(error, scoped_ptr<GDataFileProto>()); |
2161 return; | 2172 return; |
2162 } | 2173 } |
2163 | 2174 |
2164 GDataFile* file = entry->AsGDataFile(); | 2175 GDataFile* file = entry->AsGDataFile(); |
2165 if (!file) { | 2176 if (!file) { |
2166 if (!callback.is_null()) | 2177 if (!callback.is_null()) |
2167 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, | 2178 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
2168 scoped_ptr<GDataFileProto>()); | 2179 scoped_ptr<GDataFileProto>()); |
2169 return; | 2180 return; |
2170 } | 2181 } |
2171 | 2182 |
2172 scoped_ptr<GDataFileProto> file_proto(new GDataFileProto); | 2183 scoped_ptr<GDataFileProto> file_proto(new GDataFileProto); |
2173 file->ToProto(file_proto.get()); | 2184 file->ToProto(file_proto.get()); |
2174 | 2185 |
2175 if (!callback.is_null()) | 2186 if (!callback.is_null()) |
2176 callback.Run(base::PLATFORM_FILE_OK, file_proto.Pass()); | 2187 callback.Run(base::PLATFORM_FILE_OK, file_proto.Pass()); |
2177 } | 2188 } |
2178 | 2189 |
| 2190 void GDataFileSystem::ReadDirectoryByPathAsync( |
| 2191 const FilePath& file_path, |
| 2192 const ReadDirectoryCallback& callback) { |
| 2193 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 2194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 2195 const bool posted = BrowserThread::PostTask( |
| 2196 BrowserThread::UI, |
| 2197 FROM_HERE, |
| 2198 base::Bind(&GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread, |
| 2199 ui_weak_ptr_, |
| 2200 file_path, |
| 2201 base::Bind(&RelayReadDirectoryCallback, |
| 2202 base::MessageLoopProxy::current(), |
| 2203 callback))); |
| 2204 DCHECK(posted); |
| 2205 return; |
| 2206 } |
| 2207 |
| 2208 ReadDirectoryByPathAsyncOnUIThread(file_path, callback); |
| 2209 } |
| 2210 |
| 2211 void GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread( |
| 2212 const FilePath& file_path, |
| 2213 const ReadDirectoryCallback& callback) { |
| 2214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2215 |
| 2216 FindEntryByPathAsyncOnUIThread( |
| 2217 file_path, |
| 2218 base::Bind(&GDataFileSystem::OnReadDirectory, |
| 2219 ui_weak_ptr_, |
| 2220 callback)); |
| 2221 } |
| 2222 |
| 2223 void GDataFileSystem::OnReadDirectory(const ReadDirectoryCallback& callback, |
| 2224 base::PlatformFileError error, |
| 2225 const FilePath& directory_path, |
| 2226 GDataEntry* entry) { |
| 2227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2228 |
| 2229 if (error != base::PLATFORM_FILE_OK) { |
| 2230 if (!callback.is_null()) |
| 2231 callback.Run(error, scoped_ptr<GDataDirectoryProto>()); |
| 2232 return; |
| 2233 } |
| 2234 |
| 2235 GDataDirectory* directory = entry->AsGDataDirectory(); |
| 2236 if (!directory) { |
| 2237 if (!callback.is_null()) |
| 2238 callback.Run(base::PLATFORM_FILE_ERROR_NOT_FOUND, |
| 2239 scoped_ptr<GDataDirectoryProto>()); |
| 2240 return; |
| 2241 } |
| 2242 |
| 2243 scoped_ptr<GDataDirectoryProto> directory_proto(new GDataDirectoryProto); |
| 2244 directory->ToProto(directory_proto.get()); |
| 2245 |
| 2246 if (!callback.is_null()) |
| 2247 callback.Run(base::PLATFORM_FILE_OK, directory_proto.Pass()); |
| 2248 } |
| 2249 |
2179 bool GDataFileSystem::GetFileInfoByPath( | 2250 bool GDataFileSystem::GetFileInfoByPath( |
2180 const FilePath& file_path, GDataFileProperties* properties) { | 2251 const FilePath& file_path, GDataFileProperties* properties) { |
2181 DCHECK(properties); | 2252 DCHECK(properties); |
2182 base::AutoLock lock(lock_); | 2253 base::AutoLock lock(lock_); |
2183 GDataEntry* entry = GetGDataEntryByPath(file_path); | 2254 GDataEntry* entry = GetGDataEntryByPath(file_path); |
2184 if (!entry) | 2255 if (!entry) |
2185 return false; | 2256 return false; |
2186 | 2257 |
2187 properties->file_info = entry->file_info(); | 2258 properties->file_info = entry->file_info(); |
2188 properties->resource_id = entry->resource_id(); | 2259 properties->resource_id = entry->resource_id(); |
(...skipping 2455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4644 pref_registrar_->Init(profile_->GetPrefs()); | 4715 pref_registrar_->Init(profile_->GetPrefs()); |
4645 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 4716 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
4646 } | 4717 } |
4647 | 4718 |
4648 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 4719 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
4649 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 4720 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
4650 global_free_disk_getter_for_testing = getter; | 4721 global_free_disk_getter_for_testing = getter; |
4651 } | 4722 } |
4652 | 4723 |
4653 } // namespace gdata | 4724 } // namespace gdata |
OLD | NEW |