OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/file_system_provider/mount_path_util.h" | 5 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" | 12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
13 #include "chrome/browser/chromeos/file_system_provider/service.h" | 13 #include "chrome/browser/chromeos/file_system_provider/service.h" |
| 14 #include "chrome/browser/chromeos/file_system_provider/file_system_plugin/plugin
_service.h" |
14 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "components/user_manager/user.h" | 18 #include "components/user_manager/user.h" |
18 #include "components/user_manager/user_manager.h" | 19 #include "components/user_manager/user_manager.h" |
19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
20 | 21 |
21 using content::BrowserThread; | 22 using content::BrowserThread; |
22 | 23 |
23 namespace chromeos { | 24 namespace chromeos { |
24 namespace file_system_provider { | 25 namespace file_system_provider { |
25 namespace util { | 26 namespace util { |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 // Root mount path for all of the provided file systems. | 30 // Root mount path for all of the provided file systems. |
30 const base::FilePath::CharType kProvidedMountPointRoot[] = | 31 const base::FilePath::CharType kProvidedMountPointRoot[] = |
31 FILE_PATH_LITERAL("/provided"); | 32 FILE_PATH_LITERAL("/provided"); |
32 | 33 const base::FilePath::CharType kPluginProvidedPointRoot[] = |
| 34 FILE_PATH_LITERAL("/plugin_provided"); |
33 } // namespace | 35 } // namespace |
34 | 36 |
35 // Escapes the file system id so it can be used as a file/directory name. | 37 // Escapes the file system id so it can be used as a file/directory name. |
36 // This is based on net/base/escape.cc: net::(anonymous namespace)::Escape | 38 // This is based on net/base/escape.cc: net::(anonymous namespace)::Escape |
37 std::string EscapeFileSystemId(const std::string& file_system_id) { | 39 std::string EscapeFileSystemId(const std::string& file_system_id) { |
38 std::string escaped; | 40 std::string escaped; |
39 for (size_t i = 0; i < file_system_id.size(); ++i) { | 41 for (size_t i = 0; i < file_system_id.size(); ++i) { |
40 const char c = file_system_id[i]; | 42 const char c = file_system_id[i]; |
41 if (c == '%' || c == '.' || c == '/') { | 43 if (c == '%' || c == '.' || c == '/') { |
42 base::StringAppendF(&escaped, "%%%02X", c); | 44 base::StringAppendF(&escaped, "%%%02X", c); |
(...skipping 11 matching lines...) Expand all Loading... |
54 user_manager::UserManager::IsInitialized() | 56 user_manager::UserManager::IsInitialized() |
55 ? chromeos::ProfileHelper::Get()->GetUserByProfile( | 57 ? chromeos::ProfileHelper::Get()->GetUserByProfile( |
56 profile->GetOriginalProfile()) | 58 profile->GetOriginalProfile()) |
57 : NULL; | 59 : NULL; |
58 const std::string safe_file_system_id = EscapeFileSystemId(file_system_id); | 60 const std::string safe_file_system_id = EscapeFileSystemId(file_system_id); |
59 const std::string username_suffix = user ? user->username_hash() : ""; | 61 const std::string username_suffix = user ? user->username_hash() : ""; |
60 return base::FilePath(kProvidedMountPointRoot).AppendASCII( | 62 return base::FilePath(kProvidedMountPointRoot).AppendASCII( |
61 extension_id + ":" + safe_file_system_id + ":" + username_suffix); | 63 extension_id + ":" + safe_file_system_id + ":" + username_suffix); |
62 } | 64 } |
63 | 65 |
| 66 base::FilePath GetPluginMountPath(Profile* profile, |
| 67 const std::string& source_id, |
| 68 const std::string& file_system_id) { |
| 69 const user_manager::User* const user = |
| 70 user_manager::UserManager::IsInitialized() |
| 71 ? chromeos::ProfileHelper::Get()->GetUserByProfile( |
| 72 profile->GetOriginalProfile()) |
| 73 : NULL; |
| 74 const std::string safe_file_system_id = EscapeFileSystemId(file_system_id); |
| 75 const std::string username_suffix = user ? user->username_hash() : ""; |
| 76 return base::FilePath(kPluginProvidedPointRoot).AppendASCII( |
| 77 source_id + ":" + safe_file_system_id + ":" + username_suffix); |
| 78 } |
| 79 |
64 bool IsFileSystemProviderLocalPath(const base::FilePath& local_path) { | 80 bool IsFileSystemProviderLocalPath(const base::FilePath& local_path) { |
65 std::vector<base::FilePath::StringType> components; | 81 std::vector<base::FilePath::StringType> components; |
66 local_path.GetComponents(&components); | 82 local_path.GetComponents(&components); |
67 | 83 |
68 if (components.size() < 3) | 84 if (components.size() < 3) |
69 return false; | 85 return false; |
70 | 86 |
71 if (components[0] != FILE_PATH_LITERAL("/")) | 87 if (components[0] != FILE_PATH_LITERAL("/")) |
72 return false; | 88 return false; |
73 | 89 |
74 if (components[1] != kProvidedMountPointRoot + 1 /* no leading slash */) | 90 if (components[1] != kProvidedMountPointRoot + 1 ||/* no leading slash */ |
| 91 components[0] != kPluginProvidedPointRoot + 1) |
75 return false; | 92 return false; |
76 | 93 |
77 return true; | 94 return true; |
78 } | 95 } |
79 | 96 |
80 FileSystemURLParser::FileSystemURLParser(const storage::FileSystemURL& url) | 97 FileSystemURLParser::FileSystemURLParser(const storage::FileSystemURL& url) |
81 : url_(url), file_system_(NULL) { | 98 : url_(url), file_system_(NULL) { |
82 } | 99 } |
83 | 100 |
84 FileSystemURLParser::~FileSystemURLParser() { | 101 FileSystemURLParser::~FileSystemURLParser() { |
85 } | 102 } |
86 | 103 |
87 bool FileSystemURLParser::Parse() { | 104 bool FileSystemURLParser::Parse() { |
88 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 105 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
89 | 106 |
| 107 if (url_.type() == storage::kFileSystemTypeProvided) |
| 108 return ParseExtensionProvided(); |
| 109 if (url_.type() == storage::kFileSystemTypePluginProvided) |
| 110 return ParsePluginProvided(); |
| 111 return false; |
| 112 } |
| 113 |
| 114 bool FileSystemURLParser::ParseExtensionProvided() { |
| 115 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 116 |
90 if (url_.type() != storage::kFileSystemTypeProvided) | 117 if (url_.type() != storage::kFileSystemTypeProvided) |
91 return false; | 118 return false; |
92 | |
93 // First, find the service handling the mount point of the URL. | 119 // First, find the service handling the mount point of the URL. |
94 const std::vector<Profile*>& profiles = | 120 const std::vector<Profile*>& profiles = |
95 g_browser_process->profile_manager()->GetLoadedProfiles(); | 121 g_browser_process->profile_manager()->GetLoadedProfiles(); |
96 | 122 |
97 for (size_t i = 0; i < profiles.size(); ++i) { | 123 for (size_t i = 0; i < profiles.size(); ++i) { |
98 Profile* original_profile = profiles[i]->GetOriginalProfile(); | 124 Profile* original_profile = profiles[i]->GetOriginalProfile(); |
99 | 125 |
100 if (original_profile != profiles[i] || | 126 if (original_profile != profiles[i] || |
101 chromeos::ProfileHelper::IsSigninProfile(original_profile)) { | 127 chromeos::ProfileHelper::IsSigninProfile(original_profile)) { |
102 continue; | 128 continue; |
(...skipping 22 matching lines...) Expand all Loading... |
125 file_path_ = file_path_.Append(components[i]); | 151 file_path_ = file_path_.Append(components[i]); |
126 } | 152 } |
127 | 153 |
128 return true; | 154 return true; |
129 } | 155 } |
130 | 156 |
131 // Nothing has been found. | 157 // Nothing has been found. |
132 return false; | 158 return false; |
133 } | 159 } |
134 | 160 |
| 161 bool FileSystemURLParser::ParsePluginProvided() { |
| 162 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 163 |
| 164 if (url_.type() != storage::kFileSystemTypePluginProvided) |
| 165 return false; |
| 166 // First, find the service handling the mount point of the URL. |
| 167 const std::vector<Profile*>& profiles = |
| 168 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 169 |
| 170 for (size_t i = 0; i < profiles.size(); ++i) { |
| 171 Profile* original_profile = profiles[i]->GetOriginalProfile(); |
| 172 |
| 173 if (original_profile != profiles[i] || |
| 174 chromeos::ProfileHelper::IsSigninProfile(original_profile)) { |
| 175 continue; |
| 176 } |
| 177 |
| 178 PluginService* const service = PluginService::Get(original_profile); |
| 179 if (!service) |
| 180 continue; |
| 181 |
| 182 ProvidedFileSystemInterface* const file_system = |
| 183 service->GetProvidedFileSystem(url_.filesystem_id()); |
| 184 if (!file_system) |
| 185 continue; |
| 186 |
| 187 // Strip the mount path name from the local path, to extract the file path |
| 188 // within the provided file system. |
| 189 file_system_ = file_system; |
| 190 std::vector<base::FilePath::StringType> components; |
| 191 url_.path().GetComponents(&components); |
| 192 if (components.size() < 3) |
| 193 return false; |
| 194 |
| 195 file_path_ = base::FilePath(FILE_PATH_LITERAL("/")); |
| 196 for (size_t i = 3; i < components.size(); ++i) { |
| 197 file_path_ = file_path_.Append(components[i]); |
| 198 } |
| 199 |
| 200 return true; |
| 201 } |
| 202 |
| 203 // Nothing has been found. |
| 204 return false; |
| 205 } |
| 206 |
135 LocalPathParser::LocalPathParser(Profile* profile, | 207 LocalPathParser::LocalPathParser(Profile* profile, |
136 const base::FilePath& local_path) | 208 const base::FilePath& local_path) |
137 : profile_(profile), local_path_(local_path), file_system_(NULL) { | 209 : profile_(profile), local_path_(local_path), file_system_(NULL) { |
138 } | 210 } |
139 | 211 |
140 LocalPathParser::~LocalPathParser() { | 212 LocalPathParser::~LocalPathParser() { |
141 } | 213 } |
142 | 214 |
143 bool LocalPathParser::Parse() { | 215 bool LocalPathParser::Parse() { |
144 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 216 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 25 matching lines...) Expand all Loading... |
170 for (size_t i = 3; i < components.size(); ++i) { | 242 for (size_t i = 3; i < components.size(); ++i) { |
171 file_path_ = file_path_.Append(components[i]); | 243 file_path_ = file_path_.Append(components[i]); |
172 } | 244 } |
173 | 245 |
174 return true; | 246 return true; |
175 } | 247 } |
176 | 248 |
177 } // namespace util | 249 } // namespace util |
178 } // namespace file_system_provider | 250 } // namespace file_system_provider |
179 } // namespace chromeos | 251 } // namespace chromeos |
OLD | NEW |