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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // Returns DriveIntegrationService instance, if Drive is enabled. | 102 // Returns DriveIntegrationService instance, if Drive is enabled. |
103 // Otherwise, NULL. | 103 // Otherwise, NULL. |
104 DriveIntegrationService* GetIntegrationServiceByProfile(Profile* profile) { | 104 DriveIntegrationService* GetIntegrationServiceByProfile(Profile* profile) { |
105 DriveIntegrationService* service = | 105 DriveIntegrationService* service = |
106 DriveIntegrationServiceFactory::FindForProfile(profile); | 106 DriveIntegrationServiceFactory::FindForProfile(profile); |
107 if (!service || !service->IsMounted()) | 107 if (!service || !service->IsMounted()) |
108 return NULL; | 108 return NULL; |
109 return service; | 109 return service; |
110 } | 110 } |
111 | 111 |
| 112 void CheckDirectoryExistsAfterGetResourceEntry( |
| 113 const FileOperationCallback& callback, |
| 114 FileError error, |
| 115 scoped_ptr<ResourceEntry> entry) { |
| 116 if (error == FILE_ERROR_OK && !entry->file_info().is_directory()) |
| 117 error = FILE_ERROR_NOT_A_DIRECTORY; |
| 118 callback.Run(error); |
| 119 } |
| 120 |
112 } // namespace | 121 } // namespace |
113 | 122 |
114 const base::FilePath& GetDriveGrandRootPath() { | 123 const base::FilePath& GetDriveGrandRootPath() { |
115 CR_DEFINE_STATIC_LOCAL(base::FilePath, grand_root_path, | 124 CR_DEFINE_STATIC_LOCAL(base::FilePath, grand_root_path, |
116 (util::kDriveGrandRootDirName)); | 125 (util::kDriveGrandRootDirName)); |
117 return grand_root_path; | 126 return grand_root_path; |
118 } | 127 } |
119 | 128 |
120 const base::FilePath& GetDriveMyDriveRootPath() { | 129 const base::FilePath& GetDriveMyDriveRootPath() { |
121 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_root_path, | 130 CR_DEFINE_STATIC_LOCAL(base::FilePath, drive_root_path, |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 ExtractDrivePath(directory), | 345 ExtractDrivePath(directory), |
337 true /* is_exclusive */, | 346 true /* is_exclusive */, |
338 true /* is_recursive */, | 347 true /* is_recursive */, |
339 callback); | 348 callback); |
340 } else { | 349 } else { |
341 base::MessageLoopProxy::current()->PostTask( | 350 base::MessageLoopProxy::current()->PostTask( |
342 FROM_HERE, base::Bind(callback, FILE_ERROR_OK)); | 351 FROM_HERE, base::Bind(callback, FILE_ERROR_OK)); |
343 } | 352 } |
344 } | 353 } |
345 | 354 |
| 355 void CheckDirectoryExists(Profile* profile, |
| 356 const base::FilePath& directory, |
| 357 const FileOperationCallback& callback) { |
| 358 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 359 DCHECK(!callback.is_null()); |
| 360 |
| 361 FileSystemInterface* file_system = GetFileSystemByProfile(profile); |
| 362 DCHECK(file_system); |
| 363 |
| 364 file_system->GetResourceEntry( |
| 365 ExtractDrivePath(directory), |
| 366 base::Bind(&CheckDirectoryExistsAfterGetResourceEntry, callback)); |
| 367 } |
| 368 |
346 void EmptyFileOperationCallback(FileError error) { | 369 void EmptyFileOperationCallback(FileError error) { |
347 } | 370 } |
348 | 371 |
349 bool CreateGDocFile(const base::FilePath& file_path, | 372 bool CreateGDocFile(const base::FilePath& file_path, |
350 const GURL& url, | 373 const GURL& url, |
351 const std::string& resource_id) { | 374 const std::string& resource_id) { |
352 std::string content = base::StringPrintf( | 375 std::string content = base::StringPrintf( |
353 "{\"url\": \"%s\", \"resource_id\": \"%s\"}", | 376 "{\"url\": \"%s\", \"resource_id\": \"%s\"}", |
354 url.spec().c_str(), resource_id.c_str()); | 377 url.spec().c_str(), resource_id.c_str()); |
355 return file_util::WriteFile(file_path, content.data(), content.size()) == | 378 return file_util::WriteFile(file_path, content.data(), content.size()) == |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 const bool disable_sync_over_celluar = | 424 const bool disable_sync_over_celluar = |
402 profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular); | 425 profile->GetPrefs()->GetBoolean(prefs::kDisableDriveOverCellular); |
403 | 426 |
404 if (is_connection_cellular && disable_sync_over_celluar) | 427 if (is_connection_cellular && disable_sync_over_celluar) |
405 return DRIVE_CONNECTED_METERED; | 428 return DRIVE_CONNECTED_METERED; |
406 return DRIVE_CONNECTED; | 429 return DRIVE_CONNECTED; |
407 } | 430 } |
408 | 431 |
409 } // namespace util | 432 } // namespace util |
410 } // namespace drive | 433 } // namespace drive |
OLD | NEW |