| 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_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "net/url_request/url_request_filter.h" | 47 #include "net/url_request/url_request_filter.h" |
| 48 | 48 |
| 49 using content::BrowserThread; | 49 using content::BrowserThread; |
| 50 | 50 |
| 51 namespace gdata { | 51 namespace gdata { |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 const char kMimeTypeJson[] = "application/json"; | 54 const char kMimeTypeJson[] = "application/json"; |
| 55 const char kMimeTypeOctetStream[] = "application/octet-stream"; | 55 const char kMimeTypeOctetStream[] = "application/octet-stream"; |
| 56 | 56 |
| 57 const FilePath::CharType kGDataRootDirectory[] = FILE_PATH_LITERAL("gdata"); | |
| 58 const char kWildCard[] = "*"; | 57 const char kWildCard[] = "*"; |
| 59 const char kLocallyModifiedFileExtension[] = "local"; | 58 const char kLocallyModifiedFileExtension[] = "local"; |
| 60 const char kMountedArchiveFileExtension[] = "mounted"; | 59 const char kMountedArchiveFileExtension[] = "mounted"; |
| 61 | 60 |
| 62 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1"); | 61 const FilePath::CharType kGDataCacheVersionDir[] = FILE_PATH_LITERAL("v1"); |
| 63 const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta"); | 62 const FilePath::CharType kGDataCacheMetaDir[] = FILE_PATH_LITERAL("meta"); |
| 64 const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned"); | 63 const FilePath::CharType kGDataCachePinnedDir[] = FILE_PATH_LITERAL("pinned"); |
| 65 const FilePath::CharType kGDataCacheOutgoingDir[] = | 64 const FilePath::CharType kGDataCacheOutgoingDir[] = |
| 66 FILE_PATH_LITERAL("outgoing"); | 65 FILE_PATH_LITERAL("outgoing"); |
| 67 const FilePath::CharType kGDataCachePersistentDir[] = | 66 const FilePath::CharType kGDataCachePersistentDir[] = |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 } | 407 } |
| 409 } | 408 } |
| 410 | 409 |
| 411 // Recursively extracts the paths set of all sub-directories of |entry|. | 410 // Recursively extracts the paths set of all sub-directories of |entry|. |
| 412 void GetChildDirectoryPaths(GDataEntry* entry, | 411 void GetChildDirectoryPaths(GDataEntry* entry, |
| 413 std::set<FilePath>* changed_dirs) { | 412 std::set<FilePath>* changed_dirs) { |
| 414 GDataDirectory* dir = entry->AsGDataDirectory(); | 413 GDataDirectory* dir = entry->AsGDataDirectory(); |
| 415 if (!dir) | 414 if (!dir) |
| 416 return; | 415 return; |
| 417 | 416 |
| 418 for (GDataFileCollection::const_iterator it = dir->children().begin(); | 417 for (GDataDirectoryCollection::const_iterator it = |
| 419 it != dir->children().end(); ++it) { | 418 dir->child_directories().begin(); |
| 420 GDataDirectory* child_dir = it->second->AsGDataDirectory(); | 419 it != dir->child_directories().end(); ++it) { |
| 421 if (child_dir) { | 420 GDataDirectory* child_dir = it->second; |
| 422 changed_dirs->insert(child_dir->GetFilePath()); | 421 changed_dirs->insert(child_dir->GetFilePath()); |
| 423 GetChildDirectoryPaths(child_dir, changed_dirs); | 422 GetChildDirectoryPaths(child_dir, changed_dirs); |
| 424 } | |
| 425 } | 423 } |
| 426 } | 424 } |
| 427 | 425 |
| 428 | 426 |
| 429 // Helper function for removing |entry| from |directory|. If |entry| is a | 427 // Helper function for removing |entry| from |directory|. If |entry| is a |
| 430 // directory too, it will collect all its children file paths into | 428 // directory too, it will collect all its children file paths into |
| 431 // |changed_dirs| as well. | 429 // |changed_dirs| as well. |
| 432 void RemoveEntryFromDirectoryAndCollectChangedDirectories( | 430 void RemoveEntryFromDirectoryAndCollectChangedDirectories( |
| 433 GDataDirectory* directory, | 431 GDataDirectory* directory, |
| 434 GDataEntry* entry, | 432 GDataEntry* entry, |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 | 909 |
| 912 FilePath cache_base_path; | 910 FilePath cache_base_path; |
| 913 chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path); | 911 chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path); |
| 914 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname); | 912 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname); |
| 915 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir); | 913 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir); |
| 916 SetCachePaths(gdata_cache_path_); | 914 SetCachePaths(gdata_cache_path_); |
| 917 | 915 |
| 918 documents_service_->Initialize(profile_); | 916 documents_service_->Initialize(profile_); |
| 919 | 917 |
| 920 root_.reset(new GDataRootDirectory); | 918 root_.reset(new GDataRootDirectory); |
| 921 root_->set_file_name(kGDataRootDirectory); | |
| 922 | 919 |
| 923 PrefService* pref_service = profile_->GetPrefs(); | 920 PrefService* pref_service = profile_->GetPrefs(); |
| 924 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); | 921 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); |
| 925 | 922 |
| 926 InitializePreferenceObserver(); | 923 InitializePreferenceObserver(); |
| 927 } | 924 } |
| 928 | 925 |
| 929 bool GDataFileSystem::SetCacheRootPathForTesting(const FilePath& root_path) { | 926 bool GDataFileSystem::SetCacheRootPathForTesting(const FilePath& root_path) { |
| 930 if (cache_initialization_started_) | 927 if (cache_initialization_started_) |
| 931 return false; | 928 return false; |
| (...skipping 1936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2868 base::AutoLock lock(lock_); | 2865 base::AutoLock lock(lock_); |
| 2869 GDataEntry* entry = GetGDataEntryByPath(file_path); | 2866 GDataEntry* entry = GetGDataEntryByPath(file_path); |
| 2870 if (!entry) | 2867 if (!entry) |
| 2871 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 2868 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 2872 | 2869 |
| 2873 DCHECK(entry->parent()); | 2870 DCHECK(entry->parent()); |
| 2874 entry->set_title(new_name); | 2871 entry->set_title(new_name); |
| 2875 // After changing the title of the entry, call TakeFile() to remove the | 2872 // After changing the title of the entry, call TakeFile() to remove the |
| 2876 // entry from its parent directory and then add it back in order to go | 2873 // entry from its parent directory and then add it back in order to go |
| 2877 // through the file name de-duplication. | 2874 // through the file name de-duplication. |
| 2875 // TODO(achuith/satorux/zel): This code is fragile. The title has been |
| 2876 // changed, but not the file_name. TakeEntry removes the child based on the |
| 2877 // old file_name, and then re-adds the child by first assigning the new title |
| 2878 // to file_name. http://crbug.com/30157 |
| 2878 if (!entry->parent()->TakeEntry(entry)) | 2879 if (!entry->parent()->TakeEntry(entry)) |
| 2879 return base::PLATFORM_FILE_ERROR_FAILED; | 2880 return base::PLATFORM_FILE_ERROR_FAILED; |
| 2880 | 2881 |
| 2881 *updated_file_path = entry->GetFilePath(); | 2882 *updated_file_path = entry->GetFilePath(); |
| 2882 | 2883 |
| 2883 NotifyDirectoryChanged(updated_file_path->DirName()); | 2884 NotifyDirectoryChanged(updated_file_path->DirName()); |
| 2884 return base::PLATFORM_FILE_OK; | 2885 return base::PLATFORM_FILE_OK; |
| 2885 } | 2886 } |
| 2886 | 2887 |
| 2887 base::PlatformFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( | 2888 base::PlatformFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( |
| (...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4580 pref_registrar_->Init(profile_->GetPrefs()); | 4581 pref_registrar_->Init(profile_->GetPrefs()); |
| 4581 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 4582 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
| 4582 } | 4583 } |
| 4583 | 4584 |
| 4584 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 4585 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
| 4585 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 4586 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
| 4586 global_free_disk_getter_for_testing = getter; | 4587 global_free_disk_getter_for_testing = getter; |
| 4587 } | 4588 } |
| 4588 | 4589 |
| 4589 } // namespace gdata | 4590 } // namespace gdata |
| OLD | NEW |