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/extensions/file_manager/event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_manager/event_router.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_change_registrar.h" | 10 #include "base/prefs/pref_change_registrar.h" |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 | 379 |
380 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( | 380 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( |
381 const drive::JobInfo& info, const std::string& status) | 381 const drive::JobInfo& info, const std::string& status) |
382 : job_info(info), status(status) { | 382 : job_info(info), status(status) { |
383 } | 383 } |
384 | 384 |
385 EventRouter::EventRouter(Profile* profile) | 385 EventRouter::EventRouter(Profile* profile) |
386 : pref_change_registrar_(new PrefChangeRegistrar), | 386 : pref_change_registrar_(new PrefChangeRegistrar), |
387 profile_(profile), | 387 profile_(profile), |
388 device_event_router_(new DeviceEventRouterImpl(profile)), | 388 device_event_router_(new DeviceEventRouterImpl(profile)), |
389 weak_factory_(this) { | 389 weak_factory_(this), |
390 dispatch_dir_change_eve_impl_( | |
mtomasz
2014/10/16 04:02:02
ditto
yawano
2014/10/17 03:57:22
Done.
| |
391 base::Bind(&EventRouter::DispatchDirectoryChangeEventImpl, | |
392 base::Unretained(this))) { | |
390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
391 ObserveEvents(); | 394 ObserveEvents(); |
392 } | 395 } |
393 | 396 |
394 EventRouter::~EventRouter() { | 397 EventRouter::~EventRouter() { |
395 } | 398 } |
396 | 399 |
397 void EventRouter::Shutdown() { | 400 void EventRouter::Shutdown() { |
398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
399 | 402 |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 profile_, | 763 profile_, |
761 file_manager_private::OnDriveConnectionStatusChanged::kEventName, | 764 file_manager_private::OnDriveConnectionStatusChanged::kEventName, |
762 file_manager_private::OnDriveConnectionStatusChanged::Create()); | 765 file_manager_private::OnDriveConnectionStatusChanged::Create()); |
763 } | 766 } |
764 | 767 |
765 void EventRouter::HandleFileWatchNotification(const drive::FileChange* list, | 768 void EventRouter::HandleFileWatchNotification(const drive::FileChange* list, |
766 const base::FilePath& local_path, | 769 const base::FilePath& local_path, |
767 bool got_error) { | 770 bool got_error) { |
768 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 771 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
769 | 772 |
770 WatcherMap::const_iterator iter = file_watchers_.find(local_path); | |
771 if (iter == file_watchers_.end()) { | |
772 return; | |
773 } | |
774 | |
775 if (list && list->size() > kDirectoryChangeEventMaxDetailInfoSize) { | 773 if (list && list->size() > kDirectoryChangeEventMaxDetailInfoSize) { |
776 // Removes the detailed information, if the list size is more than | 774 // Removes the detailed information, if the list size is more than |
777 // kDirectoryChangeEventMaxDetailInfoSize, since passing large list | 775 // kDirectoryChangeEventMaxDetailInfoSize, since passing large list |
778 // and processing it may cause more itme. | 776 // and processing it may cause more itme. |
779 // This will be invoked full-refresh in Files.app. | 777 // This will be invoked full-refresh in Files.app. |
780 list = NULL; | 778 list = NULL; |
781 } | 779 } |
782 | 780 |
783 DispatchDirectoryChangeEvent(iter->second->virtual_path(), | 781 // Since a change in the parent directory of a watching directory causes |
mtomasz
2014/10/16 04:02:02
What if we watch for /a/b only, and /a/b is remove
yawano
2014/10/17 03:57:21
While we changed the point to fix in the latest Cl
| |
784 list, | 782 // deletion of the watching directory, we check whether the watching directory |
785 got_error, | 783 // exists and notify if it is deleted. |
786 iter->second->GetExtensionIds()); | 784 for (WatcherMap::const_iterator iter = file_watchers_.lower_bound(local_path); |
785 iter != file_watchers_.end() && | |
786 iter->first.value().find(local_path.value()) == 0; | |
787 ++iter) { | |
788 // If a change has happend in the parent directory, checks the descendant | |
789 // directory(watching directory) still exists. | |
790 if (local_path.value().size() < iter->first.value().size() && | |
791 base::PathExists(iter->first)) { | |
mtomasz
2014/10/16 04:02:02
PathExists can't be called on UI thread. You have
yawano
2014/10/17 03:57:21
Acknowledged.
| |
792 continue; | |
793 } | |
794 | |
795 DispatchDirectoryChangeEvent(iter->second->virtual_path(), | |
796 list, | |
797 got_error, | |
798 iter->second->GetExtensionIds()); | |
799 } | |
787 } | 800 } |
788 | 801 |
789 void EventRouter::DispatchDirectoryChangeEvent( | 802 void EventRouter::DispatchDirectoryChangeEvent( |
790 const base::FilePath& virtual_path, | 803 const base::FilePath& virtual_path, |
791 const drive::FileChange* list, | 804 const drive::FileChange* list, |
792 bool got_error, | 805 bool got_error, |
793 const std::vector<std::string>& extension_ids) { | 806 const std::vector<std::string>& extension_ids) { |
807 dispatch_dir_change_eve_impl_.Run(virtual_path, | |
mtomasz
2014/10/16 04:02:02
ditto
yawano
2014/10/17 03:57:21
Done.
| |
808 list, got_error, extension_ids); | |
809 } | |
810 | |
811 void EventRouter::DispatchDirectoryChangeEventImpl( | |
812 const base::FilePath& virtual_path, | |
813 const drive::FileChange* list, | |
814 bool got_error, | |
815 const std::vector<std::string>& extension_ids) { | |
794 if (!profile_) { | 816 if (!profile_) { |
795 NOTREACHED(); | 817 NOTREACHED(); |
796 return; | 818 return; |
797 } | 819 } |
798 linked_ptr<drive::FileChange> changes; | 820 linked_ptr<drive::FileChange> changes; |
799 if (list) | 821 if (list) |
800 changes.reset(new drive::FileChange(*list)); // Copy | 822 changes.reset(new drive::FileChange(*list)); // Copy |
801 | 823 |
802 for (size_t i = 0; i < extension_ids.size(); ++i) { | 824 for (size_t i = 0; i < extension_ids.size(); ++i) { |
803 std::string* extension_id = new std::string(extension_ids[i]); | 825 std::string* extension_id = new std::string(extension_ids[i]); |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
960 void EventRouter::Observe(int type, | 982 void EventRouter::Observe(int type, |
961 const content::NotificationSource& source, | 983 const content::NotificationSource& source, |
962 const content::NotificationDetails& details) { | 984 const content::NotificationDetails& details) { |
963 if (type == chrome::NOTIFICATION_PROFILE_ADDED) { | 985 if (type == chrome::NOTIFICATION_PROFILE_ADDED) { |
964 Profile* const added_profile = content::Source<Profile>(source).ptr(); | 986 Profile* const added_profile = content::Source<Profile>(source).ptr(); |
965 if (!added_profile->IsOffTheRecord()) | 987 if (!added_profile->IsOffTheRecord()) |
966 GrantAccessForAddedProfileToRunningInstance(added_profile, profile_); | 988 GrantAccessForAddedProfileToRunningInstance(added_profile, profile_); |
967 } | 989 } |
968 } | 990 } |
969 | 991 |
992 void EventRouter::SetDispatchDirChangeEveImplForTesting( | |
993 const DispatchDirChangeEveImplCallback& callback) { | |
994 dispatch_dir_change_eve_impl_ = callback; | |
mtomasz
2014/10/16 04:02:02
ditto
yawano
2014/10/17 03:57:22
Done.
| |
995 } | |
996 | |
970 } // namespace file_manager | 997 } // namespace file_manager |
OLD | NEW |