Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: chrome/browser/chromeos/file_system_provider/provided_file_system.cc

Issue 679573002: [fsp] Separate recursive and non-recursive watchers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_system_provider/provided_file_system.h" 5 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/files/file.h" 10 #include "base/files/file.h"
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 return base::Bind( 356 return base::Bind(
357 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); 357 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id);
358 } 358 }
359 359
360 ProvidedFileSystem::AbortCallback ProvidedFileSystem::ObserveDirectory( 360 ProvidedFileSystem::AbortCallback ProvidedFileSystem::ObserveDirectory(
361 const base::FilePath& directory_path, 361 const base::FilePath& directory_path,
362 bool recursive, 362 bool recursive,
363 const storage::AsyncFileUtil::StatusCallback& callback) { 363 const storage::AsyncFileUtil::StatusCallback& callback) {
364 // TODO(mtomasz): Wrap the entire method body with an asynchronous queue to 364 // TODO(mtomasz): Wrap the entire method body with an asynchronous queue to
365 // avoid races. 365 // avoid races.
366 const ObservedEntries::const_iterator it = 366 const ObservedEntryKey key(directory_path, recursive);
367 observed_entries_.find(directory_path); 367 const ObservedEntries::const_iterator it = observed_entries_.find(key);
368 if (it != observed_entries_.end()) { 368 if (it != observed_entries_.end()) {
369 if (!recursive || it->second.recursive) { 369 OnObserveDirectoryCompleted(
370 callback.Run(base::File::FILE_ERROR_EXISTS); 370 directory_path, recursive, callback, base::File::FILE_ERROR_EXISTS);
371 return AbortCallback(); 371 return AbortCallback();
372 }
373 } 372 }
374 373
375 const int request_id = request_manager_->CreateRequest( 374 const int request_id = request_manager_->CreateRequest(
376 OBSERVE_DIRECTORY, 375 OBSERVE_DIRECTORY,
377 scoped_ptr<RequestManager::HandlerInterface>( 376 scoped_ptr<RequestManager::HandlerInterface>(
378 new operations::ObserveDirectory( 377 new operations::ObserveDirectory(
379 event_router_, 378 event_router_,
380 file_system_info_, 379 file_system_info_,
381 directory_path, 380 directory_path,
382 recursive, 381 recursive,
383 base::Bind(&ProvidedFileSystem::OnObserveDirectoryCompleted, 382 base::Bind(&ProvidedFileSystem::OnObserveDirectoryCompleted,
384 weak_ptr_factory_.GetWeakPtr(), 383 weak_ptr_factory_.GetWeakPtr(),
385 directory_path, 384 directory_path,
386 recursive, 385 recursive,
387 callback)))); 386 callback))));
388 if (!request_id) { 387 if (!request_id) {
389 callback.Run(base::File::FILE_ERROR_SECURITY); 388 callback.Run(base::File::FILE_ERROR_SECURITY);
390 return AbortCallback(); 389 return AbortCallback();
391 } 390 }
392 391
393 return base::Bind( 392 return base::Bind(
394 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id); 393 &ProvidedFileSystem::Abort, weak_ptr_factory_.GetWeakPtr(), request_id);
395 } 394 }
396 395
397 void ProvidedFileSystem::UnobserveEntry( 396 void ProvidedFileSystem::UnobserveEntry(
398 const base::FilePath& entry_path, 397 const base::FilePath& entry_path,
398 bool recursive,
399 const storage::AsyncFileUtil::StatusCallback& callback) { 399 const storage::AsyncFileUtil::StatusCallback& callback) {
400 const ObservedEntries::const_iterator it = observed_entries_.find(entry_path); 400 const ObservedEntryKey key(entry_path, recursive);
401 const ObservedEntries::const_iterator it = observed_entries_.find(key);
401 if (it == observed_entries_.end()) { 402 if (it == observed_entries_.end()) {
402 callback.Run(base::File::FILE_ERROR_NOT_FOUND); 403 callback.Run(base::File::FILE_ERROR_NOT_FOUND);
403 return; 404 return;
404 } 405 }
405 406
406 // Delete the watcher in advance since the list of observed entries is owned 407 // Delete the watcher in advance since the list of observed entries is owned
407 // by the C++ layer, not by the extension. 408 // by the C++ layer, not by the extension.
408 observed_entries_.erase(it); 409 observed_entries_.erase(it);
409 410
410 FOR_EACH_OBSERVER( 411 FOR_EACH_OBSERVER(
(...skipping 30 matching lines...) Expand all
441 observers_.AddObserver(observer); 442 observers_.AddObserver(observer);
442 } 443 }
443 444
444 void ProvidedFileSystem::RemoveObserver(ProvidedFileSystemObserver* observer) { 445 void ProvidedFileSystem::RemoveObserver(ProvidedFileSystemObserver* observer) {
445 DCHECK(observer); 446 DCHECK(observer);
446 observers_.RemoveObserver(observer); 447 observers_.RemoveObserver(observer);
447 } 448 }
448 449
449 bool ProvidedFileSystem::Notify( 450 bool ProvidedFileSystem::Notify(
450 const base::FilePath& observed_path, 451 const base::FilePath& observed_path,
452 bool recursive,
451 ProvidedFileSystemObserver::ChangeType change_type, 453 ProvidedFileSystemObserver::ChangeType change_type,
452 scoped_ptr<ProvidedFileSystemObserver::ChildChanges> child_changes, 454 scoped_ptr<ProvidedFileSystemObserver::Changes> changes,
453 const std::string& tag) { 455 const std::string& tag) {
454 const ObservedEntries::iterator it = observed_entries_.find(observed_path); 456 const ObservedEntryKey key(observed_path, recursive);
457 const ObservedEntries::iterator it = observed_entries_.find(key);
455 if (it == observed_entries_.end()) 458 if (it == observed_entries_.end())
456 return false; 459 return false;
457 460
458 // The tag must be provided if and only if it's explicitly supported. 461 // The tag must be provided if and only if it's explicitly supported.
459 if (file_system_info_.supports_notify_tag() == tag.empty()) 462 if (file_system_info_.supports_notify_tag() == tag.empty())
460 return false; 463 return false;
461 464
462 // The object is owned by AutoUpdated, so the reference is valid as long as 465 // The object is owned by AutoUpdated, so the reference is valid as long as
463 // callbacks created with AutoUpdater::CreateCallback(). 466 // callbacks created with AutoUpdater::CreateCallback().
464 const ProvidedFileSystemObserver::ChildChanges& child_changes_ref = 467 const ProvidedFileSystemObserver::Changes& changes_ref = *changes.get();
465 *child_changes.get();
466 468
467 scoped_refptr<AutoUpdater> auto_updater( 469 scoped_refptr<AutoUpdater> auto_updater(
468 new AutoUpdater(base::Bind(&ProvidedFileSystem::OnNotifyCompleted, 470 new AutoUpdater(base::Bind(&ProvidedFileSystem::OnNotifyCompleted,
469 weak_ptr_factory_.GetWeakPtr(), 471 weak_ptr_factory_.GetWeakPtr(),
470 observed_path, 472 observed_path,
473 recursive,
471 change_type, 474 change_type,
472 base::Passed(&child_changes), 475 base::Passed(&changes),
473 it->second.last_tag, 476 it->second.last_tag,
474 tag))); 477 tag)));
475 478
476 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, 479 FOR_EACH_OBSERVER(ProvidedFileSystemObserver,
477 observers_, 480 observers_,
478 OnObservedEntryChanged(file_system_info_, 481 OnObservedEntryChanged(file_system_info_,
479 it->second, 482 it->second,
480 change_type, 483 change_type,
481 child_changes_ref, 484 changes_ref,
482 auto_updater->CreateCallback())); 485 auto_updater->CreateCallback()));
483 486
484 return true; 487 return true;
485 } 488 }
486 489
487 base::WeakPtr<ProvidedFileSystemInterface> ProvidedFileSystem::GetWeakPtr() { 490 base::WeakPtr<ProvidedFileSystemInterface> ProvidedFileSystem::GetWeakPtr() {
488 return weak_ptr_factory_.GetWeakPtr(); 491 return weak_ptr_factory_.GetWeakPtr();
489 } 492 }
490 493
491 void ProvidedFileSystem::Abort( 494 void ProvidedFileSystem::Abort(
(...skipping 16 matching lines...) Expand all
508 void ProvidedFileSystem::OnObserveDirectoryCompleted( 511 void ProvidedFileSystem::OnObserveDirectoryCompleted(
509 const base::FilePath& directory_path, 512 const base::FilePath& directory_path,
510 bool recursive, 513 bool recursive,
511 const storage::AsyncFileUtil::StatusCallback& callback, 514 const storage::AsyncFileUtil::StatusCallback& callback,
512 base::File::Error result) { 515 base::File::Error result) {
513 if (result != base::File::FILE_OK) { 516 if (result != base::File::FILE_OK) {
514 callback.Run(result); 517 callback.Run(result);
515 return; 518 return;
516 } 519 }
517 520
518 observed_entries_[directory_path].entry_path = directory_path; 521 const ObservedEntryKey key(directory_path, recursive);
519 observed_entries_[directory_path].recursive |= recursive; 522 const ObservedEntries::iterator it = observed_entries_.find(key);
523 if (it != observed_entries_.end()) {
524 callback.Run(base::File::FILE_OK);
525 return;
526 }
527
528 observed_entries_[key].entry_path = directory_path;
529 observed_entries_[key].recursive = recursive;
520 530
521 FOR_EACH_OBSERVER( 531 FOR_EACH_OBSERVER(
522 ProvidedFileSystemObserver, 532 ProvidedFileSystemObserver,
523 observers_, 533 observers_,
524 OnObservedEntryListChanged(file_system_info_, observed_entries_)); 534 OnObservedEntryListChanged(file_system_info_, observed_entries_));
525 535
526 callback.Run(result); 536 callback.Run(base::File::FILE_OK);
527 } 537 }
528 538
529 void ProvidedFileSystem::OnNotifyCompleted( 539 void ProvidedFileSystem::OnNotifyCompleted(
530 const base::FilePath& observed_path, 540 const base::FilePath& observed_path,
541 bool recursive,
531 ProvidedFileSystemObserver::ChangeType change_type, 542 ProvidedFileSystemObserver::ChangeType change_type,
532 scoped_ptr<ProvidedFileSystemObserver::ChildChanges> /* child_changes */, 543 scoped_ptr<ProvidedFileSystemObserver::Changes> /* changes */,
533 const std::string& last_tag, 544 const std::string& last_tag,
534 const std::string& tag) { 545 const std::string& tag) {
535 const ObservedEntries::iterator it = observed_entries_.find(observed_path); 546 const ObservedEntryKey key(observed_path, recursive);
547 const ObservedEntries::iterator it = observed_entries_.find(key);
536 // Check if the entry is still observed. 548 // Check if the entry is still observed.
537 if (it == observed_entries_.end()) 549 if (it == observed_entries_.end())
538 return; 550 return;
539 551
540 // Another following notification finished earlier. 552 // Another following notification finished earlier.
541 if (it->second.last_tag != last_tag) 553 if (it->second.last_tag != last_tag)
542 return; 554 return;
543 555
544 // It's illegal to provide a tag which is not unique. As for now only an error 556 // It's illegal to provide a tag which is not unique. As for now only an error
545 // message is printed, but we may want to pass the error to the providing 557 // message is printed, but we may want to pass the error to the providing
546 // extension. TODO(mtomasz): Consider it. 558 // extension. TODO(mtomasz): Consider it.
547 if (!tag.empty() && tag == it->second.last_tag) 559 if (!tag.empty() && tag == it->second.last_tag)
548 LOG(ERROR) << "Tag specified, but same as the previous one."; 560 LOG(ERROR) << "Tag specified, but same as the previous one.";
549 561
550 it->second.last_tag = tag; 562 it->second.last_tag = tag;
551 563
552 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, 564 FOR_EACH_OBSERVER(ProvidedFileSystemObserver,
553 observers_, 565 observers_,
554 OnObservedEntryTagUpdated(file_system_info_, it->second)); 566 OnObservedEntryTagUpdated(file_system_info_, it->second));
555 567
556 // If the observed entry is deleted, then unobserve it. 568 // If the observed entry is deleted, then unobserve it.
557 if (change_type == ProvidedFileSystemObserver::DELETED) 569 if (change_type == ProvidedFileSystemObserver::DELETED)
558 UnobserveEntry(observed_path, base::Bind(&EmptyStatusCallback)); 570 UnobserveEntry(observed_path, recursive, base::Bind(&EmptyStatusCallback));
559 } 571 }
560 572
561 } // namespace file_system_provider 573 } // namespace file_system_provider
562 } // namespace chromeos 574 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698