| 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" |
| 11 #include "chrome/browser/chromeos/drive/file_system_util.h" | 11 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 12 #include "chrome/browser/chromeos/file_manager/app_id.h" | 12 #include "chrome/browser/chromeos/file_manager/app_id.h" |
| 13 #include "chrome/browser/chromeos/file_manager/file_tasks.h" | 13 #include "chrome/browser/chromeos/file_manager/file_tasks.h" |
| 14 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" | 14 #include "chrome/browser/chromeos/file_manager/fileapi_util.h" |
| 15 #include "chrome/browser/chromeos/file_manager/mime_util.h" | 15 #include "chrome/browser/chromeos/file_manager/mime_util.h" |
| 16 #include "chrome/browser/chromeos/file_manager/path_util.h" | 16 #include "chrome/browser/chromeos/file_manager/path_util.h" |
| 17 #include "chrome/browser/chromeos/file_manager/url_util.h" | 17 #include "chrome/browser/chromeos/file_manager/url_util.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
| 20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 21 #include "chrome/browser/ui/simple_message_box.h" | 21 #include "chrome/browser/ui/simple_message_box.h" |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/user_metrics.h" | 23 #include "content/public/browser/user_metrics.h" |
| 24 #include "google_apis/drive/task_util.h" | |
| 25 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "webkit/browser/fileapi/file_system_backend.h" | 26 #include "webkit/browser/fileapi/file_system_backend.h" |
| 28 #include "webkit/browser/fileapi/file_system_context.h" | 27 #include "webkit/browser/fileapi/file_system_context.h" |
| 29 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 28 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
| 30 #include "webkit/browser/fileapi/file_system_url.h" | 29 #include "webkit/browser/fileapi/file_system_url.h" |
| 31 | 30 |
| 32 using content::BrowserThread; | 31 using content::BrowserThread; |
| 33 using fileapi::FileSystemURL; | 32 using fileapi::FileSystemURL; |
| 34 | 33 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 OpenFileManagerWithInternalActionId(profile, url, "open"); | 136 OpenFileManagerWithInternalActionId(profile, url, "open"); |
| 138 } else { | 137 } else { |
| 139 // |url| should be a file. Open it. | 138 // |url| should be a file. Open it. |
| 140 if (!OpenFile(profile, file_path, url)) { | 139 if (!OpenFile(profile, file_path, url)) { |
| 141 ShowWarningMessageBox(profile, file_path, | 140 ShowWarningMessageBox(profile, file_path, |
| 142 IDS_FILE_BROWSER_ERROR_VIEWING_FILE); | 141 IDS_FILE_BROWSER_ERROR_VIEWING_FILE); |
| 143 } | 142 } |
| 144 } | 143 } |
| 145 } | 144 } |
| 146 | 145 |
| 147 // Used to implement CheckIfDirectoryExists(). | |
| 148 void CheckIfDirectoryExistsOnIOThread( | |
| 149 scoped_refptr<fileapi::FileSystemContext> file_system_context, | |
| 150 const GURL& url, | |
| 151 const fileapi::FileSystemOperationRunner::StatusCallback& callback) { | |
| 152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 153 | |
| 154 fileapi::FileSystemURL file_system_url = file_system_context->CrackURL(url); | |
| 155 file_system_context->operation_runner()->DirectoryExists( | |
| 156 file_system_url, callback); | |
| 157 } | |
| 158 | |
| 159 // Checks if a directory exists at |url|. | |
| 160 void CheckIfDirectoryExists( | |
| 161 scoped_refptr<fileapi::FileSystemContext> file_system_context, | |
| 162 const GURL& url, | |
| 163 const fileapi::FileSystemOperationRunner::StatusCallback& callback) { | |
| 164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 165 | |
| 166 // Check the existence of directory using file system API implementation on | |
| 167 // behalf of the file manager app. We need to grant access beforehand. | |
| 168 fileapi::ExternalFileSystemBackend* backend = | |
| 169 file_system_context->external_backend(); | |
| 170 DCHECK(backend); | |
| 171 backend->GrantFullAccessToExtension(kFileManagerAppId); | |
| 172 | |
| 173 BrowserThread::PostTask( | |
| 174 BrowserThread::IO, FROM_HERE, | |
| 175 base::Bind(&CheckIfDirectoryExistsOnIOThread, | |
| 176 file_system_context, | |
| 177 url, | |
| 178 google_apis::CreateRelayCallback(callback))); | |
| 179 } | |
| 180 | |
| 181 // Converts the |given_path| passed from external callers to the form that the | 146 // Converts the |given_path| passed from external callers to the form that the |
| 182 // file manager can correctly handle. It first migrates old Drive/Download | 147 // file manager can correctly handle. It first migrates old Drive/Download |
| 183 // folder path to the new formats, and then converts path to filesystem URL. | 148 // folder path to the new formats, and then converts path to filesystem URL. |
| 184 // | 149 // |
| 185 // When conversion fails, it shows a warning dialog UI and returns false. | 150 // When conversion fails, it shows a warning dialog UI and returns false. |
| 186 bool ConvertPath(Profile* profile, | 151 bool ConvertPath(Profile* profile, |
| 187 const base::FilePath& given_path, | 152 const base::FilePath& given_path, |
| 188 base::FilePath* path, | 153 base::FilePath* path, |
| 189 GURL* url) { | 154 GURL* url) { |
| 190 // The path may have been stored in preferences in old versions. | 155 // The path may have been stored in preferences in old versions. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 GURL url; | 201 GURL url; |
| 237 if (!ConvertPath(profile, file_path, &converted_path, &url)) | 202 if (!ConvertPath(profile, file_path, &converted_path, &url)) |
| 238 return; | 203 return; |
| 239 | 204 |
| 240 // This action changes the selection so we do not reuse existing tabs. | 205 // This action changes the selection so we do not reuse existing tabs. |
| 241 OpenFileManagerWithInternalActionId(profile, url, "select"); | 206 OpenFileManagerWithInternalActionId(profile, url, "select"); |
| 242 } | 207 } |
| 243 | 208 |
| 244 } // namespace util | 209 } // namespace util |
| 245 } // namespace file_manager | 210 } // namespace file_manager |
| OLD | NEW |