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