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/drive_file_system_util.h" | 5 #include "chrome/browser/chromeos/gdata/drive_file_system_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 19 matching lines...) Expand all Loading... |
30 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
31 #include "net/base/escape.h" | 31 #include "net/base/escape.h" |
32 | 32 |
33 using content::BrowserThread; | 33 using content::BrowserThread; |
34 | 34 |
35 namespace gdata { | 35 namespace gdata { |
36 namespace util { | 36 namespace util { |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 const char kGDataSpecialRootPath[] = "/special"; | 40 const char kDriveSpecialRootPath[] = "/special"; |
41 | 41 |
42 const char kGDataMountPointPath[] = "/special/drive"; | 42 const char kDriveMountPointPath[] = "/special/drive"; |
43 | 43 |
44 const FilePath::CharType* kGDataMountPointPathComponents[] = { | 44 const FilePath::CharType* kDriveMountPointPathComponents[] = { |
45 "/", "special", "drive" | 45 "/", "special", "drive" |
46 }; | 46 }; |
47 | 47 |
48 const int kReadOnlyFilePermissions = base::PLATFORM_FILE_OPEN | | 48 const int kReadOnlyFilePermissions = base::PLATFORM_FILE_OPEN | |
49 base::PLATFORM_FILE_READ | | 49 base::PLATFORM_FILE_READ | |
50 base::PLATFORM_FILE_EXCLUSIVE_READ | | 50 base::PLATFORM_FILE_EXCLUSIVE_READ | |
51 base::PLATFORM_FILE_ASYNC; | 51 base::PLATFORM_FILE_ASYNC; |
52 | 52 |
53 DriveFileSystemInterface* GetDriveFileSystem(Profile* profile) { | 53 DriveFileSystemInterface* GetDriveFileSystem(Profile* profile) { |
54 DriveSystemService* system_service = | 54 DriveSystemService* system_service = |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 void OpenEditURLUIThread(Profile* profile, const GURL* edit_url) { | 94 void OpenEditURLUIThread(Profile* profile, const GURL* edit_url) { |
95 Browser* browser = browser::FindLastActiveWithProfile(profile); | 95 Browser* browser = browser::FindLastActiveWithProfile(profile); |
96 if (browser) { | 96 if (browser) { |
97 browser->OpenURL(content::OpenURLParams(*edit_url, content::Referrer(), | 97 browser->OpenURL(content::OpenURLParams(*edit_url, content::Referrer(), |
98 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); | 98 CURRENT_TAB, content::PAGE_TRANSITION_TYPED, false)); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 // Invoked upon completion of GetEntryInfoByResourceId initiated by | 102 // Invoked upon completion of GetEntryInfoByResourceId initiated by |
103 // ModifyGDataFileResourceUrl. | 103 // ModifyDriveFileResourceUrl. |
104 void OnGetEntryInfoByResourceId(Profile* profile, | 104 void OnGetEntryInfoByResourceId(Profile* profile, |
105 const std::string& resource_id, | 105 const std::string& resource_id, |
106 DriveFileError error, | 106 DriveFileError error, |
107 const FilePath& /* gdata_file_path */, | 107 const FilePath& /* gdata_file_path */, |
108 scoped_ptr<DriveEntryProto> entry_proto) { | 108 scoped_ptr<DriveEntryProto> entry_proto) { |
109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
110 | 110 |
111 if (error != DRIVE_FILE_OK) | 111 if (error != DRIVE_FILE_OK) |
112 return; | 112 return; |
113 | 113 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 cache->GetCacheFilePath(resource_id, file_md5, | 168 cache->GetCacheFilePath(resource_id, file_md5, |
169 DriveCache::CACHE_TYPE_TMP, | 169 DriveCache::CACHE_TYPE_TMP, |
170 DriveCache::CACHED_FILE_FROM_SERVER), | 170 DriveCache::CACHED_FILE_FROM_SERVER), |
171 kReadOnlyFilePermissions)); | 171 kReadOnlyFilePermissions)); |
172 | 172 |
173 callback.Run(); | 173 callback.Run(); |
174 } | 174 } |
175 | 175 |
176 } // namespace | 176 } // namespace |
177 | 177 |
178 const FilePath& GetGDataMountPointPath() { | 178 const FilePath& GetDriveMountPointPath() { |
179 CR_DEFINE_STATIC_LOCAL(FilePath, gdata_mount_path, | 179 CR_DEFINE_STATIC_LOCAL(FilePath, gdata_mount_path, |
180 (FilePath::FromUTF8Unsafe(kGDataMountPointPath))); | 180 (FilePath::FromUTF8Unsafe(kDriveMountPointPath))); |
181 return gdata_mount_path; | 181 return gdata_mount_path; |
182 } | 182 } |
183 | 183 |
184 const std::string& GetGDataMountPointPathAsString() { | 184 const std::string& GetDriveMountPointPathAsString() { |
185 CR_DEFINE_STATIC_LOCAL(std::string, gdata_mount_path_string, | 185 CR_DEFINE_STATIC_LOCAL(std::string, gdata_mount_path_string, |
186 (kGDataMountPointPath)); | 186 (kDriveMountPointPath)); |
187 return gdata_mount_path_string; | 187 return gdata_mount_path_string; |
188 } | 188 } |
189 | 189 |
190 const FilePath& GetSpecialRemoteRootPath() { | 190 const FilePath& GetSpecialRemoteRootPath() { |
191 CR_DEFINE_STATIC_LOCAL(FilePath, gdata_mount_path, | 191 CR_DEFINE_STATIC_LOCAL(FilePath, gdata_mount_path, |
192 (FilePath::FromUTF8Unsafe(kGDataSpecialRootPath))); | 192 (FilePath::FromUTF8Unsafe(kDriveSpecialRootPath))); |
193 return gdata_mount_path; | 193 return gdata_mount_path; |
194 } | 194 } |
195 | 195 |
196 GURL GetFileResourceUrl(const std::string& resource_id, | 196 GURL GetFileResourceUrl(const std::string& resource_id, |
197 const std::string& file_name) { | 197 const std::string& file_name) { |
198 std::string url(base::StringPrintf( | 198 std::string url(base::StringPrintf( |
199 "%s:%s", | 199 "%s:%s", |
200 chrome::kDriveScheme, | 200 chrome::kDriveScheme, |
201 net::EscapePath(resource_id).c_str())); | 201 net::EscapePath(resource_id).c_str())); |
202 return GURL(url); | 202 return GURL(url); |
203 } | 203 } |
204 | 204 |
205 void ModifyGDataFileResourceUrl(Profile* profile, | 205 void ModifyDriveFileResourceUrl(Profile* profile, |
206 const FilePath& drive_cache_path, | 206 const FilePath& drive_cache_path, |
207 GURL* url) { | 207 GURL* url) { |
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
209 | 209 |
210 DriveFileSystemInterface* file_system = GetDriveFileSystem(profile); | 210 DriveFileSystemInterface* file_system = GetDriveFileSystem(profile); |
211 if (!file_system) | 211 if (!file_system) |
212 return; | 212 return; |
213 DriveCache* cache = GetDriveCache(profile); | 213 DriveCache* cache = GetDriveCache(profile); |
214 if (!cache) | 214 if (!cache) |
215 return; | 215 return; |
(...skipping 17 matching lines...) Expand all Loading... |
233 drive_cache_path.BaseName().RemoveExtension().AsUTF8Unsafe(); | 233 drive_cache_path.BaseName().RemoveExtension().AsUTF8Unsafe(); |
234 file_system->GetEntryInfoByResourceId( | 234 file_system->GetEntryInfoByResourceId( |
235 resource_id, | 235 resource_id, |
236 base::Bind(&OnGetEntryInfoByResourceId, | 236 base::Bind(&OnGetEntryInfoByResourceId, |
237 profile, | 237 profile, |
238 resource_id)); | 238 resource_id)); |
239 *url = GURL(); | 239 *url = GURL(); |
240 } | 240 } |
241 } | 241 } |
242 | 242 |
243 bool IsUnderGDataMountPoint(const FilePath& path) { | 243 bool IsUnderDriveMountPoint(const FilePath& path) { |
244 return GetGDataMountPointPath() == path || | 244 return GetDriveMountPointPath() == path || |
245 GetGDataMountPointPath().IsParent(path); | 245 GetDriveMountPointPath().IsParent(path); |
246 } | 246 } |
247 | 247 |
248 FilePath ExtractGDataPath(const FilePath& path) { | 248 FilePath ExtractDrivePath(const FilePath& path) { |
249 if (!IsUnderGDataMountPoint(path)) | 249 if (!IsUnderDriveMountPoint(path)) |
250 return FilePath(); | 250 return FilePath(); |
251 | 251 |
252 std::vector<FilePath::StringType> components; | 252 std::vector<FilePath::StringType> components; |
253 path.GetComponents(&components); | 253 path.GetComponents(&components); |
254 | 254 |
255 // -1 to include 'drive'. | 255 // -1 to include 'drive'. |
256 FilePath extracted; | 256 FilePath extracted; |
257 for (size_t i = arraysize(kGDataMountPointPathComponents) - 1; | 257 for (size_t i = arraysize(kDriveMountPointPathComponents) - 1; |
258 i < components.size(); ++i) { | 258 i < components.size(); ++i) { |
259 extracted = extracted.Append(components[i]); | 259 extracted = extracted.Append(components[i]); |
260 } | 260 } |
261 return extracted; | 261 return extracted; |
262 } | 262 } |
263 | 263 |
264 void InsertDriveCachePathsPermissions( | 264 void InsertDriveCachePathsPermissions( |
265 Profile* profile, | 265 Profile* profile, |
266 scoped_ptr<std::vector<FilePath> > gdata_paths, | 266 scoped_ptr<std::vector<FilePath> > gdata_paths, |
267 std::vector<std::pair<FilePath, int> >* cache_paths, | 267 std::vector<std::pair<FilePath, int> >* cache_paths, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : | 359 *md5 = (extension_count > 0) ? extensions[extension_count - 1] : |
360 std::string(); | 360 std::string(); |
361 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : | 361 *extra_extension = (extension_count > 1) ? extensions[extension_count - 2] : |
362 std::string(); | 362 std::string(); |
363 } | 363 } |
364 | 364 |
365 void PrepareWritableFileAndRun(Profile* profile, | 365 void PrepareWritableFileAndRun(Profile* profile, |
366 const FilePath& path, | 366 const FilePath& path, |
367 const OpenFileCallback& callback) { | 367 const OpenFileCallback& callback) { |
368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
369 if (IsUnderGDataMountPoint(path)) { | 369 if (IsUnderDriveMountPoint(path)) { |
370 FileWriteHelper* file_write_helper = GetFileWriteHelper(profile); | 370 FileWriteHelper* file_write_helper = GetFileWriteHelper(profile); |
371 if (!file_write_helper) | 371 if (!file_write_helper) |
372 return; | 372 return; |
373 FilePath remote_path(ExtractGDataPath(path)); | 373 FilePath remote_path(ExtractDrivePath(path)); |
374 file_write_helper->PrepareWritableFileAndRun(remote_path, callback); | 374 file_write_helper->PrepareWritableFileAndRun(remote_path, callback); |
375 } else { | 375 } else { |
376 if (!callback.is_null()) { | 376 if (!callback.is_null()) { |
377 content::BrowserThread::GetBlockingPool()->PostTask( | 377 content::BrowserThread::GetBlockingPool()->PostTask( |
378 FROM_HERE, base::Bind(callback, DRIVE_FILE_OK, path)); | 378 FROM_HERE, base::Bind(callback, DRIVE_FILE_OK, path)); |
379 } | 379 } |
380 } | 380 } |
381 } | 381 } |
382 | 382 |
383 DriveFileError GDataToDriveFileError(GDataErrorCode status) { | 383 DriveFileError GDataToDriveFileError(GDataErrorCode status) { |
(...skipping 11 matching lines...) Expand all Loading... |
395 return DRIVE_FILE_ERROR_ABORT; | 395 return DRIVE_FILE_ERROR_ABORT; |
396 case GDATA_NO_CONNECTION: | 396 case GDATA_NO_CONNECTION: |
397 return DRIVE_FILE_ERROR_NO_CONNECTION; | 397 return DRIVE_FILE_ERROR_NO_CONNECTION; |
398 default: | 398 default: |
399 return DRIVE_FILE_ERROR_FAILED; | 399 return DRIVE_FILE_ERROR_FAILED; |
400 } | 400 } |
401 } | 401 } |
402 | 402 |
403 } // namespace util | 403 } // namespace util |
404 } // namespace gdata | 404 } // namespace gdata |
OLD | NEW |