Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Side by Side Diff: components/drive/chromeos/file_cache.cc

Issue 2416093003: Fixed the bug that Drive doesn't appear on Files App on epehmeral mode. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "components/drive/chromeos/file_cache.h" 5 #include "components/drive/chromeos/file_cache.h"
6 6
7 #include <linux/fs.h> 7 #include <linux/fs.h>
8 #include <sys/ioctl.h> 8 #include <sys/ioctl.h>
9 #include <sys/xattr.h> 9 #include <sys/xattr.h>
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 std::string GetIdFromPath(const base::FilePath& path) { 45 std::string GetIdFromPath(const base::FilePath& path) {
46 return util::UnescapeCacheFileName(path.BaseName().AsUTF8Unsafe()); 46 return util::UnescapeCacheFileName(path.BaseName().AsUTF8Unsafe());
47 } 47 }
48 48
49 base::FilePath GetPathForId(const base::FilePath& cache_directory, 49 base::FilePath GetPathForId(const base::FilePath& cache_directory,
50 const std::string& id) { 50 const std::string& id) {
51 return cache_directory.Append( 51 return cache_directory.Append(
52 base::FilePath::FromUTF8Unsafe(util::EscapeCacheFileName(id))); 52 base::FilePath::FromUTF8Unsafe(util::EscapeCacheFileName(id)));
53 } 53 }
54 54
55 // Returns if the filesystem backing |path| supports file attributes.
56 // This will return false if the filesystem is for example tmpfs, which is used
57 // for ephemeral mode.
58 bool IsFileAttributesSupported(const base::FilePath& path) {
59 if (getxattr(path.value().c_str(), "user.foo", nullptr, 0) >= 0) {
60 return true;
61 }
62 return errno != ENOTSUP;
63 }
64
55 // Sets extended file attribute as |name| |value| pair. 65 // Sets extended file attribute as |name| |value| pair.
56 bool SetExtendedFileAttributes(const base::FilePath& path, 66 bool SetExtendedFileAttributes(const base::FilePath& path,
57 const std::string& name, const std::string& value) { 67 const std::string& name, const std::string& value) {
58 return setxattr(path.value().c_str(), name.c_str(), value.c_str(), 68 return setxattr(path.value().c_str(), name.c_str(), value.c_str(),
59 value.size() + 1, 0) == 0; 69 value.size() + 1, 0) == 0;
60 } 70 }
61 71
62 // Changes attributes of the file with |flags|, e.g. FS_NODUMP_FL (cryptohome 72 // Changes attributes of the file with |flags|, e.g. FS_NODUMP_FL (cryptohome
63 // will remove Drive caches with this attribute). 73 // will remove Drive caches with this attribute).
64 // See linux/fs.h for available flags, and chattr(1) which does similar thing. 74 // See linux/fs.h for available flags, and chattr(1) which does similar thing.
(...skipping 20 matching lines...) Expand all
85 return -1; 95 return -1;
86 } 96 }
87 FileAttributes flags = 0; 97 FileAttributes flags = 0;
88 if (ioctl(file.GetPlatformFile(), FS_IOC_GETFLAGS, &flags) < 0) { 98 if (ioctl(file.GetPlatformFile(), FS_IOC_GETFLAGS, &flags) < 0) {
89 PLOG(ERROR) << "ioctl: " << path.value(); 99 PLOG(ERROR) << "ioctl: " << path.value();
90 return -1; 100 return -1;
91 } 101 }
92 return flags; 102 return flags;
93 } 103 }
94 104
95 // Marks the cache file to be removable by cryptohome. 105 // Marks the cache file to be removable by cryptohome, or do nothing if
106 // underlying filesystem doesn't support file attributes, as tmpfs for ephemeral
107 // mode.
96 bool SetRemovable(const base::FilePath& path) { 108 bool SetRemovable(const base::FilePath& path) {
109 // For ephemeral mode.
110 if (!IsFileAttributesSupported(path)) {
111 return true;
112 }
97 FileAttributes flags = GetFileAttributes(path); 113 FileAttributes flags = GetFileAttributes(path);
98 if (flags < 0) return false; 114 if (flags < 0) return false;
99 if ((flags & FS_NODUMP_FL) == FS_NODUMP_FL) return true; 115 if ((flags & FS_NODUMP_FL) == FS_NODUMP_FL) return true;
100 116
101 return SetFileAttributes(path, flags | FS_NODUMP_FL); 117 return SetFileAttributes(path, flags | FS_NODUMP_FL);
102 } 118 }
103 119
104 // Marks the cache file to be unremovable by cryptohome. 120 // Marks the cache file to be unremovable by cryptohome, or do nothing if
121 // underlying filesystem doesn't support file attributes, as tmpfs for ephemeral
122 // mode.
105 bool UnsetRemovable(const base::FilePath& path) { 123 bool UnsetRemovable(const base::FilePath& path) {
124 // For ephemeral mode.
125 if (!IsFileAttributesSupported(path)) {
126 return true;
127 }
106 FileAttributes flags = GetFileAttributes(path); 128 FileAttributes flags = GetFileAttributes(path);
107 if (flags < 0) return false; 129 if (flags < 0) return false;
108 if ((flags & FS_NODUMP_FL) == 0) return true; 130 if ((flags & FS_NODUMP_FL) == 0) return true;
109 131
110 return SetFileAttributes(path, flags & ~FS_NODUMP_FL); 132 return SetFileAttributes(path, flags & ~FS_NODUMP_FL);
111 } 133 }
112 134
113 // Marks |path| as drive cache dir. 135 // Marks |path| as drive cache dir, or do nothing if underlying filesystem
114 // Returns if the operation succeeded. 136 // doesn't support file attributes, as tmpfs for ephemeral mode. Returns if the
137 // operation succeeded.
115 bool MarkAsDriveCacheDir(const base::FilePath& path) { 138 bool MarkAsDriveCacheDir(const base::FilePath& path) {
139 // For ephemeral mode.
140 if (!IsFileAttributesSupported(path)) {
141 return true;
142 }
116 return SetRemovable(path) 143 return SetRemovable(path)
117 && SetExtendedFileAttributes(path, FileCache::kGCacheFilesAttribute, ""); 144 && SetExtendedFileAttributes(path, FileCache::kGCacheFilesAttribute, "");
118 } 145 }
119 146
120 class CacheInfoLatestCompare { 147 class CacheInfoLatestCompare {
121 public: 148 public:
122 bool operator()(const CacheInfo& info_a, const CacheInfo& info_b) { 149 bool operator()(const CacheInfo& info_a, const CacheInfo& info_b) {
123 return info_a.first.last_accessed < info_b.first.last_accessed; 150 return info_a.first.last_accessed < info_b.first.last_accessed;
124 } 151 }
125 }; 152 };
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 932
906 bool FileCache::IsEvictable(const std::string& id, const ResourceEntry& entry) { 933 bool FileCache::IsEvictable(const std::string& id, const ResourceEntry& entry) {
907 return IsPresent(entry) && 934 return IsPresent(entry) &&
908 !entry.file_specific_info().cache_state().is_pinned() && 935 !entry.file_specific_info().cache_state().is_pinned() &&
909 !entry.file_specific_info().cache_state().is_dirty() && 936 !entry.file_specific_info().cache_state().is_dirty() &&
910 !mounted_files_.count(id); 937 !mounted_files_.count(id);
911 } 938 }
912 939
913 } // namespace internal 940 } // namespace internal
914 } // namespace drive 941 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698