Chromium Code Reviews| 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/extensions/file_manager/private_api_file_syste m.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/private_api_file_syste m.h" |
| 6 | 6 |
| 7 #include <sys/statvfs.h> | 7 #include <sys/statvfs.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | |
| 11 #include <utility> | 10 #include <utility> |
| 12 #include <vector> | |
| 13 | 11 |
| 14 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 15 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/weak_ptr.h" | |
| 17 #include "base/posix/eintr_wrapper.h" | 14 #include "base/posix/eintr_wrapper.h" |
| 18 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 20 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
| 21 #include "base/task_runner_util.h" | 18 #include "base/task_runner_util.h" |
| 22 #include "base/task_scheduler/post_task.h" | 19 #include "base/task_scheduler/post_task.h" |
| 23 #include "base/threading/sequenced_worker_pool.h" | 20 #include "base/threading/sequenced_worker_pool.h" |
| 24 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chromeos/drive/file_system_util.h" | 22 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 26 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" | 23 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 backend->GrantFileAccessToExtension(extension_->id(), | 297 backend->GrantFileAccessToExtension(extension_->id(), |
| 301 file_system_url.virtual_path()); | 298 file_system_url.virtual_path()); |
| 302 content::ChildProcessSecurityPolicy::GetInstance() | 299 content::ChildProcessSecurityPolicy::GetInstance() |
| 303 ->GrantCreateReadWriteFile(render_frame_host()->GetProcess()->GetID(), | 300 ->GrantCreateReadWriteFile(render_frame_host()->GetProcess()->GetID(), |
| 304 file_system_url.path()); | 301 file_system_url.path()); |
| 305 } | 302 } |
| 306 } | 303 } |
| 307 return RespondNow(NoArguments()); | 304 return RespondNow(NoArguments()); |
| 308 } | 305 } |
| 309 | 306 |
| 307 namespace { | |
| 308 | |
| 309 void CallResponseCallbackOnUIThread( | |
| 310 const FileWatchFunctionBase::ResponseCallback& callback, | |
| 311 bool success) { | |
| 312 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 313 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 314 base::Bind(callback, success)); | |
| 315 } | |
| 316 | |
| 317 void CallNotificationCallbackOnUIThread( | |
| 318 const storage::WatcherManager::NotificationCallback& callback, | |
| 319 storage::WatcherManager::ChangeType type) { | |
| 320 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 321 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 322 base::Bind(callback, type)); | |
| 323 } | |
| 324 | |
| 325 } // namespace | |
| 326 | |
| 310 void FileWatchFunctionBase::Respond(bool success) { | 327 void FileWatchFunctionBase::Respond(bool success) { |
| 311 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 328 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 312 | 329 |
| 313 SetResult(base::MakeUnique<base::FundamentalValue>(success)); | 330 SetResult(base::MakeUnique<base::FundamentalValue>(success)); |
| 314 SendResponse(success); | 331 SendResponse(success); |
| 315 } | 332 } |
| 316 | 333 |
| 317 bool FileWatchFunctionBase::RunAsync() { | 334 bool FileWatchFunctionBase::RunAsync() { |
| 318 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 335 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 319 | 336 |
| 320 if (!render_frame_host() || !render_frame_host()->GetProcess()) | 337 if (!render_frame_host() || !render_frame_host()->GetProcess()) |
| 321 return false; | 338 return false; |
| 322 | 339 |
| 323 // First param is url of a file to watch. | 340 // First param is url of a file to watch. |
| 324 std::string url; | 341 std::string url; |
| 325 if (!args_->GetString(0, &url) || url.empty()) | 342 if (!args_->GetString(0, &url) || url.empty()) |
| 326 return false; | 343 return false; |
| 327 | 344 |
| 328 scoped_refptr<storage::FileSystemContext> file_system_context = | 345 scoped_refptr<storage::FileSystemContext> file_system_context = |
| 329 file_manager::util::GetFileSystemContextForRenderFrameHost( | 346 file_manager::util::GetFileSystemContextForRenderFrameHost( |
| 330 GetProfile(), render_frame_host()); | 347 GetProfile(), render_frame_host()); |
| 331 | 348 |
| 332 const FileSystemURL file_system_url = | 349 const FileSystemURL file_system_url = |
| 333 file_system_context->CrackURL(GURL(url)); | 350 file_system_context->CrackURL(GURL(url)); |
| 334 if (file_system_url.path().empty()) { | 351 if (file_system_url.path().empty()) { |
| 335 Respond(false); | 352 Respond(false); |
| 336 return true; | 353 return true; |
| 337 } | 354 } |
| 338 | 355 |
| 339 PerformFileWatchOperation(file_system_context, file_system_url, | |
| 340 extension_id()); | |
| 341 return true; | |
| 342 } | |
| 343 | |
| 344 void FileManagerPrivateInternalAddFileWatchFunction::PerformFileWatchOperation( | |
| 345 scoped_refptr<storage::FileSystemContext> file_system_context, | |
| 346 const storage::FileSystemURL& file_system_url, | |
| 347 const std::string& extension_id) { | |
| 348 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 349 | |
| 350 file_manager::EventRouter* const event_router = | 356 file_manager::EventRouter* const event_router = |
| 351 file_manager::EventRouterFactory::GetForProfile(GetProfile()); | 357 file_manager::EventRouterFactory::GetForProfile(GetProfile()); |
| 352 | 358 |
| 359 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
| 360 base::Bind(&FileWatchFunctionBase::RunAsyncOnIOThread, | |
| 361 this, file_system_context, file_system_url, | |
| 362 event_router->GetWeakPtr())); | |
| 363 return true; | |
| 364 } | |
| 365 | |
| 366 void FileWatchFunctionBase::RunAsyncOnIOThread( | |
| 367 scoped_refptr<storage::FileSystemContext> file_system_context, | |
| 368 const storage::FileSystemURL& file_system_url, | |
| 369 base::WeakPtr<file_manager::EventRouter> event_router) { | |
| 370 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 371 | |
| 353 storage::WatcherManager* const watcher_manager = | 372 storage::WatcherManager* const watcher_manager = |
| 354 file_system_context->GetWatcherManager(file_system_url.type()); | 373 file_system_context->GetWatcherManager(file_system_url.type()); |
| 355 if (watcher_manager) { | 374 |
| 356 watcher_manager->AddWatcher( | 375 if (!watcher_manager) { |
| 357 file_system_url, false /* recursive */, | 376 BrowserThread::PostTask( |
| 377 BrowserThread::UI, FROM_HERE, | |
| 358 base::Bind( | 378 base::Bind( |
| 359 &StatusCallbackToResponseCallback, | 379 &FileWatchFunctionBase::PerformFallbackFileWatchOperationOnUIThread, |
| 360 base::Bind(&FileManagerPrivateInternalAddFileWatchFunction::Respond, | 380 this, file_system_url, event_router)); |
| 361 this)), | |
| 362 base::Bind(&file_manager::EventRouter::OnWatcherManagerNotification, | |
| 363 event_router->GetWeakPtr(), file_system_url, extension_id)); | |
| 364 return; | 381 return; |
| 365 } | 382 } |
| 366 | 383 |
| 384 PerformFileWatchOperationOnIOThread(file_system_context, watcher_manager, | |
| 385 file_system_url, event_router); | |
| 386 } | |
| 387 | |
| 388 void FileManagerPrivateInternalAddFileWatchFunction:: | |
| 389 PerformFileWatchOperationOnIOThread( | |
| 390 scoped_refptr<storage::FileSystemContext> file_system_context, | |
| 391 storage::WatcherManager* watcher_manager, | |
| 392 const storage::FileSystemURL& file_system_url, | |
| 393 base::WeakPtr<file_manager::EventRouter> event_router) { | |
| 394 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 395 | |
| 396 watcher_manager->AddWatcher( | |
| 397 file_system_url, false /* recursive */, | |
| 398 base::Bind(&StatusCallbackToResponseCallback, | |
| 399 base::Bind(&CallResponseCallbackOnUIThread, | |
| 400 base::Bind(&FileWatchFunctionBase::Respond, this))), | |
| 401 base::Bind( | |
| 402 &CallNotificationCallbackOnUIThread, | |
| 403 base::Bind(&file_manager::EventRouter::OnWatcherManagerNotification, | |
| 404 event_router, file_system_url, extension_id()))); | |
| 405 } | |
| 406 | |
| 407 void FileManagerPrivateInternalAddFileWatchFunction:: | |
| 408 PerformFallbackFileWatchOperationOnUIThread( | |
| 409 const storage::FileSystemURL& file_system_url, | |
| 410 base::WeakPtr<file_manager::EventRouter> event_router) { | |
| 411 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 412 DCHECK(event_router); | |
| 413 | |
| 367 // Obsolete. Fallback code if storage::WatcherManager is not implemented. | 414 // Obsolete. Fallback code if storage::WatcherManager is not implemented. |
| 368 event_router->AddFileWatch( | 415 event_router->AddFileWatch(file_system_url.path(), |
| 369 file_system_url.path(), file_system_url.virtual_path(), extension_id, | 416 file_system_url.virtual_path(), extension_id(), |
| 370 base::Bind(&FileManagerPrivateInternalAddFileWatchFunction::Respond, | 417 base::Bind(&FileWatchFunctionBase::Respond, this)); |
| 371 this)); | |
| 372 } | 418 } |
| 373 | 419 |
| 374 void FileManagerPrivateInternalRemoveFileWatchFunction:: | 420 void FileManagerPrivateInternalRemoveFileWatchFunction:: |
| 375 PerformFileWatchOperation( | 421 PerformFileWatchOperationOnIOThread( |
| 376 scoped_refptr<storage::FileSystemContext> file_system_context, | 422 scoped_refptr<storage::FileSystemContext> file_system_context, |
| 423 storage::WatcherManager* watcher_manager, | |
| 377 const storage::FileSystemURL& file_system_url, | 424 const storage::FileSystemURL& file_system_url, |
| 378 const std::string& extension_id) { | 425 base::WeakPtr<file_manager::EventRouter> event_router) { |
|
tzik
2017/02/23 03:57:18
|event_router| is not used?
Shuhei Takahashi
2017/02/23 04:05:57
It is not used in FileManagerPrivateInternalRemove
| |
| 426 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 427 | |
| 428 watcher_manager->RemoveWatcher( | |
| 429 file_system_url, false /* recursive */, | |
| 430 base::Bind( | |
| 431 &StatusCallbackToResponseCallback, | |
| 432 base::Bind(&CallResponseCallbackOnUIThread, | |
| 433 base::Bind(&FileWatchFunctionBase::Respond, this)))); | |
| 434 } | |
| 435 | |
| 436 void FileManagerPrivateInternalRemoveFileWatchFunction:: | |
| 437 PerformFallbackFileWatchOperationOnUIThread( | |
| 438 const storage::FileSystemURL& file_system_url, | |
| 439 base::WeakPtr<file_manager::EventRouter> event_router) { | |
| 379 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 440 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 380 | 441 DCHECK(event_router); |
| 381 file_manager::EventRouter* const event_router = | |
| 382 file_manager::EventRouterFactory::GetForProfile(GetProfile()); | |
| 383 | |
| 384 storage::WatcherManager* const watcher_manager = | |
| 385 file_system_context->GetWatcherManager(file_system_url.type()); | |
| 386 if (watcher_manager) { | |
| 387 watcher_manager->RemoveWatcher( | |
| 388 file_system_url, false /* recursive */, | |
| 389 base::Bind(&StatusCallbackToResponseCallback, | |
| 390 base::Bind(&FileWatchFunctionBase::Respond, this))); | |
| 391 return; | |
| 392 } | |
| 393 | 442 |
| 394 // Obsolete. Fallback code if storage::WatcherManager is not implemented. | 443 // Obsolete. Fallback code if storage::WatcherManager is not implemented. |
| 395 event_router->RemoveFileWatch(file_system_url.path(), extension_id); | 444 event_router->RemoveFileWatch(file_system_url.path(), extension_id()); |
| 396 Respond(true); | 445 Respond(true); |
| 397 } | 446 } |
| 398 | 447 |
| 399 bool FileManagerPrivateGetSizeStatsFunction::RunAsync() { | 448 bool FileManagerPrivateGetSizeStatsFunction::RunAsync() { |
| 400 using extensions::api::file_manager_private::GetSizeStats::Params; | 449 using extensions::api::file_manager_private::GetSizeStats::Params; |
| 401 const std::unique_ptr<Params> params(Params::Create(*args_)); | 450 const std::unique_ptr<Params> params(Params::Create(*args_)); |
| 402 EXTENSION_FUNCTION_VALIDATE(params); | 451 EXTENSION_FUNCTION_VALIDATE(params); |
| 403 | 452 |
| 404 using file_manager::VolumeManager; | 453 using file_manager::VolumeManager; |
| 405 using file_manager::Volume; | 454 using file_manager::Volume; |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1002 } | 1051 } |
| 1003 | 1052 |
| 1004 void FileManagerPrivateInternalGetDirectorySizeFunction:: | 1053 void FileManagerPrivateInternalGetDirectorySizeFunction:: |
| 1005 OnDirectorySizeRetrieved(int64_t size) { | 1054 OnDirectorySizeRetrieved(int64_t size) { |
| 1006 SetResult( | 1055 SetResult( |
| 1007 base::MakeUnique<base::FundamentalValue>(static_cast<double>(size))); | 1056 base::MakeUnique<base::FundamentalValue>(static_cast<double>(size))); |
| 1008 SendResponse(true); | 1057 SendResponse(true); |
| 1009 } | 1058 } |
| 1010 | 1059 |
| 1011 } // namespace extensions | 1060 } // namespace extensions |
| OLD | NEW |