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

Side by Side Diff: webkit/fileapi/isolated_context.cc

Issue 10540070: Make Isolated file system writable only if it is configured so (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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
« no previous file with comments | « webkit/fileapi/isolated_context.h ('k') | webkit/fileapi/isolated_file_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "webkit/fileapi/isolated_context.h" 5 #include "webkit/fileapi/isolated_context.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 } 44 }
45 toplevel_map_[filesystem_id] = toplevels; 45 toplevel_map_[filesystem_id] = toplevels;
46 return filesystem_id; 46 return filesystem_id;
47 } 47 }
48 48
49 // Revoke any registered drag context for the child_id. 49 // Revoke any registered drag context for the child_id.
50 void IsolatedContext::RevokeIsolatedFileSystem( 50 void IsolatedContext::RevokeIsolatedFileSystem(
51 const std::string& filesystem_id) { 51 const std::string& filesystem_id) {
52 base::AutoLock locker(lock_); 52 base::AutoLock locker(lock_);
53 toplevel_map_.erase(filesystem_id); 53 toplevel_map_.erase(filesystem_id);
54 writable_ids_.erase(filesystem_id);
54 } 55 }
55 56
56 bool IsolatedContext::CrackIsolatedPath(const FilePath& virtual_path, 57 bool IsolatedContext::CrackIsolatedPath(const FilePath& virtual_path,
57 std::string* filesystem_id, 58 std::string* filesystem_id,
58 FilePath* root_path, 59 FilePath* root_path,
59 FilePath* platform_path) const { 60 FilePath* platform_path) const {
60 DCHECK(filesystem_id); 61 DCHECK(filesystem_id);
61 DCHECK(platform_path); 62 DCHECK(platform_path);
62 63
63 // This should not contain any '..' references. 64 // This should not contain any '..' references.
(...skipping 26 matching lines...) Expand all
90 FilePath path = found->second; 91 FilePath path = found->second;
91 if (root_path) 92 if (root_path)
92 *root_path = path; 93 *root_path = path;
93 for (size_t i = 2; i < components.size(); ++i) { 94 for (size_t i = 2; i < components.size(); ++i) {
94 path = path.Append(components[i]); 95 path = path.Append(components[i]);
95 } 96 }
96 *platform_path = path; 97 *platform_path = path;
97 return true; 98 return true;
98 } 99 }
99 100
100 bool IsolatedContext::GetTopLevelPaths(std::string filesystem_id, 101 bool IsolatedContext::GetTopLevelPaths(const std::string& filesystem_id,
101 std::vector<FilePath>* paths) const { 102 std::vector<FilePath>* paths) const {
102 DCHECK(paths); 103 DCHECK(paths);
103 base::AutoLock locker(lock_); 104 base::AutoLock locker(lock_);
104 IDToPathMap::const_iterator found = toplevel_map_.find(filesystem_id); 105 IDToPathMap::const_iterator found = toplevel_map_.find(filesystem_id);
105 if (found == toplevel_map_.end()) 106 if (found == toplevel_map_.end())
106 return false; 107 return false;
107 paths->clear(); 108 paths->clear();
108 PathMap toplevels = found->second; 109 PathMap toplevels = found->second;
109 for (PathMap::const_iterator iter = toplevels.begin(); 110 for (PathMap::const_iterator iter = toplevels.begin();
110 iter != toplevels.end(); ++iter) { 111 iter != toplevels.end(); ++iter) {
111 // Each path map entry holds a map of a toplevel name to its full path. 112 // Each path map entry holds a map of a toplevel name to its full path.
112 paths->push_back(iter->second); 113 paths->push_back(iter->second);
113 } 114 }
114 return true; 115 return true;
115 } 116 }
116 117
118 bool IsolatedContext::SetWritable(const std::string& filesystem_id,
119 bool writable) {
120 base::AutoLock locker(lock_);
121 if (writable_ids_.find(filesystem_id) == writable_ids_.end())
122 return false;
kinaba 2012/06/08 04:40:19 I failed to understand these two lines. It looks l
kinuko 2012/06/08 05:24:25 Aha you're right. I was first writing this patch
123 if (writable)
124 writable_ids_.insert(filesystem_id);
125 else
126 writable_ids_.erase(filesystem_id);
127 return true;
128 }
129
130 bool IsolatedContext::IsWritable(const std::string& filesystem_id) const {
131 base::AutoLock locker(lock_);
132 return (writable_ids_.find(filesystem_id) != writable_ids_.end());
133 }
134
117 FilePath IsolatedContext::CreateVirtualPath( 135 FilePath IsolatedContext::CreateVirtualPath(
118 const std::string& filesystem_id, const FilePath& relative_path) const { 136 const std::string& filesystem_id, const FilePath& relative_path) const {
119 FilePath full_path; 137 FilePath full_path;
120 full_path = full_path.AppendASCII(filesystem_id); 138 full_path = full_path.AppendASCII(filesystem_id);
121 if (relative_path.value() != FILE_PATH_LITERAL("/")) 139 if (relative_path.value() != FILE_PATH_LITERAL("/"))
122 full_path = full_path.Append(relative_path); 140 full_path = full_path.Append(relative_path);
123 return full_path; 141 return full_path;
124 } 142 }
125 143
126 IsolatedContext::IsolatedContext() { 144 IsolatedContext::IsolatedContext() {
127 } 145 }
128 146
129 IsolatedContext::~IsolatedContext() { 147 IsolatedContext::~IsolatedContext() {
130 } 148 }
131 149
132 std::string IsolatedContext::GetNewFileSystemId() const { 150 std::string IsolatedContext::GetNewFileSystemId() const {
133 // Returns an arbitrary random string which must be unique in the map. 151 // Returns an arbitrary random string which must be unique in the map.
134 uint32 random_data[4]; 152 uint32 random_data[4];
135 std::string id; 153 std::string id;
136 do { 154 do {
137 base::RandBytes(random_data, sizeof(random_data)); 155 base::RandBytes(random_data, sizeof(random_data));
138 id = base::HexEncode(random_data, sizeof(random_data)); 156 id = base::HexEncode(random_data, sizeof(random_data));
139 } while (toplevel_map_.find(id) != toplevel_map_.end()); 157 } while (toplevel_map_.find(id) != toplevel_map_.end());
140 return id; 158 return id;
141 } 159 }
142 160
143 } // namespace fileapi 161 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/isolated_context.h ('k') | webkit/fileapi/isolated_file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698