OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_manager/fileapi_util.h" | 5 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
6 | 6 |
7 #include "base/files/file.h" | 7 #include "base/files/file.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "chrome/browser/chromeos/drive/file_system_util.h" | 9 #include "chrome/browser/chromeos/drive/file_system_util.h" |
10 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 // Converts the element under the iterator to an entry. First, converts | 64 // Converts the element under the iterator to an entry. First, converts |
65 // the virtual path to an URL, and calls OnResolvedURL(). In case of error | 65 // the virtual path to an URL, and calls OnResolvedURL(). In case of error |
66 // calls OnIteratorConverted with an error entry definition. | 66 // calls OnIteratorConverted with an error entry definition. |
67 void ConvertNextIterator(scoped_ptr<FileDefinitionListConverter> self_deleter, | 67 void ConvertNextIterator(scoped_ptr<FileDefinitionListConverter> self_deleter, |
68 FileDefinitionList::const_iterator iterator); | 68 FileDefinitionList::const_iterator iterator); |
69 | 69 |
70 // Creates an entry definition from the URL as well as the file definition. | 70 // Creates an entry definition from the URL as well as the file definition. |
71 // Then, calls OnIteratorConverted with the created entry definition. | 71 // Then, calls OnIteratorConverted with the created entry definition. |
72 void OnResolvedURL(scoped_ptr<FileDefinitionListConverter> self_deleter, | 72 void OnResolvedURL(scoped_ptr<FileDefinitionListConverter> self_deleter, |
73 FileDefinitionList::const_iterator iterator, | 73 FileDefinitionList::const_iterator iterator, |
74 const GURL& root_url, | 74 base::File::Error error, |
75 const std::string& name, | 75 const fileapi::FileSystemInfo& info, |
76 base::File::Error error); | 76 const base::FilePath& file_path, |
77 fileapi::FileSystemContext::ResolvedEntryType type); | |
77 | 78 |
78 // Called when the iterator is converted. Adds the |entry_definition| to | 79 // Called when the iterator is converted. Adds the |entry_definition| to |
79 // |results_| and calls ConvertNextIterator() for the next element. | 80 // |results_| and calls ConvertNextIterator() for the next element. |
80 void OnIteratorConverted(scoped_ptr<FileDefinitionListConverter> self_deleter, | 81 void OnIteratorConverted(scoped_ptr<FileDefinitionListConverter> self_deleter, |
81 FileDefinitionList::const_iterator iterator, | 82 FileDefinitionList::const_iterator iterator, |
82 const EntryDefinition& entry_definition); | 83 const EntryDefinition& entry_definition); |
83 | 84 |
84 scoped_refptr<fileapi::FileSystemContext> file_system_context_; | 85 scoped_refptr<fileapi::FileSystemContext> file_system_context_; |
85 const std::string extension_id_; | 86 const std::string extension_id_; |
86 const FileDefinitionList file_definition_list_; | 87 const FileDefinitionList file_definition_list_; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 } | 126 } |
126 | 127 |
127 if (!file_system_context_.get()) { | 128 if (!file_system_context_.get()) { |
128 OnIteratorConverted(self_deleter.Pass(), | 129 OnIteratorConverted(self_deleter.Pass(), |
129 iterator, | 130 iterator, |
130 CreateEntryDefinitionWithError( | 131 CreateEntryDefinitionWithError( |
131 base::File::FILE_ERROR_INVALID_OPERATION)); | 132 base::File::FILE_ERROR_INVALID_OPERATION)); |
132 return; | 133 return; |
133 } | 134 } |
134 | 135 |
135 fileapi::ExternalFileSystemBackend* backend = | |
136 file_system_context_->external_backend(); | |
137 if (!backend) { | |
138 OnIteratorConverted(self_deleter.Pass(), | |
139 iterator, | |
140 CreateEntryDefinitionWithError( | |
141 base::File::FILE_ERROR_INVALID_OPERATION)); | |
142 return; | |
143 } | |
144 | |
145 fileapi::FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( | 136 fileapi::FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
146 extensions::Extension::GetBaseURLFromExtensionId(extension_id_), | 137 extensions::Extension::GetBaseURLFromExtensionId(extension_id_), |
147 fileapi::kFileSystemTypeExternal, | 138 fileapi::kFileSystemTypeExternal, |
148 iterator->virtual_path); | 139 iterator->virtual_path); |
149 DCHECK(url.is_valid()); | 140 DCHECK(url.is_valid()); |
150 | 141 |
151 // The converter object will be deleted if the callback is not called because | 142 // The converter object will be deleted if the callback is not called because |
152 // of shutdown during ResolveURL(). | 143 // of shutdown during ResolveURL(). |
153 // | 144 file_system_context_->ResolveURL( |
154 // TODO(mtomasz, nhiroki): Call FileSystemContext::ResolveURL() directly, | |
155 // after removing redundant thread restrictions in there. | |
156 backend->ResolveURL( | |
157 url, | 145 url, |
158 // Not sandboxed file systems are not creatable via ResolveURL(). | |
159 fileapi::OPEN_FILE_SYSTEM_FAIL_IF_NONEXISTENT, | |
160 base::Bind(&FileDefinitionListConverter::OnResolvedURL, | 146 base::Bind(&FileDefinitionListConverter::OnResolvedURL, |
161 base::Unretained(this), | 147 base::Unretained(this), |
162 base::Passed(&self_deleter), | 148 base::Passed(&self_deleter), |
163 iterator)); | 149 iterator)); |
164 } | 150 } |
165 | 151 |
166 void FileDefinitionListConverter::OnResolvedURL( | 152 void FileDefinitionListConverter::OnResolvedURL( |
167 scoped_ptr<FileDefinitionListConverter> self_deleter, | 153 scoped_ptr<FileDefinitionListConverter> self_deleter, |
168 FileDefinitionList::const_iterator iterator, | 154 FileDefinitionList::const_iterator iterator, |
169 const GURL& root_url, | 155 base::File::Error error, |
170 const std::string& name, | 156 const fileapi::FileSystemInfo& info, |
171 base::File::Error error) { | 157 const base::FilePath& file_path, |
158 fileapi::FileSystemContext::ResolvedEntryType type) { | |
mtomasz
2014/04/21 05:03:05
I'm wondering if introducing a new argument is nec
kinaba
2014/04/21 05:19:09
I think "ERROR but output value fields (like |entr
mtomasz
2014/04/21 05:48:33
My concern was that, if we returned an error, then
kinaba
2014/04/21 07:59:25
My concern is that the suggested plan makes the AP
mtomasz
2014/04/21 08:04:07
Ah, now I understand your point of view. Yep, I th
| |
172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
173 | 160 |
161 if (error != base::File::FILE_OK) { | |
162 OnIteratorConverted(self_deleter.Pass(), | |
163 iterator, | |
164 CreateEntryDefinitionWithError(error)); | |
165 return; | |
166 } | |
167 | |
174 EntryDefinition entry_definition; | 168 EntryDefinition entry_definition; |
175 entry_definition.file_system_root_url = root_url.spec(); | 169 entry_definition.file_system_root_url = info.root_url.spec(); |
176 entry_definition.file_system_name = name; | 170 entry_definition.file_system_name = info.name; |
171 DCHECK(type == fileapi::FileSystemContext::RESOLVED_ENTRY_NOT_FOUND || | |
172 iterator->is_directory == | |
173 (type == fileapi::FileSystemContext::RESOLVED_ENTRY_DIRECTORY)); | |
177 entry_definition.is_directory = iterator->is_directory; | 174 entry_definition.is_directory = iterator->is_directory; |
178 entry_definition.error = error; | 175 entry_definition.error = error; |
mtomasz
2014/04/21 05:50:02
nit: This is always FILE_OK here, so how about inl
kinaba
2014/04/21 07:59:25
Done.
| |
179 | 176 |
180 // Construct a target Entry.fullPath value from the virtual path and the | 177 // Construct a target Entry.fullPath value from the virtual path and the |
181 // root URL. Eg. Downloads/A/b.txt -> A/b.txt. | 178 // root URL. Eg. Downloads/A/b.txt -> A/b.txt. |
182 const base::FilePath root_virtual_path = | 179 const base::FilePath root_virtual_path = |
183 file_system_context_->CrackURL(root_url).virtual_path(); | 180 file_system_context_->CrackURL(info.root_url).virtual_path(); |
184 DCHECK(root_virtual_path == iterator->virtual_path || | 181 DCHECK(root_virtual_path == iterator->virtual_path || |
185 root_virtual_path.IsParent(iterator->virtual_path)); | 182 root_virtual_path.IsParent(iterator->virtual_path)); |
186 base::FilePath full_path; | 183 base::FilePath full_path; |
187 root_virtual_path.AppendRelativePath(iterator->virtual_path, &full_path); | 184 root_virtual_path.AppendRelativePath(iterator->virtual_path, &full_path); |
188 entry_definition.full_path = full_path; | 185 entry_definition.full_path = full_path; |
189 | 186 |
190 OnIteratorConverted(self_deleter.Pass(), iterator, entry_definition); | 187 OnIteratorConverted(self_deleter.Pass(), iterator, entry_definition); |
191 } | 188 } |
192 | 189 |
193 void FileDefinitionListConverter::OnIteratorConverted( | 190 void FileDefinitionListConverter::OnIteratorConverted( |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 file_definition_list.push_back(file_definition); | 316 file_definition_list.push_back(file_definition); |
320 ConvertFileDefinitionListToEntryDefinitionList( | 317 ConvertFileDefinitionListToEntryDefinitionList( |
321 profile, | 318 profile, |
322 extension_id, | 319 extension_id, |
323 file_definition_list, | 320 file_definition_list, |
324 base::Bind(&OnConvertFileDefinitionDone, callback)); | 321 base::Bind(&OnConvertFileDefinitionDone, callback)); |
325 } | 322 } |
326 | 323 |
327 } // namespace util | 324 } // namespace util |
328 } // namespace file_manager | 325 } // namespace file_manager |
OLD | NEW |