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