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/chromeos/file_manager/app_id.h" |
10 #include "chrome/browser/extensions/extension_util.h" | 11 #include "chrome/browser/extensions/extension_util.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
14 #include "content/public/browser/site_instance.h" | 15 #include "content/public/browser/site_instance.h" |
15 #include "content/public/browser/storage_partition.h" | 16 #include "content/public/browser/storage_partition.h" |
16 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
| 18 #include "google_apis/drive/task_util.h" |
17 #include "net/base/escape.h" | 19 #include "net/base/escape.h" |
18 #include "url/gurl.h" | 20 #include "url/gurl.h" |
19 #include "webkit/browser/fileapi/file_system_context.h" | 21 #include "webkit/browser/fileapi/file_system_context.h" |
20 #include "webkit/browser/fileapi/open_file_system_mode.h" | 22 #include "webkit/browser/fileapi/open_file_system_mode.h" |
21 #include "webkit/common/fileapi/file_system_util.h" | 23 #include "webkit/common/fileapi/file_system_util.h" |
22 | 24 |
23 using content::BrowserThread; | 25 using content::BrowserThread; |
24 | 26 |
25 namespace file_manager { | 27 namespace file_manager { |
26 namespace util { | 28 namespace util { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 206 |
205 // Helper function to return the converted definition entry directly, without | 207 // Helper function to return the converted definition entry directly, without |
206 // the redundant container. | 208 // the redundant container. |
207 void OnConvertFileDefinitionDone( | 209 void OnConvertFileDefinitionDone( |
208 const EntryDefinitionCallback& callback, | 210 const EntryDefinitionCallback& callback, |
209 scoped_ptr<EntryDefinitionList> entry_definition_list) { | 211 scoped_ptr<EntryDefinitionList> entry_definition_list) { |
210 DCHECK_EQ(1u, entry_definition_list->size()); | 212 DCHECK_EQ(1u, entry_definition_list->size()); |
211 callback.Run(entry_definition_list->at(0)); | 213 callback.Run(entry_definition_list->at(0)); |
212 } | 214 } |
213 | 215 |
| 216 // Used to implement CheckIfDirectoryExists(). |
| 217 void CheckIfDirectoryExistsOnIOThread( |
| 218 scoped_refptr<fileapi::FileSystemContext> file_system_context, |
| 219 const GURL& url, |
| 220 const fileapi::FileSystemOperationRunner::StatusCallback& callback) { |
| 221 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 222 |
| 223 fileapi::FileSystemURL file_system_url = file_system_context->CrackURL(url); |
| 224 file_system_context->operation_runner()->DirectoryExists( |
| 225 file_system_url, callback); |
| 226 } |
| 227 |
214 } // namespace | 228 } // namespace |
215 | 229 |
216 EntryDefinition::EntryDefinition() { | 230 EntryDefinition::EntryDefinition() { |
217 } | 231 } |
218 | 232 |
219 EntryDefinition::~EntryDefinition() { | 233 EntryDefinition::~EntryDefinition() { |
220 } | 234 } |
221 | 235 |
222 fileapi::FileSystemContext* GetFileSystemContextForExtensionId( | 236 fileapi::FileSystemContext* GetFileSystemContextForExtensionId( |
223 Profile* profile, | 237 Profile* profile, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 | 335 |
322 FileDefinitionList file_definition_list; | 336 FileDefinitionList file_definition_list; |
323 file_definition_list.push_back(file_definition); | 337 file_definition_list.push_back(file_definition); |
324 ConvertFileDefinitionListToEntryDefinitionList( | 338 ConvertFileDefinitionListToEntryDefinitionList( |
325 profile, | 339 profile, |
326 extension_id, | 340 extension_id, |
327 file_definition_list, | 341 file_definition_list, |
328 base::Bind(&OnConvertFileDefinitionDone, callback)); | 342 base::Bind(&OnConvertFileDefinitionDone, callback)); |
329 } | 343 } |
330 | 344 |
| 345 void CheckIfDirectoryExists( |
| 346 scoped_refptr<fileapi::FileSystemContext> file_system_context, |
| 347 const GURL& url, |
| 348 const fileapi::FileSystemOperationRunner::StatusCallback& callback) { |
| 349 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 350 |
| 351 // Check the existence of directory using file system API implementation on |
| 352 // behalf of the file manager app. We need to grant access beforehand. |
| 353 fileapi::ExternalFileSystemBackend* backend = |
| 354 file_system_context->external_backend(); |
| 355 DCHECK(backend); |
| 356 backend->GrantFullAccessToExtension(kFileManagerAppId); |
| 357 |
| 358 BrowserThread::PostTask( |
| 359 BrowserThread::IO, FROM_HERE, |
| 360 base::Bind(&CheckIfDirectoryExistsOnIOThread, |
| 361 file_system_context, |
| 362 url, |
| 363 google_apis::CreateRelayCallback(callback))); |
| 364 } |
| 365 |
331 } // namespace util | 366 } // namespace util |
332 } // namespace file_manager | 367 } // namespace file_manager |
OLD | NEW |