| 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/drive/file_system_util.h" | 5 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 const char kSlash[] = "/"; | 44 const char kSlash[] = "/"; |
| 45 const char kEscapedSlash[] = "\xE2\x88\x95"; | 45 const char kEscapedSlash[] = "\xE2\x88\x95"; |
| 46 | 46 |
| 47 const int kReadOnlyFilePermissions = base::PLATFORM_FILE_OPEN | | 47 const int kReadOnlyFilePermissions = base::PLATFORM_FILE_OPEN | |
| 48 base::PLATFORM_FILE_READ | | 48 base::PLATFORM_FILE_READ | |
| 49 base::PLATFORM_FILE_EXCLUSIVE_READ | | 49 base::PLATFORM_FILE_EXCLUSIVE_READ | |
| 50 base::PLATFORM_FILE_ASYNC; | 50 base::PLATFORM_FILE_ASYNC; |
| 51 | 51 |
| 52 DriveFileSystemInterface* GetDriveFileSystem(Profile* profile) { | 52 DriveFileSystemInterface* GetFileSystem(Profile* profile) { |
| 53 DriveSystemService* system_service = | 53 DriveSystemService* system_service = |
| 54 DriveSystemServiceFactory::GetForProfile(profile); | 54 DriveSystemServiceFactory::GetForProfile(profile); |
| 55 return system_service ? system_service->file_system() : NULL; | 55 return system_service ? system_service->file_system() : NULL; |
| 56 } | 56 } |
| 57 | 57 |
| 58 FileWriteHelper* GetFileWriteHelper(Profile* profile) { | 58 FileWriteHelper* GetFileWriteHelper(Profile* profile) { |
| 59 DriveSystemService* system_service = | 59 DriveSystemService* system_service = |
| 60 DriveSystemServiceFactory::GetForProfile(profile); | 60 DriveSystemServiceFactory::GetForProfile(profile); |
| 61 return system_service ? system_service->file_write_helper() : NULL; | 61 return system_service ? system_service->file_write_helper() : NULL; |
| 62 } | 62 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 url.path(), net::UnescapeRule::NORMAL); | 143 url.path(), net::UnescapeRule::NORMAL); |
| 144 return base::FilePath::FromUTF8Unsafe(path_string); | 144 return base::FilePath::FromUTF8Unsafe(path_string); |
| 145 } | 145 } |
| 146 | 146 |
| 147 void MaybeSetDriveURL(Profile* profile, const base::FilePath& path, GURL* url) { | 147 void MaybeSetDriveURL(Profile* profile, const base::FilePath& path, GURL* url) { |
| 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 149 | 149 |
| 150 if (!IsUnderDriveMountPoint(path)) | 150 if (!IsUnderDriveMountPoint(path)) |
| 151 return; | 151 return; |
| 152 | 152 |
| 153 DriveFileSystemInterface* file_system = GetDriveFileSystem(profile); | 153 DriveFileSystemInterface* file_system = GetFileSystem(profile); |
| 154 if (!file_system) | 154 if (!file_system) |
| 155 return; | 155 return; |
| 156 | 156 |
| 157 *url = FilePathToDriveURL(util::ExtractDrivePath(path)); | 157 *url = FilePathToDriveURL(util::ExtractDrivePath(path)); |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool IsUnderDriveMountPoint(const base::FilePath& path) { | 160 bool IsUnderDriveMountPoint(const base::FilePath& path) { |
| 161 return GetDriveMountPointPath() == path || | 161 return GetDriveMountPointPath() == path || |
| 162 GetDriveMountPointPath().IsParent(path); | 162 GetDriveMountPointPath().IsParent(path); |
| 163 } | 163 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 | 307 |
| 308 void EnsureDirectoryExists(Profile* profile, | 308 void EnsureDirectoryExists(Profile* profile, |
| 309 const base::FilePath& directory, | 309 const base::FilePath& directory, |
| 310 const FileOperationCallback& callback) { | 310 const FileOperationCallback& callback) { |
| 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
| 312 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 312 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 313 DCHECK(!callback.is_null()); | 313 DCHECK(!callback.is_null()); |
| 314 if (IsUnderDriveMountPoint(directory)) { | 314 if (IsUnderDriveMountPoint(directory)) { |
| 315 DriveFileSystemInterface* file_system = GetDriveFileSystem(profile); | 315 DriveFileSystemInterface* file_system = GetFileSystem(profile); |
| 316 DCHECK(file_system); | 316 DCHECK(file_system); |
| 317 file_system->CreateDirectory( | 317 file_system->CreateDirectory( |
| 318 ExtractDrivePath(directory), | 318 ExtractDrivePath(directory), |
| 319 true /* is_exclusive */, | 319 true /* is_exclusive */, |
| 320 true /* is_recursive */, | 320 true /* is_recursive */, |
| 321 callback); | 321 callback); |
| 322 } else { | 322 } else { |
| 323 base::MessageLoopProxy::current()->PostTask( | 323 base::MessageLoopProxy::current()->PostTask( |
| 324 FROM_HERE, base::Bind(callback, FILE_ERROR_OK)); | 324 FROM_HERE, base::Bind(callback, FILE_ERROR_OK)); |
| 325 } | 325 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 proto->set_last_modified(file_info.last_modified.ToInternalValue()); | 370 proto->set_last_modified(file_info.last_modified.ToInternalValue()); |
| 371 proto->set_last_accessed(file_info.last_accessed.ToInternalValue()); | 371 proto->set_last_accessed(file_info.last_accessed.ToInternalValue()); |
| 372 proto->set_creation_time(file_info.creation_time.ToInternalValue()); | 372 proto->set_creation_time(file_info.creation_time.ToInternalValue()); |
| 373 } | 373 } |
| 374 | 374 |
| 375 void EmptyFileOperationCallback(FileError error) { | 375 void EmptyFileOperationCallback(FileError error) { |
| 376 } | 376 } |
| 377 | 377 |
| 378 } // namespace util | 378 } // namespace util |
| 379 } // namespace drive | 379 } // namespace drive |
| OLD | NEW |