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_browser_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 } | 368 } |
369 | 369 |
370 void FileBrowserEventRouter::OnNetworkManagerChanged( | 370 void FileBrowserEventRouter::OnNetworkManagerChanged( |
371 chromeos::NetworkLibrary* network_library) { | 371 chromeos::NetworkLibrary* network_library) { |
372 if (!profile_ || !profile_->GetExtensionEventRouter()) { | 372 if (!profile_ || !profile_->GetExtensionEventRouter()) { |
373 NOTREACHED(); | 373 NOTREACHED(); |
374 return; | 374 return; |
375 } | 375 } |
376 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 376 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
377 extensions::event_names::kOnFileBrowserNetworkConnectionChanged, | 377 extensions::event_names::kOnFileBrowserNetworkConnectionChanged, |
378 "[]", NULL, GURL()); | 378 scoped_ptr<ListValue>(new ListValue()), NULL, GURL()); |
379 } | 379 } |
380 | 380 |
381 void FileBrowserEventRouter::Observe( | 381 void FileBrowserEventRouter::Observe( |
382 int type, | 382 int type, |
383 const content::NotificationSource& source, | 383 const content::NotificationSource& source, |
384 const content::NotificationDetails& details) { | 384 const content::NotificationDetails& details) { |
385 if (!profile_ || !profile_->GetExtensionEventRouter()) { | 385 if (!profile_ || !profile_->GetExtensionEventRouter()) { |
386 NOTREACHED(); | 386 NOTREACHED(); |
387 return; | 387 return; |
388 } | 388 } |
(...skipping 11 matching lines...) Expand all Loading... |
400 LOG(INFO) << "Unmounting " << it->second.mount_path | 400 LOG(INFO) << "Unmounting " << it->second.mount_path |
401 << " because of policy."; | 401 << " because of policy."; |
402 manager->UnmountPath(it->second.mount_path); | 402 manager->UnmountPath(it->second.mount_path); |
403 } | 403 } |
404 return; | 404 return; |
405 } else if (*pref_name == prefs::kDisableGDataOverCellular || | 405 } else if (*pref_name == prefs::kDisableGDataOverCellular || |
406 *pref_name == prefs::kDisableGDataHostedFiles || | 406 *pref_name == prefs::kDisableGDataHostedFiles || |
407 *pref_name == prefs::kDisableGData) { | 407 *pref_name == prefs::kDisableGData) { |
408 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 408 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
409 extensions::event_names::kOnFileBrowserGDataPreferencesChanged, | 409 extensions::event_names::kOnFileBrowserGDataPreferencesChanged, |
410 "[]", NULL, GURL()); | 410 scoped_ptr<ListValue>(new ListValue()), NULL, GURL()); |
411 } | 411 } |
412 } | 412 } |
413 } | 413 } |
414 | 414 |
415 void FileBrowserEventRouter::OnProgressUpdate( | 415 void FileBrowserEventRouter::OnProgressUpdate( |
416 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) { | 416 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) { |
417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
418 | 418 |
419 scoped_ptr<ListValue> event_list( | 419 scoped_ptr<ListValue> event_list( |
420 file_manager_util::ProgressStatusVectorToListValue( | 420 file_manager_util::ProgressStatusVectorToListValue( |
421 profile_, | 421 profile_, |
422 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), | 422 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), |
423 list)); | 423 list)); |
424 | 424 |
425 ListValue args; | 425 scoped_ptr<ListValue> args(new ListValue()); |
426 args.Append(event_list.release()); | 426 args->Append(event_list.release()); |
427 | |
428 std::string args_json; | |
429 base::JSONWriter::Write(&args, | |
430 &args_json); | |
431 | 427 |
432 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 428 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
433 std::string(kFileBrowserDomain), | 429 std::string(kFileBrowserDomain), |
434 extensions::event_names::kOnFileTransfersUpdated, args_json, | 430 extensions::event_names::kOnFileTransfersUpdated, args.Pass(), NULL, |
435 NULL, GURL()); | 431 GURL()); |
436 } | 432 } |
437 | 433 |
438 void FileBrowserEventRouter::OnDirectoryChanged( | 434 void FileBrowserEventRouter::OnDirectoryChanged( |
439 const FilePath& directory_path) { | 435 const FilePath& directory_path) { |
440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
441 HandleFileWatchNotification(directory_path, false); | 437 HandleFileWatchNotification(directory_path, false); |
442 } | 438 } |
443 | 439 |
444 void FileBrowserEventRouter::OnDocumentFeedFetched( | 440 void FileBrowserEventRouter::OnDocumentFeedFetched( |
445 int num_accumulated_entries) { | 441 int num_accumulated_entries) { |
446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
447 | 443 |
448 ListValue args; | 444 scoped_ptr<ListValue> args(new ListValue()); |
449 args.Append(base::Value::CreateIntegerValue(num_accumulated_entries)); | 445 args->Append(base::Value::CreateIntegerValue(num_accumulated_entries)); |
450 std::string args_json; | |
451 base::JSONWriter::Write(&args, &args_json); | |
452 | 446 |
453 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 447 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
454 std::string(kFileBrowserDomain), | 448 std::string(kFileBrowserDomain), |
455 extensions::event_names::kOnDocumentFeedFetched, args_json, | 449 extensions::event_names::kOnDocumentFeedFetched, args.Pass(), NULL, |
456 NULL, GURL()); | 450 GURL()); |
457 } | 451 } |
458 | 452 |
459 void FileBrowserEventRouter::OnFileSystemMounted() { | 453 void FileBrowserEventRouter::OnFileSystemMounted() { |
460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 454 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
461 | 455 |
462 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing. | 456 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing. |
463 } | 457 } |
464 | 458 |
465 void FileBrowserEventRouter::OnFileSystemBeingUnmounted() { | 459 void FileBrowserEventRouter::OnFileSystemBeingUnmounted() { |
466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 return; | 503 return; |
510 } | 504 } |
511 | 505 |
512 for (ExtensionUsageRegistry::const_iterator iter = extensions.begin(); | 506 for (ExtensionUsageRegistry::const_iterator iter = extensions.begin(); |
513 iter != extensions.end(); ++iter) { | 507 iter != extensions.end(); ++iter) { |
514 GURL target_origin_url(extensions::Extension::GetBaseURLFromExtensionId( | 508 GURL target_origin_url(extensions::Extension::GetBaseURLFromExtensionId( |
515 iter->first)); | 509 iter->first)); |
516 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url, | 510 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url, |
517 fileapi::kFileSystemTypeExternal); | 511 fileapi::kFileSystemTypeExternal); |
518 GURL target_file_url = GURL(base_url.spec() + virtual_path.value()); | 512 GURL target_file_url = GURL(base_url.spec() + virtual_path.value()); |
519 ListValue args; | 513 scoped_ptr<ListValue> args(new ListValue()); |
520 DictionaryValue* watch_info = new DictionaryValue(); | 514 DictionaryValue* watch_info = new DictionaryValue(); |
521 args.Append(watch_info); | 515 args->Append(watch_info); |
522 watch_info->SetString("fileUrl", target_file_url.spec()); | 516 watch_info->SetString("fileUrl", target_file_url.spec()); |
523 watch_info->SetString("eventType", | 517 watch_info->SetString("eventType", |
524 got_error ? kPathWatchError : kPathChanged); | 518 got_error ? kPathWatchError : kPathChanged); |
525 | 519 |
526 std::string args_json; | |
527 base::JSONWriter::Write(&args, &args_json); | |
528 | |
529 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 520 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
530 iter->first, extensions::event_names::kOnFileChanged, args_json, | 521 iter->first, extensions::event_names::kOnFileChanged, args.Pass(), NULL, |
531 NULL, GURL()); | 522 GURL()); |
532 } | 523 } |
533 } | 524 } |
534 | 525 |
535 // TODO(tbarzic): This is not used anymore. Remove it. | 526 // TODO(tbarzic): This is not used anymore. Remove it. |
536 void FileBrowserEventRouter::DispatchDiskEvent( | 527 void FileBrowserEventRouter::DispatchDiskEvent( |
537 const DiskMountManager::Disk* disk, bool added) { | 528 const DiskMountManager::Disk* disk, bool added) { |
538 if (!profile_) { | 529 if (!profile_) { |
539 NOTREACHED(); | 530 NOTREACHED(); |
540 return; | 531 return; |
541 } | 532 } |
542 | 533 |
543 ListValue args; | 534 scoped_ptr<ListValue> args(new ListValue()); |
544 DictionaryValue* mount_info = new DictionaryValue(); | 535 DictionaryValue* mount_info = new DictionaryValue(); |
545 args.Append(mount_info); | 536 args->Append(mount_info); |
546 mount_info->SetString("eventType", | 537 mount_info->SetString("eventType", |
547 added ? kDiskAddedEventType : kDiskRemovedEventType); | 538 added ? kDiskAddedEventType : kDiskRemovedEventType); |
548 DictionaryValue* disk_info = DiskToDictionaryValue(disk); | 539 DictionaryValue* disk_info = DiskToDictionaryValue(disk); |
549 mount_info->Set("volumeInfo", disk_info); | 540 mount_info->Set("volumeInfo", disk_info); |
550 | 541 |
551 std::string args_json; | |
552 base::JSONWriter::Write(&args, &args_json); | |
553 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 542 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
554 extensions::event_names::kOnFileBrowserDiskChanged, args_json, NULL, | 543 extensions::event_names::kOnFileBrowserDiskChanged, args.Pass(), NULL, |
555 GURL()); | 544 GURL()); |
556 } | 545 } |
557 | 546 |
558 void FileBrowserEventRouter::DispatchMountCompletedEvent( | 547 void FileBrowserEventRouter::DispatchMountCompletedEvent( |
559 DiskMountManager::MountEvent event, | 548 DiskMountManager::MountEvent event, |
560 chromeos::MountError error_code, | 549 chromeos::MountError error_code, |
561 const DiskMountManager::MountPointInfo& mount_info) { | 550 const DiskMountManager::MountPointInfo& mount_info) { |
562 if (!profile_ || mount_info.mount_type == chromeos::MOUNT_TYPE_INVALID) { | 551 if (!profile_ || mount_info.mount_type == chromeos::MOUNT_TYPE_INVALID) { |
563 NOTREACHED(); | 552 NOTREACHED(); |
564 return; | 553 return; |
565 } | 554 } |
566 | 555 |
567 ListValue args; | 556 scoped_ptr<ListValue> args(new ListValue()); |
568 DictionaryValue* mount_info_value = new DictionaryValue(); | 557 DictionaryValue* mount_info_value = new DictionaryValue(); |
569 args.Append(mount_info_value); | 558 args->Append(mount_info_value); |
570 mount_info_value->SetString("eventType", | 559 mount_info_value->SetString("eventType", |
571 event == DiskMountManager::MOUNTING ? "mount" : "unmount"); | 560 event == DiskMountManager::MOUNTING ? "mount" : "unmount"); |
572 mount_info_value->SetString("status", MountErrorToString(error_code)); | 561 mount_info_value->SetString("status", MountErrorToString(error_code)); |
573 mount_info_value->SetString( | 562 mount_info_value->SetString( |
574 "mountType", | 563 "mountType", |
575 DiskMountManager::MountTypeToString(mount_info.mount_type)); | 564 DiskMountManager::MountTypeToString(mount_info.mount_type)); |
576 | 565 |
577 // Add sourcePath to the event. | 566 // Add sourcePath to the event. |
578 mount_info_value->SetString("sourcePath", mount_info.source_path); | 567 mount_info_value->SetString("sourcePath", mount_info.source_path); |
579 | 568 |
(...skipping 12 matching lines...) Expand all Loading... |
592 mount_info_value->SetString("mountPath", | 581 mount_info_value->SetString("mountPath", |
593 "/" + relative_mount_path.value()); | 582 "/" + relative_mount_path.value()); |
594 relative_mount_path_set = true; | 583 relative_mount_path_set = true; |
595 } else { | 584 } else { |
596 LOG(ERROR) << "Mount path is not accessible: " << mount_info.mount_path; | 585 LOG(ERROR) << "Mount path is not accessible: " << mount_info.mount_path; |
597 mount_info_value->SetString("status", | 586 mount_info_value->SetString("status", |
598 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED)); | 587 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED)); |
599 } | 588 } |
600 } | 589 } |
601 | 590 |
602 std::string args_json; | |
603 base::JSONWriter::Write(&args, &args_json); | |
604 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 591 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
605 extensions::event_names::kOnFileBrowserMountCompleted, args_json, NULL, | 592 extensions::event_names::kOnFileBrowserMountCompleted, args.Pass(), NULL, |
606 GURL()); | 593 GURL()); |
607 | 594 |
608 // Do not attempt to open File Manager while the login is in progress or | 595 // Do not attempt to open File Manager while the login is in progress or |
609 // the screen is locked. | 596 // the screen is locked. |
610 if (chromeos::BaseLoginDisplayHost::default_host() || | 597 if (chromeos::BaseLoginDisplayHost::default_host() || |
611 chromeos::ScreenLocker::default_screen_locker()) | 598 chromeos::ScreenLocker::default_screen_locker()) |
612 return; | 599 return; |
613 | 600 |
614 if (relative_mount_path_set && | 601 if (relative_mount_path_set && |
615 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && | 602 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 return scoped_refptr<RefcountedProfileKeyedService>( | 859 return scoped_refptr<RefcountedProfileKeyedService>( |
873 new FileBrowserEventRouter(profile)); | 860 new FileBrowserEventRouter(profile)); |
874 } | 861 } |
875 | 862 |
876 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { | 863 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { |
877 // Explicitly and always allow this router in guest login mode. see | 864 // Explicitly and always allow this router in guest login mode. see |
878 // chrome/browser/profiles/profile_keyed_base_factory.h comment | 865 // chrome/browser/profiles/profile_keyed_base_factory.h comment |
879 // for the details. | 866 // for the details. |
880 return true; | 867 return true; |
881 } | 868 } |
OLD | NEW |