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_util.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 kReadOnlyFilePermissions)); | 139 kReadOnlyFilePermissions)); |
140 cache_paths->push_back(std::make_pair( | 140 cache_paths->push_back(std::make_pair( |
141 file_system->GetCacheFilePath(resource_id, file_md5, | 141 file_system->GetCacheFilePath(resource_id, file_md5, |
142 GDataCache::CACHE_TYPE_TMP, | 142 GDataCache::CACHE_TYPE_TMP, |
143 GDataCache::CACHED_FILE_FROM_SERVER), | 143 GDataCache::CACHED_FILE_FROM_SERVER), |
144 kReadOnlyFilePermissions)); | 144 kReadOnlyFilePermissions)); |
145 | 145 |
146 callback.Run(); | 146 callback.Run(); |
147 } | 147 } |
148 | 148 |
149 // Invoked upon completeion of FindEntryByResourceIdAsync initiated by | |
achuithb
2012/06/11 20:46:37
completion
hshi1
2012/06/11 20:58:51
Done.
| |
150 // ModifyGDataFileResourceUrl. | |
151 void OnFindEntryByResourceIdAsync(Profile* profile, | |
152 const std::string& resource_id, | |
153 base::PlatformFileError error, | |
154 GDataEntry* entry) { | |
155 if (error != base::PLATFORM_FILE_OK || !entry || !entry->AsGDataFile()) | |
156 return; | |
157 | |
158 std::string file_name = entry->AsGDataFile()->file_name(); | |
159 GURL edit_url = GetFileResourceUrl(resource_id, file_name); | |
160 OpenEditURLUIThread(profile, &edit_url); | |
161 DVLOG(1) << "OnFindEntryByResourceIdAsync " << edit_url; | |
162 } | |
163 | |
149 } // namespace | 164 } // namespace |
150 | 165 |
151 const FilePath& GetGDataMountPointPath() { | 166 const FilePath& GetGDataMountPointPath() { |
152 CR_DEFINE_STATIC_LOCAL(FilePath, gdata_mount_path, | 167 CR_DEFINE_STATIC_LOCAL(FilePath, gdata_mount_path, |
153 (FilePath::FromUTF8Unsafe(kGDataMountPointPath))); | 168 (FilePath::FromUTF8Unsafe(kGDataMountPointPath))); |
154 return gdata_mount_path; | 169 return gdata_mount_path; |
155 } | 170 } |
156 | 171 |
157 const std::string& GetGDataMountPointPathAsString() { | 172 const std::string& GetGDataMountPointPathAsString() { |
158 CR_DEFINE_STATIC_LOCAL(std::string, gdata_mount_path_string, | 173 CR_DEFINE_STATIC_LOCAL(std::string, gdata_mount_path_string, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 base::Bind(&OpenEditURLUIThread, profile, base::Owned(edit_url))); | 209 base::Bind(&OpenEditURLUIThread, profile, base::Owned(edit_url))); |
195 *url = GURL(); | 210 *url = GURL(); |
196 return; | 211 return; |
197 } | 212 } |
198 | 213 |
199 // Handle all other gdata files. | 214 // Handle all other gdata files. |
200 if (file_system->GetCacheDirectoryPath( | 215 if (file_system->GetCacheDirectoryPath( |
201 GDataCache::CACHE_TYPE_TMP).IsParent(gdata_cache_path)) { | 216 GDataCache::CACHE_TYPE_TMP).IsParent(gdata_cache_path)) { |
202 const std::string resource_id = | 217 const std::string resource_id = |
203 gdata_cache_path.BaseName().RemoveExtension().AsUTF8Unsafe(); | 218 gdata_cache_path.BaseName().RemoveExtension().AsUTF8Unsafe(); |
204 GDataEntry* entry = NULL; | 219 file_system->FindEntryByResourceIdAsync(resource_id, |
205 file_system->FindEntryByResourceIdSync( | 220 base::Bind( |
206 resource_id, base::Bind(&ReadOnlyFindEntryCallback, &entry)); | 221 &OnFindEntryByResourceIdAsync, |
207 | 222 profile, |
208 std::string file_name; | 223 resource_id)); |
209 if (entry && entry->AsGDataFile()) | 224 *url = GURL(); |
210 file_name = entry->AsGDataFile()->file_name(); | 225 return; |
211 | |
212 *url = gdata::util::GetFileResourceUrl(resource_id, file_name); | |
213 DVLOG(1) << "ModifyGDataFileResourceUrl " << *url; | |
214 } | 226 } |
215 } | 227 } |
216 | 228 |
217 bool IsUnderGDataMountPoint(const FilePath& path) { | 229 bool IsUnderGDataMountPoint(const FilePath& path) { |
218 return GetGDataMountPointPath() == path || | 230 return GetGDataMountPointPath() == path || |
219 GetGDataMountPointPath().IsParent(path); | 231 GetGDataMountPointPath().IsParent(path); |
220 } | 232 } |
221 | 233 |
222 GDataSearchPathType GetSearchPathStatus(const FilePath& path) { | 234 GDataSearchPathType GetSearchPathStatus(const FilePath& path) { |
223 std::vector<std::string> components; | 235 std::vector<std::string> components; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
397 // Assign the extracted extensions to md5 and extra_extension. | 409 // Assign the extracted extensions to md5 and extra_extension. |
398 int extension_count = extensions.size(); | 410 int extension_count = extensions.size(); |
399 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : | 411 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : |
400 std::string(); | 412 std::string(); |
401 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : | 413 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : |
402 std::string(); | 414 std::string(); |
403 } | 415 } |
404 | 416 |
405 } // namespace util | 417 } // namespace util |
406 } // namespace gdata | 418 } // namespace gdata |
OLD | NEW |