| OLD | NEW |
| 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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 const ObservedEntries::const_iterator it = observed_entries_.find(entry_path); | 400 const ObservedEntries::const_iterator it = observed_entries_.find(entry_path); |
| 401 if (it == observed_entries_.end()) { | 401 if (it == observed_entries_.end()) { |
| 402 callback.Run(base::File::FILE_ERROR_NOT_FOUND); | 402 callback.Run(base::File::FILE_ERROR_NOT_FOUND); |
| 403 return; | 403 return; |
| 404 } | 404 } |
| 405 | 405 |
| 406 // Delete the watcher in advance since the list of observed entries is owned | 406 // Delete the watcher in advance since the list of observed entries is owned |
| 407 // by the C++ layer, not by the extension. | 407 // by the C++ layer, not by the extension. |
| 408 observed_entries_.erase(it); | 408 observed_entries_.erase(it); |
| 409 | 409 |
| 410 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, | 410 FOR_EACH_OBSERVER( |
| 411 observers_, | 411 ProvidedFileSystemObserver, |
| 412 OnObservedEntryListChanged(file_system_info_)); | 412 observers_, |
| 413 OnObservedEntryListChanged(file_system_info_, observed_entries_)); |
| 413 | 414 |
| 414 // TODO(mtomasz): Consider returning always an OK error code, since for the | 415 // TODO(mtomasz): Consider returning always an OK error code, since for the |
| 415 // callers it's important that the entry is not watched anymore. The watcher | 416 // callers it's important that the entry is not watched anymore. The watcher |
| 416 // is removed even if the extension returns an error. | 417 // is removed even if the extension returns an error. |
| 417 const int request_id = request_manager_->CreateRequest( | 418 const int request_id = request_manager_->CreateRequest( |
| 418 UNOBSERVE_ENTRY, | 419 UNOBSERVE_ENTRY, |
| 419 scoped_ptr<RequestManager::HandlerInterface>( | 420 scoped_ptr<RequestManager::HandlerInterface>( |
| 420 new operations::UnobserveEntry( | 421 new operations::UnobserveEntry( |
| 421 event_router_, file_system_info_, entry_path, callback))); | 422 event_router_, file_system_info_, entry_path, callback))); |
| 422 if (!request_id) | 423 if (!request_id) |
| 423 callback.Run(base::File::FILE_ERROR_SECURITY); | 424 callback.Run(base::File::FILE_ERROR_SECURITY); |
| 424 } | 425 } |
| 425 | 426 |
| 426 const ProvidedFileSystemInfo& ProvidedFileSystem::GetFileSystemInfo() const { | 427 const ProvidedFileSystemInfo& ProvidedFileSystem::GetFileSystemInfo() const { |
| 427 return file_system_info_; | 428 return file_system_info_; |
| 428 } | 429 } |
| 429 | 430 |
| 430 RequestManager* ProvidedFileSystem::GetRequestManager() { | 431 RequestManager* ProvidedFileSystem::GetRequestManager() { |
| 431 return request_manager_.get(); | 432 return request_manager_.get(); |
| 432 } | 433 } |
| 433 | 434 |
| 434 ProvidedFileSystem::ObservedEntries* ProvidedFileSystem::GetObservedEntries() { | 435 ObservedEntries* ProvidedFileSystem::GetObservedEntries() { |
| 435 return &observed_entries_; | 436 return &observed_entries_; |
| 436 } | 437 } |
| 437 | 438 |
| 438 void ProvidedFileSystem::AddObserver(ProvidedFileSystemObserver* observer) { | 439 void ProvidedFileSystem::AddObserver(ProvidedFileSystemObserver* observer) { |
| 439 DCHECK(observer); | 440 DCHECK(observer); |
| 440 observers_.AddObserver(observer); | 441 observers_.AddObserver(observer); |
| 441 } | 442 } |
| 442 | 443 |
| 443 void ProvidedFileSystem::RemoveObserver(ProvidedFileSystemObserver* observer) { | 444 void ProvidedFileSystem::RemoveObserver(ProvidedFileSystemObserver* observer) { |
| 444 DCHECK(observer); | 445 DCHECK(observer); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 const storage::AsyncFileUtil::StatusCallback& callback, | 511 const storage::AsyncFileUtil::StatusCallback& callback, |
| 511 base::File::Error result) { | 512 base::File::Error result) { |
| 512 if (result != base::File::FILE_OK) { | 513 if (result != base::File::FILE_OK) { |
| 513 callback.Run(result); | 514 callback.Run(result); |
| 514 return; | 515 return; |
| 515 } | 516 } |
| 516 | 517 |
| 517 observed_entries_[directory_path].entry_path = directory_path; | 518 observed_entries_[directory_path].entry_path = directory_path; |
| 518 observed_entries_[directory_path].recursive |= recursive; | 519 observed_entries_[directory_path].recursive |= recursive; |
| 519 | 520 |
| 520 FOR_EACH_OBSERVER(ProvidedFileSystemObserver, | 521 FOR_EACH_OBSERVER( |
| 521 observers_, | 522 ProvidedFileSystemObserver, |
| 522 OnObservedEntryListChanged(file_system_info_)); | 523 observers_, |
| 524 OnObservedEntryListChanged(file_system_info_, observed_entries_)); |
| 523 | 525 |
| 524 callback.Run(result); | 526 callback.Run(result); |
| 525 } | 527 } |
| 526 | 528 |
| 527 void ProvidedFileSystem::OnNotifyCompleted( | 529 void ProvidedFileSystem::OnNotifyCompleted( |
| 528 const base::FilePath& observed_path, | 530 const base::FilePath& observed_path, |
| 529 ProvidedFileSystemObserver::ChangeType change_type, | 531 ProvidedFileSystemObserver::ChangeType change_type, |
| 530 scoped_ptr<ProvidedFileSystemObserver::ChildChanges> /* child_changes */, | 532 scoped_ptr<ProvidedFileSystemObserver::ChildChanges> /* child_changes */, |
| 531 const std::string& last_tag, | 533 const std::string& last_tag, |
| 532 const std::string& tag) { | 534 const std::string& tag) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 543 // message is printed, but we may want to pass the error to the providing | 545 // message is printed, but we may want to pass the error to the providing |
| 544 // extension. TODO(mtomasz): Consider it. | 546 // extension. TODO(mtomasz): Consider it. |
| 545 if (!tag.empty() && tag == it->second.last_tag) | 547 if (!tag.empty() && tag == it->second.last_tag) |
| 546 LOG(ERROR) << "Tag specified, but same as the previous one."; | 548 LOG(ERROR) << "Tag specified, but same as the previous one."; |
| 547 | 549 |
| 548 it->second.last_tag = tag; | 550 it->second.last_tag = tag; |
| 549 | 551 |
| 550 FOR_EACH_OBSERVER( | 552 FOR_EACH_OBSERVER( |
| 551 ProvidedFileSystemObserver, | 553 ProvidedFileSystemObserver, |
| 552 observers_, | 554 observers_, |
| 553 OnObservedEntryTagUpdated(file_system_info_, observed_path)); | 555 OnObservedEntryTagUpdated(file_system_info_, observed_path, tag)); |
| 554 | 556 |
| 555 // If the observed entry is deleted, then unobserve it. | 557 // If the observed entry is deleted, then unobserve it. |
| 556 if (change_type == ProvidedFileSystemObserver::DELETED) | 558 if (change_type == ProvidedFileSystemObserver::DELETED) |
| 557 UnobserveEntry(observed_path, base::Bind(&EmptyStatusCallback)); | 559 UnobserveEntry(observed_path, base::Bind(&EmptyStatusCallback)); |
| 558 } | 560 } |
| 559 | 561 |
| 560 } // namespace file_system_provider | 562 } // namespace file_system_provider |
| 561 } // namespace chromeos | 563 } // namespace chromeos |
| OLD | NEW |