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 completion of FindEntryByResourceId initiated by | |
150 // ModifyGDataFileResourceUrl. | |
151 void OnFindEntryByResourceId(Profile* profile, | |
achuithb
2012/06/11 21:48:41
Could we move this next to OpenEditURLUIThread? Th
hshi1
2012/06/11 22:42:21
Sounds reasonable, done.
On 2012/06/11 21:48:41,
| |
152 const std::string& resource_id, | |
achuithb
2012/06/11 21:48:41
indentation is off
hshi1
2012/06/11 22:42:21
Done.
| |
153 base::PlatformFileError error, | |
154 GDataEntry* entry) { | |
155 if (error != base::PLATFORM_FILE_OK || !entry || !entry->AsGDataFile()) | |
achuithb
2012/06/11 21:48:41
Could you please add a DCHECK for UI thread here?
hshi1
2012/06/11 22:42:21
Again, this is run on the CALLER thread, not on UI
achuithb
2012/06/11 22:56:11
Which I believe is the UI thread in this case, rig
hshi1
2012/06/11 23:17:52
Yes you're right. Done.
| |
156 return; | |
157 | |
158 std::string file_name = entry->AsGDataFile()->file_name(); | |
achuithb
2012/06/11 21:48:41
could we make this const?
hshi1
2012/06/11 22:42:21
Done.
| |
159 GURL edit_url = GetFileResourceUrl(resource_id, file_name); | |
achuithb
2012/06/11 21:48:41
could we make this const too? You may need to chan
hshi1
2012/06/11 22:42:21
If I declare the object as "const GURL edit_url" h
achuithb
2012/06/11 22:56:11
That's strange. It should be const GURL* since edi
hshi1
2012/06/11 23:17:52
Sorry I was mistaken. It should be "const GURL*".
| |
160 OpenEditURLUIThread(profile, &edit_url); | |
161 DVLOG(1) << "OnFindEntryByResourceId " << 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 12 matching lines...) Expand all Loading... | |
171 std::string url(base::StringPrintf( | 186 std::string url(base::StringPrintf( |
172 "%s:%s", | 187 "%s:%s", |
173 chrome::kDriveScheme, | 188 chrome::kDriveScheme, |
174 net::EscapePath(resource_id).c_str())); | 189 net::EscapePath(resource_id).c_str())); |
175 return GURL(url); | 190 return GURL(url); |
176 } | 191 } |
177 | 192 |
178 void ModifyGDataFileResourceUrl(Profile* profile, | 193 void ModifyGDataFileResourceUrl(Profile* profile, |
179 const FilePath& gdata_cache_path, | 194 const FilePath& gdata_cache_path, |
180 GURL* url) { | 195 GURL* url) { |
181 GDataFileSystem* file_system = GetGDataFileSystem(profile); | 196 GDataFileSystem* file_system = GetGDataFileSystem(profile); |
achuithb
2012/06/11 21:48:41
Could you please add a DCHECK for UI thread here?
hshi1
2012/06/11 22:42:21
Done.
| |
182 if (!file_system) | 197 if (!file_system) |
183 return; | 198 return; |
184 | 199 |
185 // Handle hosted documents. The edit url is in the temporary file, so we | 200 // Handle hosted documents. The edit url is in the temporary file, so we |
186 // read it on a blocking thread. | 201 // read it on a blocking thread. |
187 if (file_system->GetCacheDirectoryPath( | 202 if (file_system->GetCacheDirectoryPath( |
188 GDataCache::CACHE_TYPE_TMP_DOCUMENTS).IsParent( | 203 GDataCache::CACHE_TYPE_TMP_DOCUMENTS).IsParent( |
189 gdata_cache_path)) { | 204 gdata_cache_path)) { |
190 GURL* edit_url = new GURL(); | 205 GURL* edit_url = new GURL(); |
191 content::BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, | 206 content::BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, |
192 base::Bind(&GetHostedDocumentURLBlockingThread, | 207 base::Bind(&GetHostedDocumentURLBlockingThread, |
193 gdata_cache_path, edit_url), | 208 gdata_cache_path, edit_url), |
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; |
achuithb
2012/06/11 21:48:41
instead of this return, how about using an else in
hshi1
2012/06/11 22:42:21
Done.
| |
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->FindEntryByResourceId(resource_id, |
205 file_system->FindEntryByResourceIdSync( | 220 base::Bind(&OnFindEntryByResourceId, |
206 resource_id, base::Bind(&ReadOnlyFindEntryCallback, &entry)); | 221 profile, |
207 | 222 resource_id)); |
208 std::string file_name; | 223 *url = GURL(); |
209 if (entry && entry->AsGDataFile()) | 224 return; |
achuithb
2012/06/11 21:48:41
this return seems unnecessary
hshi1
2012/06/11 22:42:21
Done.
| |
210 file_name = entry->AsGDataFile()->file_name(); | |
211 | |
212 *url = gdata::util::GetFileResourceUrl(resource_id, file_name); | |
213 DVLOG(1) << "ModifyGDataFileResourceUrl " << *url; | |
214 } | 225 } |
215 } | 226 } |
216 | 227 |
217 bool IsUnderGDataMountPoint(const FilePath& path) { | 228 bool IsUnderGDataMountPoint(const FilePath& path) { |
218 return GetGDataMountPointPath() == path || | 229 return GetGDataMountPointPath() == path || |
219 GetGDataMountPointPath().IsParent(path); | 230 GetGDataMountPointPath().IsParent(path); |
220 } | 231 } |
221 | 232 |
222 GDataSearchPathType GetSearchPathStatus(const FilePath& path) { | 233 GDataSearchPathType GetSearchPathStatus(const FilePath& path) { |
223 std::vector<std::string> components; | 234 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. | 408 // Assign the extracted extensions to md5 and extra_extension. |
398 int extension_count = extensions.size(); | 409 int extension_count = extensions.size(); |
399 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : | 410 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : |
400 std::string(); | 411 std::string(); |
401 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : | 412 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : |
402 std::string(); | 413 std::string(); |
403 } | 414 } |
404 | 415 |
405 } // namespace util | 416 } // namespace util |
406 } // namespace gdata | 417 } // namespace gdata |
OLD | NEW |