| 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_util.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 13 #include "chrome/common/libxml_utils.h" | 14 #include "chrome/common/libxml_utils.h" |
| 15 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
| 16 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
| 17 #include "content/public/browser/child_process_security_policy.h" |
| 14 | 18 |
| 15 namespace gdata { | 19 namespace gdata { |
| 16 namespace util { | 20 namespace util { |
| 17 | 21 |
| 18 namespace { | 22 namespace { |
| 19 | 23 |
| 20 const char kGDataMountPointPath[] = "/special/gdata"; | 24 const char kGDataMountPointPath[] = "/special/gdata"; |
| 21 | 25 |
| 22 const FilePath::CharType* kGDataMountPointPathComponents[] = { | 26 const FilePath::CharType* kGDataMountPointPathComponents[] = { |
| 23 "/", "special", "gdata" | 27 "/", "special", "gdata" |
| 24 }; | 28 }; |
| 25 | 29 |
| 30 const int kReadOnlyFilePermissions = base::PLATFORM_FILE_OPEN | |
| 31 base::PLATFORM_FILE_READ | |
| 32 base::PLATFORM_FILE_EXCLUSIVE_READ | |
| 33 base::PLATFORM_FILE_ASYNC; |
| 34 |
| 26 } // namespace | 35 } // namespace |
| 27 | 36 |
| 28 const FilePath& GetGDataMountPointPath() { | 37 const FilePath& GetGDataMountPointPath() { |
| 29 CR_DEFINE_STATIC_LOCAL(FilePath, gdata_mount_path, | 38 CR_DEFINE_STATIC_LOCAL(FilePath, gdata_mount_path, |
| 30 (FilePath::FromUTF8Unsafe(kGDataMountPointPath))); | 39 (FilePath::FromUTF8Unsafe(kGDataMountPointPath))); |
| 31 return gdata_mount_path; | 40 return gdata_mount_path; |
| 32 } | 41 } |
| 33 | 42 |
| 34 const std::string& GetGDataMountPointPathAsString() { | 43 const std::string& GetGDataMountPointPathAsString() { |
| 35 CR_DEFINE_STATIC_LOCAL(std::string, gdata_mount_path_string, | 44 CR_DEFINE_STATIC_LOCAL(std::string, gdata_mount_path_string, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 51 | 60 |
| 52 // -1 to include 'gdata'. | 61 // -1 to include 'gdata'. |
| 53 FilePath extracted; | 62 FilePath extracted; |
| 54 for (size_t i = arraysize(kGDataMountPointPathComponents) - 1; | 63 for (size_t i = arraysize(kGDataMountPointPathComponents) - 1; |
| 55 i < components.size(); ++i) { | 64 i < components.size(); ++i) { |
| 56 extracted = extracted.Append(components[i]); | 65 extracted = extracted.Append(components[i]); |
| 57 } | 66 } |
| 58 return extracted; | 67 return extracted; |
| 59 } | 68 } |
| 60 | 69 |
| 70 |
| 71 void SetPermissionsForGDataCacheFiles(Profile* profile, |
| 72 int pid, |
| 73 const FilePath& path) { |
| 74 GDataSystemService* system_service = |
| 75 GDataSystemServiceFactory::GetForProfile(profile); |
| 76 DCHECK(system_service); |
| 77 |
| 78 GDataFileSystem* file_system = system_service->file_system(); |
| 79 DCHECK(file_system); |
| 80 |
| 81 GDataFileProperties file_properties; |
| 82 file_system->GetFileInfoFromPath(path, &file_properties); |
| 83 |
| 84 std::string resource_id = file_properties.resource_id; |
| 85 std::string file_md5 = file_properties.file_md5; |
| 86 |
| 87 // We check permissions for raw cache file paths only for read-only |
| 88 // operations (when fileEntry.file() is called), so read only permissions |
| 89 // should be sufficient for all cache paths. For the rest of supported |
| 90 // operations the file access check is done for gdata/ paths. |
| 91 std::vector<std::pair<FilePath, int> > cache_paths; |
| 92 cache_paths.push_back(std::make_pair( |
| 93 file_system->GetCacheFilePath(resource_id, file_md5, |
| 94 GDataRootDirectory::CACHE_TYPE_PERSISTENT, |
| 95 GDataFileSystem::CACHED_FILE_FROM_SERVER), |
| 96 kReadOnlyFilePermissions)); |
| 97 // TODO(tbarzic): When we start supporting openFile operation, we may have to |
| 98 // change permission for localy modified files to match handler's permissions. |
| 99 cache_paths.push_back(std::make_pair( |
| 100 file_system->GetCacheFilePath(resource_id, file_md5, |
| 101 GDataRootDirectory::CACHE_TYPE_PERSISTENT, |
| 102 GDataFileSystem::CACHED_FILE_LOCALLY_MODIFIED), |
| 103 kReadOnlyFilePermissions)); |
| 104 cache_paths.push_back(std::make_pair( |
| 105 file_system->GetCacheFilePath(resource_id, file_md5, |
| 106 GDataRootDirectory::CACHE_TYPE_TMP, |
| 107 GDataFileSystem::CACHED_FILE_FROM_SERVER), |
| 108 kReadOnlyFilePermissions)); |
| 109 |
| 110 for (size_t i = 0; i < cache_paths.size(); i++) { |
| 111 content::ChildProcessSecurityPolicy::GetInstance()->GrantPermissionsForFile( |
| 112 pid, cache_paths[i].first, cache_paths[i].second); |
| 113 } |
| 114 } |
| 115 |
| 61 } // namespace util | 116 } // namespace util |
| 62 } // namespace gdata | 117 } // namespace gdata |
| OLD | NEW |