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

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

Issue 294073007: [fsp] Let extensions decide about the file system id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 7 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 <vector> 7 #include <vector>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string_number_conversions.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/login/users/user.h" 14 #include "chrome/browser/chromeos/login/users/user.h"
15 #include "chrome/browser/chromeos/login/users/user_manager.h" 15 #include "chrome/browser/chromeos/login/users/user_manager.h"
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" 16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/profiles/profile_manager.h" 18 #include "chrome/browser/profiles/profile_manager.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 20
21 using content::BrowserThread; 21 using content::BrowserThread;
22 22
23 namespace chromeos { 23 namespace chromeos {
24 namespace file_system_provider { 24 namespace file_system_provider {
25 namespace util { 25 namespace util {
26 26
27 namespace { 27 namespace {
28 28
29 // Root mount path for all of the provided file systems. 29 // Root mount path for all of the provided file systems.
30 const base::FilePath::CharType kProvidedMountPointRoot[] = 30 const base::FilePath::CharType kProvidedMountPointRoot[] =
31 FILE_PATH_LITERAL("/provided"); 31 FILE_PATH_LITERAL("/provided");
32 32
33 } // namespace 33 } // namespace
34 34
35 // 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
37 std::string EscapeFileSystemId(const std::string& file_system_id) {
38 std::string escaped;
39 for (size_t i = 0; i < file_system_id.size(); ++i) {
40 const char c = file_system_id[i];
41 if (c == '%' || c == '.' || c == '/') {
42 base::StringAppendF(&escaped, "%%%02X", c);
43 } else {
44 escaped.push_back(c);
45 }
46 }
47 return escaped;
48 }
49
35 base::FilePath GetMountPath(Profile* profile, 50 base::FilePath GetMountPath(Profile* profile,
36 std::string extension_id, 51 const std::string& extension_id,
37 int file_system_id) { 52 const std::string& file_system_id) {
38 chromeos::User* const user = 53 chromeos::User* const user =
39 chromeos::UserManager::IsInitialized() 54 chromeos::UserManager::IsInitialized()
40 ? chromeos::UserManager::Get()->GetUserByProfile( 55 ? chromeos::UserManager::Get()->GetUserByProfile(
41 profile->GetOriginalProfile()) 56 profile->GetOriginalProfile())
42 : NULL; 57 : NULL;
43 const std::string user_suffix = user ? "-" + user->username_hash() : ""; 58 const std::string safe_file_system_id = EscapeFileSystemId(file_system_id);
59 const std::string username_suffix = user ? user->username_hash() : "";
44 return base::FilePath(kProvidedMountPointRoot).AppendASCII( 60 return base::FilePath(kProvidedMountPointRoot).AppendASCII(
45 extension_id + "-" + base::IntToString(file_system_id) + user_suffix); 61 extension_id + ":" + safe_file_system_id + ":" + username_suffix);
46 } 62 }
47 63
48 FileSystemURLParser::FileSystemURLParser(const fileapi::FileSystemURL& url) 64 FileSystemURLParser::FileSystemURLParser(const fileapi::FileSystemURL& url)
49 : url_(url), file_system_(NULL) { 65 : url_(url), file_system_(NULL) {
50 } 66 }
51 67
52 FileSystemURLParser::~FileSystemURLParser() { 68 FileSystemURLParser::~FileSystemURLParser() {
53 } 69 }
54 70
55 bool FileSystemURLParser::Parse() { 71 bool FileSystemURLParser::Parse() {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return true; 110 return true;
95 } 111 }
96 112
97 // Nothing has been found. 113 // Nothing has been found.
98 return false; 114 return false;
99 } 115 }
100 116
101 } // namespace util 117 } // namespace util
102 } // namespace file_system_provider 118 } // namespace file_system_provider
103 } // namespace chromeos 119 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698