OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 8 #include "base/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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // Tweak watch path for remote sources - we need to drop leading /special | 325 // Tweak watch path for remote sources - we need to drop leading /special |
326 // directory from there in order to be able to pair these events with | 326 // directory from there in order to be able to pair these events with |
327 // their change notifications. | 327 // their change notifications. |
328 if (drive::util::IsUnderDriveMountPoint(watch_path)) { | 328 if (drive::util::IsUnderDriveMountPoint(watch_path)) { |
329 watch_path = drive::util::ExtractDrivePath(watch_path); | 329 watch_path = drive::util::ExtractDrivePath(watch_path); |
330 is_remote_watch = true; | 330 is_remote_watch = true; |
331 } | 331 } |
332 | 332 |
333 WatcherMap::iterator iter = file_watchers_.find(watch_path); | 333 WatcherMap::iterator iter = file_watchers_.find(watch_path); |
334 if (iter == file_watchers_.end()) { | 334 if (iter == file_watchers_.end()) { |
335 scoped_ptr<FileWatcherExtensions> | 335 scoped_ptr<FileWatcher> watcher( |
336 watch(new FileWatcherExtensions(virtual_path, | 336 new FileWatcher(virtual_path, extension_id, is_remote_watch)); |
337 extension_id, | 337 watcher->Watch(watch_path, file_watcher_callback_, callback); |
338 is_remote_watch)); | 338 file_watchers_[watch_path] = watcher.release(); |
339 watch->Watch(watch_path, | |
340 file_watcher_callback_, | |
341 callback); | |
342 file_watchers_[watch_path] = watch.release(); | |
343 } else { | 339 } else { |
344 iter->second->AddExtension(extension_id); | 340 iter->second->AddExtension(extension_id); |
345 base::MessageLoopProxy::current()->PostTask(FROM_HERE, | 341 base::MessageLoopProxy::current()->PostTask(FROM_HERE, |
346 base::Bind(callback, true)); | 342 base::Bind(callback, true)); |
347 } | 343 } |
348 } | 344 } |
349 | 345 |
350 void EventRouter::RemoveFileWatch(const base::FilePath& local_path, | 346 void EventRouter::RemoveFileWatch(const base::FilePath& local_path, |
351 const std::string& extension_id) { | 347 const std::string& extension_id) { |
352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 if (iter == file_watchers_.end()) { | 636 if (iter == file_watchers_.end()) { |
641 return; | 637 return; |
642 } | 638 } |
643 DispatchDirectoryChangeEvent(iter->second->virtual_path(), got_error, | 639 DispatchDirectoryChangeEvent(iter->second->virtual_path(), got_error, |
644 iter->second->extensions()); | 640 iter->second->extensions()); |
645 } | 641 } |
646 | 642 |
647 void EventRouter::DispatchDirectoryChangeEvent( | 643 void EventRouter::DispatchDirectoryChangeEvent( |
648 const base::FilePath& virtual_path, | 644 const base::FilePath& virtual_path, |
649 bool got_error, | 645 bool got_error, |
650 const FileWatcherExtensions::ExtensionUsageRegistry& extensions) { | 646 const FileWatcher::ExtensionUsageRegistry& extensions) { |
651 if (!profile_) { | 647 if (!profile_) { |
652 NOTREACHED(); | 648 NOTREACHED(); |
653 return; | 649 return; |
654 } | 650 } |
655 | 651 |
656 for (FileWatcherExtensions::ExtensionUsageRegistry::const_iterator iter = | 652 for (FileWatcher::ExtensionUsageRegistry::const_iterator iter = |
657 extensions.begin(); iter != extensions.end(); ++iter) { | 653 extensions.begin(); iter != extensions.end(); ++iter) { |
658 GURL target_origin_url(extensions::Extension::GetBaseURLFromExtensionId( | 654 GURL target_origin_url(extensions::Extension::GetBaseURLFromExtensionId( |
659 iter->first)); | 655 iter->first)); |
660 GURL base_url = fileapi::GetFileSystemRootURI( | 656 GURL base_url = fileapi::GetFileSystemRootURI( |
661 target_origin_url, | 657 target_origin_url, |
662 fileapi::kFileSystemTypeExternal); | 658 fileapi::kFileSystemTypeExternal); |
663 GURL target_directory_url = GURL(base_url.spec() + virtual_path.value()); | 659 GURL target_directory_url = GURL(base_url.spec() + virtual_path.value()); |
664 scoped_ptr<ListValue> args(new ListValue()); | 660 scoped_ptr<ListValue> args(new ListValue()); |
665 DictionaryValue* watch_info = new DictionaryValue(); | 661 DictionaryValue* watch_info = new DictionaryValue(); |
666 args->Append(watch_info); | 662 args->Append(watch_info); |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 chromeos::MOUNT_TYPE_DEVICE); | 856 chromeos::MOUNT_TYPE_DEVICE); |
861 } else { | 857 } else { |
862 notifications_->HideNotification(DesktopNotifications::FORMAT_START, | 858 notifications_->HideNotification(DesktopNotifications::FORMAT_START, |
863 device_path); | 859 device_path); |
864 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL, | 860 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL, |
865 device_path); | 861 device_path); |
866 } | 862 } |
867 } | 863 } |
868 | 864 |
869 } // namespace file_manager | 865 } // namespace file_manager |
OLD | NEW |