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 "base/files/file_path.h" | 7 #include <vector> |
| 8 |
8 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
9 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
| 13 #include "chrome/browser/chromeos/file_system_provider/service.h" |
10 #include "chrome/browser/chromeos/login/user.h" | 14 #include "chrome/browser/chromeos/login/user.h" |
11 #include "chrome/browser/chromeos/login/user_manager.h" | 15 #include "chrome/browser/chromeos/login/user_manager.h" |
| 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" |
12 | 19 |
13 namespace chromeos { | 20 namespace chromeos { |
14 namespace file_system_provider { | 21 namespace file_system_provider { |
15 namespace util { | 22 namespace util { |
16 | 23 |
17 namespace { | 24 namespace { |
18 | 25 |
19 // Root mount path for all of the provided file systems. | 26 // Root mount path for all of the provided file systems. |
20 const base::FilePath::CharType kProvidedMountPointRoot[] = | 27 const base::FilePath::CharType kProvidedMountPointRoot[] = |
21 FILE_PATH_LITERAL("/provided"); | 28 FILE_PATH_LITERAL("/provided"); |
22 | 29 |
23 } // namespace | 30 } // namespace |
24 | 31 |
25 base::FilePath GetMountPointPath(Profile* profile, | 32 base::FilePath GetMountPath(Profile* profile, |
26 std::string extension_id, | 33 std::string extension_id, |
27 int file_system_id) { | 34 int file_system_id) { |
28 chromeos::User* const user = | 35 chromeos::User* const user = |
29 chromeos::UserManager::IsInitialized() | 36 chromeos::UserManager::IsInitialized() |
30 ? chromeos::UserManager::Get()->GetUserByProfile( | 37 ? chromeos::UserManager::Get()->GetUserByProfile( |
31 profile->GetOriginalProfile()) | 38 profile->GetOriginalProfile()) |
32 : NULL; | 39 : NULL; |
33 const std::string user_suffix = user ? "-" + user->username_hash() : ""; | 40 const std::string user_suffix = user ? "-" + user->username_hash() : ""; |
34 return base::FilePath(kProvidedMountPointRoot).AppendASCII( | 41 return base::FilePath(kProvidedMountPointRoot).AppendASCII( |
35 extension_id + "-" + base::IntToString(file_system_id) + user_suffix); | 42 extension_id + "-" + base::IntToString(file_system_id) + user_suffix); |
36 } | 43 } |
37 | 44 |
| 45 FileSystemURLParser::FileSystemURLParser(const fileapi::FileSystemURL& url) |
| 46 : url_(url), file_system_(NULL) { |
| 47 } |
| 48 |
| 49 FileSystemURLParser::~FileSystemURLParser() { |
| 50 } |
| 51 |
| 52 bool FileSystemURLParser::Parse() { |
| 53 if (url_.type() != fileapi::kFileSystemTypeProvided) |
| 54 return false; |
| 55 |
| 56 // First, find the service handling the mount point of the URL. |
| 57 const std::vector<Profile*>& profiles = |
| 58 g_browser_process->profile_manager()->GetLoadedProfiles(); |
| 59 |
| 60 for (size_t i = 0; i < profiles.size(); ++i) { |
| 61 Profile* original_profile = profiles[i]->GetOriginalProfile(); |
| 62 |
| 63 if (original_profile != profiles[i] || |
| 64 chromeos::ProfileHelper::IsSigninProfile(original_profile)) { |
| 65 continue; |
| 66 } |
| 67 |
| 68 Service* service = Service::Get(original_profile); |
| 69 if (!service) |
| 70 continue; |
| 71 |
| 72 ProvidedFileSystemInterface* file_system = |
| 73 service->GetProvidedFileSystem(url_.filesystem_id()); |
| 74 if (!file_system) |
| 75 continue; |
| 76 |
| 77 // Strip the mount point name from the virtual path, to extract the file |
| 78 // path within the provided file system. |
| 79 file_system_ = file_system; |
| 80 std::vector<base::FilePath::StringType> components; |
| 81 url_.virtual_path().GetComponents(&components); |
| 82 DCHECK_LT(0u, components.size()); |
| 83 file_path_ = base::FilePath(); |
| 84 for (size_t i = 1; i < components.size(); ++i) { |
| 85 // TODO(mtomasz): This could be optimized, to avoid unnecessary copies. |
| 86 file_path_ = file_path_.Append(components[i]); |
| 87 } |
| 88 |
| 89 return true; |
| 90 } |
| 91 |
| 92 // Nothing has been found. |
| 93 return false; |
| 94 } |
| 95 |
38 } // namespace util | 96 } // namespace util |
39 } // namespace file_system_provider | 97 } // namespace file_system_provider |
40 } // namespace chromeos | 98 } // namespace chromeos |
OLD | NEW |