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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
409 } | 408 } |
410 } | 409 } |
411 | 410 |
412 // Recursively extracts the paths set of all sub-directories of |entry|. | 411 // Recursively extracts the paths set of all sub-directories of |entry|. |
413 void GetChildDirectoryPaths(GDataEntry* entry, | 412 void GetChildDirectoryPaths(GDataEntry* entry, |
414 std::set<FilePath>* changed_dirs) { | 413 std::set<FilePath>* changed_dirs) { |
415 GDataDirectory* dir = entry->AsGDataDirectory(); | 414 GDataDirectory* dir = entry->AsGDataDirectory(); |
416 if (!dir) | 415 if (!dir) |
417 return; | 416 return; |
418 | 417 |
419 for (GDataFileCollection::const_iterator it = dir->children().begin(); | 418 for (GDataDirectoryCollection::const_iterator it = |
420 it != dir->children().end(); ++it) { | 419 dir->child_directories().begin(); |
421 GDataDirectory* child_dir = it->second->AsGDataDirectory(); | 420 it != dir->child_directories().end(); ++it) { |
422 if (child_dir) { | 421 GDataDirectory* child_dir = it->second; |
423 changed_dirs->insert(child_dir->GetFilePath()); | 422 changed_dirs->insert(child_dir->GetFilePath()); |
424 GetChildDirectoryPaths(child_dir, changed_dirs); | 423 GetChildDirectoryPaths(child_dir, changed_dirs); |
425 } | |
426 } | 424 } |
427 } | 425 } |
428 | 426 |
429 | 427 |
430 // Helper function for removing |entry| from |directory|. If |entry| is a | 428 // Helper function for removing |entry| from |directory|. If |entry| is a |
431 // directory too, it will collect all its children file paths into | 429 // directory too, it will collect all its children file paths into |
432 // |changed_dirs| as well. | 430 // |changed_dirs| as well. |
433 void RemoveEntryFromDirectoryAndCollectChangedDirectories( | 431 void RemoveEntryFromDirectoryAndCollectChangedDirectories( |
434 GDataDirectory* directory, | 432 GDataDirectory* directory, |
435 GDataEntry* entry, | 433 GDataEntry* entry, |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
838 | 836 |
839 FilePath cache_base_path; | 837 FilePath cache_base_path; |
840 chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path); | 838 chrome::GetUserCacheDirectory(profile_->GetPath(), &cache_base_path); |
841 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname); | 839 gdata_cache_path_ = cache_base_path.Append(chrome::kGDataCacheDirname); |
842 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir); | 840 gdata_cache_path_ = gdata_cache_path_.Append(kGDataCacheVersionDir); |
843 SetCachePaths(gdata_cache_path_); | 841 SetCachePaths(gdata_cache_path_); |
844 | 842 |
845 documents_service_->Initialize(profile_); | 843 documents_service_->Initialize(profile_); |
846 | 844 |
847 root_.reset(new GDataRootDirectory); | 845 root_.reset(new GDataRootDirectory); |
848 root_->set_file_name(kGDataRootDirectory); | |
849 | 846 |
850 PrefService* pref_service = profile_->GetPrefs(); | 847 PrefService* pref_service = profile_->GetPrefs(); |
851 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); | 848 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); |
852 | 849 |
853 InitializePreferenceObserver(); | 850 InitializePreferenceObserver(); |
854 } | 851 } |
855 | 852 |
856 bool GDataFileSystem::SetCacheRootPathForTesting(const FilePath& root_path) { | 853 bool GDataFileSystem::SetCacheRootPathForTesting(const FilePath& root_path) { |
857 if (cache_initialization_started_) | 854 if (cache_initialization_started_) |
858 return false; | 855 return false; |
(...skipping 1688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2547 base::AutoLock lock(lock_); | 2544 base::AutoLock lock(lock_); |
2548 GDataEntry* entry = GetGDataEntryByPath(file_path); | 2545 GDataEntry* entry = GetGDataEntryByPath(file_path); |
2549 if (!entry) | 2546 if (!entry) |
2550 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 2547 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
2551 | 2548 |
2552 DCHECK(entry->parent()); | 2549 DCHECK(entry->parent()); |
2553 entry->set_title(new_name); | 2550 entry->set_title(new_name); |
2554 // After changing the title of the entry, call TakeFile() to remove the | 2551 // After changing the title of the entry, call TakeFile() to remove the |
2555 // entry from its parent directory and then add it back in order to go | 2552 // entry from its parent directory and then add it back in order to go |
2556 // through the file name de-duplication. | 2553 // through the file name de-duplication. |
2554 // TODO(achuith/satorux/zel): This code is fragile. The title has been | |
2555 // changed, but not the file_name. TakeEntry removes the child based on the | |
2556 // old file_name, and then re-adds the child by first assigning the new title | |
2557 // to file_name. | |
satorux1
2012/04/27 22:29:41
file a bug and add a URL?
achuithb
2012/04/27 22:43:22
Done.
| |
2557 if (!entry->parent()->TakeEntry(entry)) | 2558 if (!entry->parent()->TakeEntry(entry)) |
2558 return base::PLATFORM_FILE_ERROR_FAILED; | 2559 return base::PLATFORM_FILE_ERROR_FAILED; |
2559 | 2560 |
2560 *updated_file_path = entry->GetFilePath(); | 2561 *updated_file_path = entry->GetFilePath(); |
2561 | 2562 |
2562 NotifyDirectoryChanged(updated_file_path->DirName()); | 2563 NotifyDirectoryChanged(updated_file_path->DirName()); |
2563 return base::PLATFORM_FILE_OK; | 2564 return base::PLATFORM_FILE_OK; |
2564 } | 2565 } |
2565 | 2566 |
2566 base::PlatformFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( | 2567 base::PlatformFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( |
(...skipping 1700 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4267 pref_registrar_->Init(profile_->GetPrefs()); | 4268 pref_registrar_->Init(profile_->GetPrefs()); |
4268 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 4269 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
4269 } | 4270 } |
4270 | 4271 |
4271 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 4272 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
4272 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 4273 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
4273 global_free_disk_getter_for_testing = getter; | 4274 global_free_disk_getter_for_testing = getter; |
4274 } | 4275 } |
4275 | 4276 |
4276 } // namespace gdata | 4277 } // namespace gdata |
OLD | NEW |