OLD | NEW |
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 "chrome/browser/chromeos/file_manager/open_util.h" | 5 #include "chrome/browser/chromeos/file_manager/open_util.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 OpenFileManagerWithInternalActionId(profile, url, "open"); | 166 OpenFileManagerWithInternalActionId(profile, url, "open"); |
167 } else { | 167 } else { |
168 // |url| should be a file. Open it. | 168 // |url| should be a file. Open it. |
169 OpenFile(profile, | 169 OpenFile(profile, |
170 file_path, | 170 file_path, |
171 url, | 171 url, |
172 base::Bind(&OnContinueOpenItemCompleted, profile, file_path)); | 172 base::Bind(&OnContinueOpenItemCompleted, profile, file_path)); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 // Converts the |given_path| passed from external callers to the form that the | 176 // Converts the |path| passed from external callers to the filesystem URL |
177 // file manager can correctly handle. It first migrates old Drive/Download | 177 // that the file manager can correctly handle. |
178 // folder path to the new formats, and then converts path to filesystem URL. | |
179 // | 178 // |
180 // When conversion fails, it shows a warning dialog UI and returns false. | 179 // When conversion fails, it shows a warning dialog UI and returns false. |
181 bool ConvertPath(Profile* profile, | 180 bool ConvertPath(Profile* profile, const base::FilePath& path, GURL* url) { |
182 const base::FilePath& given_path, | |
183 base::FilePath* path, | |
184 GURL* url) { | |
185 // The path may have been stored in preferences in old versions. | |
186 // We need migration here. | |
187 // TODO(kinaba): crbug.com/313539 remove it in the future. | |
188 if (!util::MigratePathFromOldFormat(profile, given_path, path)) | |
189 *path = given_path; | |
190 | |
191 if (!ConvertAbsoluteFilePathToFileSystemUrl( | 181 if (!ConvertAbsoluteFilePathToFileSystemUrl( |
192 profile, *path, kFileManagerAppId, url)) { | 182 profile, path, kFileManagerAppId, url)) { |
193 ShowWarningMessageBox(profile, *path, | 183 ShowWarningMessageBox(profile, path, |
194 IDS_FILE_BROWSER_ERROR_UNRESOLVABLE_FILE); | 184 IDS_FILE_BROWSER_ERROR_UNRESOLVABLE_FILE); |
195 return false; | 185 return false; |
196 } | 186 } |
197 return true; | 187 return true; |
198 } | 188 } |
199 | 189 |
200 } // namespace | 190 } // namespace |
201 | 191 |
202 void OpenRemovableDrive(Profile* profile, const base::FilePath& file_path) { | 192 void OpenRemovableDrive(Profile* profile, const base::FilePath& file_path) { |
203 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 193 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
204 | 194 |
205 base::FilePath converted_path; | |
206 GURL url; | 195 GURL url; |
207 if (!ConvertPath(profile, file_path, &converted_path, &url)) | 196 if (!ConvertPath(profile, file_path, &url)) |
208 return; | 197 return; |
209 | 198 |
210 OpenFileManagerWithInternalActionId(profile, url, "auto-open"); | 199 OpenFileManagerWithInternalActionId(profile, url, "auto-open"); |
211 } | 200 } |
212 | 201 |
213 void OpenItem(Profile* profile, const base::FilePath& file_path) { | 202 void OpenItem(Profile* profile, const base::FilePath& file_path) { |
214 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 203 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
215 | 204 |
216 base::FilePath converted_path; | |
217 GURL url; | 205 GURL url; |
218 if (!ConvertPath(profile, file_path, &converted_path, &url)) | 206 if (!ConvertPath(profile, file_path, &url)) |
219 return; | 207 return; |
220 | 208 |
221 CheckIfDirectoryExists( | 209 CheckIfDirectoryExists( |
222 GetFileSystemContextForExtensionId(profile, kFileManagerAppId), | 210 GetFileSystemContextForExtensionId(profile, kFileManagerAppId), |
223 url, | 211 url, |
224 base::Bind(&ContinueOpenItem, profile, converted_path, url)); | 212 base::Bind(&ContinueOpenItem, profile, file_path, url)); |
225 } | 213 } |
226 | 214 |
227 void ShowItemInFolder(Profile* profile, const base::FilePath& file_path) { | 215 void ShowItemInFolder(Profile* profile, const base::FilePath& file_path) { |
228 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 216 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
229 | 217 |
230 base::FilePath converted_path; | |
231 GURL url; | 218 GURL url; |
232 if (!ConvertPath(profile, file_path, &converted_path, &url)) | 219 if (!ConvertPath(profile, file_path, &url)) |
233 return; | 220 return; |
234 | 221 |
235 // This action changes the selection so we do not reuse existing tabs. | 222 // This action changes the selection so we do not reuse existing tabs. |
236 OpenFileManagerWithInternalActionId(profile, url, "select"); | 223 OpenFileManagerWithInternalActionId(profile, url, "select"); |
237 } | 224 } |
238 | 225 |
239 } // namespace util | 226 } // namespace util |
240 } // namespace file_manager | 227 } // namespace file_manager |
OLD | NEW |