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

Side by Side Diff: chrome/browser/chromeos/file_system_provider/mount_path_util.cc

Issue 237583015: [fsp] Add FileSystemURLParser to the file system provider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplified. Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
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 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
38 } // namespace util 94 } // namespace util
39 } // namespace file_system_provider 95 } // namespace file_system_provider
40 } // namespace chromeos 96 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698