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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 void EventRouter::DefaultNetworkChanged(const chromeos::NetworkState* network) { | 458 void EventRouter::DefaultNetworkChanged(const chromeos::NetworkState* network) { |
459 if (!profile_ || | 459 if (!profile_ || |
460 !extensions::ExtensionSystem::Get(profile_)->event_router()) { | 460 !extensions::ExtensionSystem::Get(profile_)->event_router()) { |
461 NOTREACHED(); | 461 NOTREACHED(); |
462 return; | 462 return; |
463 } | 463 } |
464 | 464 |
465 BroadcastEvent( | 465 BroadcastEvent( |
466 profile_, | 466 profile_, |
467 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, | 467 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, |
468 make_scoped_ptr(new ListValue)); | 468 make_scoped_ptr(new base::ListValue)); |
469 } | 469 } |
470 | 470 |
471 void EventRouter::OnFileManagerPrefsChanged() { | 471 void EventRouter::OnFileManagerPrefsChanged() { |
472 if (!profile_ || | 472 if (!profile_ || |
473 !extensions::ExtensionSystem::Get(profile_)->event_router()) { | 473 !extensions::ExtensionSystem::Get(profile_)->event_router()) { |
474 NOTREACHED(); | 474 NOTREACHED(); |
475 return; | 475 return; |
476 } | 476 } |
477 | 477 |
478 BroadcastEvent( | 478 BroadcastEvent( |
479 profile_, | 479 profile_, |
480 extensions::event_names::kOnFileBrowserPreferencesChanged, | 480 extensions::event_names::kOnFileBrowserPreferencesChanged, |
481 make_scoped_ptr(new ListValue)); | 481 make_scoped_ptr(new base::ListValue)); |
482 } | 482 } |
483 | 483 |
484 void EventRouter::OnJobAdded(const drive::JobInfo& job_info) { | 484 void EventRouter::OnJobAdded(const drive::JobInfo& job_info) { |
485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
486 OnJobUpdated(job_info); | 486 OnJobUpdated(job_info); |
487 } | 487 } |
488 | 488 |
489 void EventRouter::OnJobUpdated(const drive::JobInfo& job_info) { | 489 void EventRouter::OnJobUpdated(const drive::JobInfo& job_info) { |
490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
491 if (!drive::IsActiveFileTransferJobInfo(job_info)) | 491 if (!drive::IsActiveFileTransferJobInfo(job_info)) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 for (std::map<drive::JobID, DriveJobInfoWithStatus>::iterator | 544 for (std::map<drive::JobID, DriveJobInfoWithStatus>::iterator |
545 iter = drive_jobs_.begin(); iter != drive_jobs_.end(); ++iter) { | 545 iter = drive_jobs_.begin(); iter != drive_jobs_.end(); ++iter) { |
546 | 546 |
547 scoped_ptr<base::DictionaryValue> job_info_dict( | 547 scoped_ptr<base::DictionaryValue> job_info_dict( |
548 JobInfoToDictionaryValue(kFileManagerAppId, | 548 JobInfoToDictionaryValue(kFileManagerAppId, |
549 iter->second.status, | 549 iter->second.status, |
550 iter->second.job_info)); | 550 iter->second.job_info)); |
551 event_list->Append(job_info_dict.release()); | 551 event_list->Append(job_info_dict.release()); |
552 } | 552 } |
553 | 553 |
554 scoped_ptr<ListValue> args(new ListValue()); | 554 scoped_ptr<base::ListValue> args(new base::ListValue()); |
555 args->Append(event_list.release()); | 555 args->Append(event_list.release()); |
556 scoped_ptr<extensions::Event> event(new extensions::Event( | 556 scoped_ptr<extensions::Event> event(new extensions::Event( |
557 extensions::event_names::kOnFileTransfersUpdated, args.Pass())); | 557 extensions::event_names::kOnFileTransfersUpdated, args.Pass())); |
558 extensions::ExtensionSystem::Get(profile_)->event_router()-> | 558 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
559 DispatchEventToExtension(kFileManagerAppId, event.Pass()); | 559 DispatchEventToExtension(kFileManagerAppId, event.Pass()); |
560 | 560 |
561 last_file_transfer_event_ = now; | 561 last_file_transfer_event_ = now; |
562 } | 562 } |
563 | 563 |
564 void EventRouter::OnDirectoryChanged(const base::FilePath& directory_path) { | 564 void EventRouter::OnDirectoryChanged(const base::FilePath& directory_path) { |
565 HandleFileWatchNotification(directory_path, false); | 565 HandleFileWatchNotification(directory_path, false); |
566 } | 566 } |
567 | 567 |
568 void EventRouter::OnRefreshTokenInvalid() { | 568 void EventRouter::OnRefreshTokenInvalid() { |
569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
570 | 570 |
571 // Raise a DriveConnectionStatusChanged event to notify the status offline. | 571 // Raise a DriveConnectionStatusChanged event to notify the status offline. |
572 BroadcastEvent( | 572 BroadcastEvent( |
573 profile_, | 573 profile_, |
574 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, | 574 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, |
575 make_scoped_ptr(new ListValue)); | 575 make_scoped_ptr(new base::ListValue)); |
576 } | 576 } |
577 | 577 |
578 void EventRouter::HandleFileWatchNotification(const base::FilePath& local_path, | 578 void EventRouter::HandleFileWatchNotification(const base::FilePath& local_path, |
579 bool got_error) { | 579 bool got_error) { |
580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
581 | 581 |
582 WatcherMap::const_iterator iter = file_watchers_.find(local_path); | 582 WatcherMap::const_iterator iter = file_watchers_.find(local_path); |
583 if (iter == file_watchers_.end()) { | 583 if (iter == file_watchers_.end()) { |
584 return; | 584 return; |
585 } | 585 } |
586 DispatchDirectoryChangeEvent(iter->second->virtual_path(), got_error, | 586 DispatchDirectoryChangeEvent(iter->second->virtual_path(), got_error, |
587 iter->second->GetExtensionIds()); | 587 iter->second->GetExtensionIds()); |
588 } | 588 } |
589 | 589 |
590 void EventRouter::DispatchDirectoryChangeEvent( | 590 void EventRouter::DispatchDirectoryChangeEvent( |
591 const base::FilePath& virtual_path, | 591 const base::FilePath& virtual_path, |
592 bool got_error, | 592 bool got_error, |
593 const std::vector<std::string>& extension_ids) { | 593 const std::vector<std::string>& extension_ids) { |
594 if (!profile_) { | 594 if (!profile_) { |
595 NOTREACHED(); | 595 NOTREACHED(); |
596 return; | 596 return; |
597 } | 597 } |
598 | 598 |
599 for (size_t i = 0; i < extension_ids.size(); ++i) { | 599 for (size_t i = 0; i < extension_ids.size(); ++i) { |
600 const std::string& extension_id = extension_ids[i]; | 600 const std::string& extension_id = extension_ids[i]; |
601 | 601 |
602 GURL target_origin_url(extensions::Extension::GetBaseURLFromExtensionId( | 602 GURL target_origin_url(extensions::Extension::GetBaseURLFromExtensionId( |
603 extension_id)); | 603 extension_id)); |
604 scoped_ptr<ListValue> args(new ListValue()); | 604 scoped_ptr<base::ListValue> args(new base::ListValue()); |
605 DictionaryValue* watch_info = new DictionaryValue(); | 605 base::DictionaryValue* watch_info = new base::DictionaryValue(); |
606 args->Append(watch_info); | 606 args->Append(watch_info); |
607 | 607 |
608 // This will be replaced with a real Entry in custom bindings. | 608 // This will be replaced with a real Entry in custom bindings. |
609 fileapi::FileSystemInfo info = | 609 fileapi::FileSystemInfo info = |
610 fileapi::GetFileSystemInfoForChromeOS(target_origin_url.GetOrigin()); | 610 fileapi::GetFileSystemInfoForChromeOS(target_origin_url.GetOrigin()); |
611 DictionaryValue* entry = new DictionaryValue(); | 611 base::DictionaryValue* entry = new base::DictionaryValue(); |
612 entry->SetString("fileSystemName", info.name); | 612 entry->SetString("fileSystemName", info.name); |
613 entry->SetString("fileSystemRoot", info.root_url.spec()); | 613 entry->SetString("fileSystemRoot", info.root_url.spec()); |
614 entry->SetString("fileFullPath", "/" + virtual_path.value()); | 614 entry->SetString("fileFullPath", "/" + virtual_path.value()); |
615 entry->SetBoolean("fileIsDirectory", true); | 615 entry->SetBoolean("fileIsDirectory", true); |
616 watch_info->Set("entry", entry); | 616 watch_info->Set("entry", entry); |
617 watch_info->SetString("eventType", | 617 watch_info->SetString("eventType", |
618 got_error ? kPathWatchError : kPathChanged); | 618 got_error ? kPathWatchError : kPathChanged); |
619 scoped_ptr<extensions::Event> event(new extensions::Event( | 619 scoped_ptr<extensions::Event> event(new extensions::Event( |
620 extensions::event_names::kOnDirectoryChanged, args.Pass())); | 620 extensions::event_names::kOnDirectoryChanged, args.Pass())); |
621 extensions::ExtensionSystem::Get(profile_)->event_router()-> | 621 extensions::ExtensionSystem::Get(profile_)->event_router()-> |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 base::TimeDelta::FromSeconds(4)); | 761 base::TimeDelta::FromSeconds(4)); |
762 } else { | 762 } else { |
763 notifications_->HideNotification(DesktopNotifications::FORMAT_START, | 763 notifications_->HideNotification(DesktopNotifications::FORMAT_START, |
764 device_path); | 764 device_path); |
765 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL, | 765 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL, |
766 device_path); | 766 device_path); |
767 } | 767 } |
768 } | 768 } |
769 | 769 |
770 } // namespace file_manager | 770 } // namespace file_manager |
OLD | NEW |