Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_event_router.cc

Issue 11440004: Remove deprecated extension EventRouter APIs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/prefs/public/pref_change_registrar.h" 10 #include "base/prefs/public/pref_change_registrar.h"
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 } 363 }
364 } 364 }
365 365
366 void FileBrowserEventRouter::OnNetworkManagerChanged( 366 void FileBrowserEventRouter::OnNetworkManagerChanged(
367 chromeos::NetworkLibrary* network_library) { 367 chromeos::NetworkLibrary* network_library) {
368 if (!profile_ || 368 if (!profile_ ||
369 !extensions::ExtensionSystem::Get(profile_)->event_router()) { 369 !extensions::ExtensionSystem::Get(profile_)->event_router()) {
370 NOTREACHED(); 370 NOTREACHED();
371 return; 371 return;
372 } 372 }
373 scoped_ptr<extensions::Event> event(new extensions::Event(
374 extensions::event_names::kOnFileBrowserNetworkConnectionChanged,
375 scoped_ptr<ListValue>(new ListValue())));
373 extensions::ExtensionSystem::Get(profile_)->event_router()-> 376 extensions::ExtensionSystem::Get(profile_)->event_router()->
374 DispatchEventToRenderers( 377 BroadcastEvent(event.Pass());
375 extensions::event_names::kOnFileBrowserNetworkConnectionChanged,
376 scoped_ptr<ListValue>(new ListValue()), NULL, GURL());
377 } 378 }
378 379
379 void FileBrowserEventRouter::OnExternalStorageDisabledChanged() { 380 void FileBrowserEventRouter::OnExternalStorageDisabledChanged() {
380 // If the policy just got disabled we have to unmount every device currently 381 // If the policy just got disabled we have to unmount every device currently
381 // mounted. The opposite is fine - we can let the user re-plug her device to 382 // mounted. The opposite is fine - we can let the user re-plug her device to
382 // make it available. 383 // make it available.
383 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 384 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
384 DiskMountManager* manager = DiskMountManager::GetInstance(); 385 DiskMountManager* manager = DiskMountManager::GetInstance();
385 DiskMountManager::MountPointMap mounts(manager->mount_points()); 386 DiskMountManager::MountPointMap mounts(manager->mount_points());
386 for (DiskMountManager::MountPointMap::const_iterator it = mounts.begin(); 387 for (DiskMountManager::MountPointMap::const_iterator it = mounts.begin();
387 it != mounts.end(); ++it) { 388 it != mounts.end(); ++it) {
388 LOG(INFO) << "Unmounting " << it->second.mount_path 389 LOG(INFO) << "Unmounting " << it->second.mount_path
389 << " because of policy."; 390 << " because of policy.";
390 manager->UnmountPath(it->second.mount_path, 391 manager->UnmountPath(it->second.mount_path,
391 chromeos::UNMOUNT_OPTIONS_NONE); 392 chromeos::UNMOUNT_OPTIONS_NONE);
392 } 393 }
393 } 394 }
394 } 395 }
395 396
396 void FileBrowserEventRouter::OnFileBrowserPrefsChanged() { 397 void FileBrowserEventRouter::OnFileBrowserPrefsChanged() {
397 if (!profile_ || 398 if (!profile_ ||
398 !extensions::ExtensionSystem::Get(profile_)->event_router()) { 399 !extensions::ExtensionSystem::Get(profile_)->event_router()) {
399 NOTREACHED(); 400 NOTREACHED();
400 return; 401 return;
401 } 402 }
402 403
404 scoped_ptr<extensions::Event> event(new extensions::Event(
405 extensions::event_names::kOnFileBrowserPreferencesChanged,
406 scoped_ptr<ListValue>(new ListValue())));
403 extensions::ExtensionSystem::Get(profile_)->event_router()-> 407 extensions::ExtensionSystem::Get(profile_)->event_router()->
404 DispatchEventToRenderers( 408 BroadcastEvent(event.Pass());
405 extensions::event_names::kOnFileBrowserPreferencesChanged,
406 scoped_ptr<ListValue>(new ListValue()), NULL, GURL());
407 } 409 }
408 410
409 void FileBrowserEventRouter::OnProgressUpdate( 411 void FileBrowserEventRouter::OnProgressUpdate(
410 const google_apis::OperationProgressStatusList& list) { 412 const google_apis::OperationProgressStatusList& list) {
411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
412 414
413 scoped_ptr<ListValue> event_list( 415 scoped_ptr<ListValue> event_list(
414 file_manager_util::ProgressStatusVectorToListValue( 416 file_manager_util::ProgressStatusVectorToListValue(
415 profile_, 417 profile_,
416 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), 418 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(),
417 list)); 419 list));
418 420
419 scoped_ptr<ListValue> args(new ListValue()); 421 scoped_ptr<ListValue> args(new ListValue());
420 args->Append(event_list.release()); 422 args->Append(event_list.release());
421 423 scoped_ptr<extensions::Event> event(new extensions::Event(
424 extensions::event_names::kOnFileTransfersUpdated, args.Pass()));
422 extensions::ExtensionSystem::Get(profile_)->event_router()-> 425 extensions::ExtensionSystem::Get(profile_)->event_router()->
423 DispatchEventToExtension( 426 DispatchEventToExtension(std::string(kFileBrowserDomain), event.Pass());
424 std::string(kFileBrowserDomain),
425 extensions::event_names::kOnFileTransfersUpdated, args.Pass(), NULL,
426 GURL());
427 } 427 }
428 428
429 void FileBrowserEventRouter::OnDirectoryChanged( 429 void FileBrowserEventRouter::OnDirectoryChanged(
430 const FilePath& directory_path) { 430 const FilePath& directory_path) {
431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 431 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
432 HandleFileWatchNotification(directory_path, false); 432 HandleFileWatchNotification(directory_path, false);
433 } 433 }
434 434
435 void FileBrowserEventRouter::OnDocumentFeedFetched( 435 void FileBrowserEventRouter::OnDocumentFeedFetched(
436 int num_accumulated_entries) { 436 int num_accumulated_entries) {
437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
438 438
439 scoped_ptr<ListValue> args(new ListValue()); 439 scoped_ptr<ListValue> args(new ListValue());
440 args->Append(base::Value::CreateIntegerValue(num_accumulated_entries)); 440 args->Append(base::Value::CreateIntegerValue(num_accumulated_entries));
441 441
442 scoped_ptr<extensions::Event> event(new extensions::Event(
443 extensions::event_names::kOnDocumentFeedFetched, args.Pass()));
442 extensions::ExtensionSystem::Get(profile_)->event_router()-> 444 extensions::ExtensionSystem::Get(profile_)->event_router()->
443 DispatchEventToExtension( 445 DispatchEventToExtension(std::string(kFileBrowserDomain), event.Pass());
444 std::string(kFileBrowserDomain),
445 extensions::event_names::kOnDocumentFeedFetched, args.Pass(), NULL,
446 GURL());
447 } 446 }
448 447
449 void FileBrowserEventRouter::OnFileSystemMounted() { 448 void FileBrowserEventRouter::OnFileSystemMounted() {
450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
451 450
452 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing. 451 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing.
453 } 452 }
454 453
455 void FileBrowserEventRouter::OnFileSystemBeingUnmounted() { 454 void FileBrowserEventRouter::OnFileSystemBeingUnmounted() {
456 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 DictionaryValue* watch_info = new DictionaryValue(); 514 DictionaryValue* watch_info = new DictionaryValue();
516 args->Append(watch_info); 515 args->Append(watch_info);
517 watch_info->SetString("directoryUrl", target_directory_url.spec()); 516 watch_info->SetString("directoryUrl", target_directory_url.spec());
518 watch_info->SetString("eventType", 517 watch_info->SetString("eventType",
519 got_error ? kPathWatchError : kPathChanged); 518 got_error ? kPathWatchError : kPathChanged);
520 519
521 // TODO(mtomasz): Pass set of entries. http://crbug.com/157834 520 // TODO(mtomasz): Pass set of entries. http://crbug.com/157834
522 ListValue* watch_info_entries = new ListValue(); 521 ListValue* watch_info_entries = new ListValue();
523 watch_info->Set("changedEntries", watch_info_entries); 522 watch_info->Set("changedEntries", watch_info_entries);
524 523
524 scoped_ptr<extensions::Event> event(new extensions::Event(
525 extensions::event_names::kOnDirectoryChanged, args.Pass()));
525 extensions::ExtensionSystem::Get(profile_)->event_router()-> 526 extensions::ExtensionSystem::Get(profile_)->event_router()->
526 DispatchEventToExtension( 527 DispatchEventToExtension(iter->first, event.Pass());
527 iter->first,
528 extensions::event_names::kOnDirectoryChanged,
529 args.Pass(),
530 NULL,
531 GURL());
532 } 528 }
533 } 529 }
534 530
535 // TODO(tbarzic): This is not used anymore. Remove it. 531 // TODO(tbarzic): This is not used anymore. Remove it.
536 void FileBrowserEventRouter::DispatchDiskEvent( 532 void FileBrowserEventRouter::DispatchDiskEvent(
537 const DiskMountManager::Disk* disk, bool added) { 533 const DiskMountManager::Disk* disk, bool added) {
538 if (!profile_) { 534 if (!profile_) {
539 NOTREACHED(); 535 NOTREACHED();
540 return; 536 return;
541 } 537 }
542 538
543 scoped_ptr<ListValue> args(new ListValue()); 539 scoped_ptr<ListValue> args(new ListValue());
544 DictionaryValue* mount_info = new DictionaryValue(); 540 DictionaryValue* mount_info = new DictionaryValue();
545 args->Append(mount_info); 541 args->Append(mount_info);
546 mount_info->SetString("eventType", 542 mount_info->SetString("eventType",
547 added ? kDiskAddedEventType : kDiskRemovedEventType); 543 added ? kDiskAddedEventType : kDiskRemovedEventType);
548 DictionaryValue* disk_info = DiskToDictionaryValue(disk); 544 DictionaryValue* disk_info = DiskToDictionaryValue(disk);
549 mount_info->Set("volumeInfo", disk_info); 545 mount_info->Set("volumeInfo", disk_info);
550 546
547 scoped_ptr<extensions::Event> event(new extensions::Event(
548 extensions::event_names::kOnFileBrowserDiskChanged, args.Pass()));
551 extensions::ExtensionSystem::Get(profile_)->event_router()-> 549 extensions::ExtensionSystem::Get(profile_)->event_router()->
552 DispatchEventToRenderers( 550 BroadcastEvent(event.Pass());
553 extensions::event_names::kOnFileBrowserDiskChanged, args.Pass(), NULL,
554 GURL());
555 } 551 }
556 552
557 void FileBrowserEventRouter::DispatchMountEvent( 553 void FileBrowserEventRouter::DispatchMountEvent(
558 DiskMountManager::MountEvent event, 554 DiskMountManager::MountEvent event,
559 chromeos::MountError error_code, 555 chromeos::MountError error_code,
560 const DiskMountManager::MountPointInfo& mount_info) { 556 const DiskMountManager::MountPointInfo& mount_info) {
561 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can 557 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can
562 // happen at shutdown. 558 // happen at shutdown.
563 if (!profile_) 559 if (!profile_)
564 return; 560 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 mount_info_value->SetString("mountPath", 593 mount_info_value->SetString("mountPath",
598 "/" + relative_mount_path.value()); 594 "/" + relative_mount_path.value());
599 relative_mount_path_set = true; 595 relative_mount_path_set = true;
600 } else { 596 } else {
601 LOG(ERROR) << "Mount path is not accessible: " << mount_info.mount_path; 597 LOG(ERROR) << "Mount path is not accessible: " << mount_info.mount_path;
602 mount_info_value->SetString("status", 598 mount_info_value->SetString("status",
603 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED)); 599 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED));
604 } 600 }
605 } 601 }
606 602
603 scoped_ptr<extensions::Event> extension_event(new extensions::Event(
604 extensions::event_names::kOnFileBrowserMountCompleted, args.Pass()));
607 extensions::ExtensionSystem::Get(profile_)->event_router()-> 605 extensions::ExtensionSystem::Get(profile_)->event_router()->
608 DispatchEventToRenderers( 606 BroadcastEvent(extension_event.Pass());
609 extensions::event_names::kOnFileBrowserMountCompleted, args.Pass(),
610 NULL, GURL());
611 607
612 // Do not attempt to open File Manager while the login is in progress or 608 // Do not attempt to open File Manager while the login is in progress or
613 // the screen is locked. 609 // the screen is locked.
614 if (chromeos::BaseLoginDisplayHost::default_host() || 610 if (chromeos::BaseLoginDisplayHost::default_host() ||
615 chromeos::ScreenLocker::default_screen_locker()) 611 chromeos::ScreenLocker::default_screen_locker())
616 return; 612 return;
617 613
618 if (relative_mount_path_set && 614 if (relative_mount_path_set &&
619 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && 615 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE &&
620 !mount_info.mount_condition && 616 !mount_info.mount_condition &&
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 return scoped_refptr<RefcountedProfileKeyedService>( 877 return scoped_refptr<RefcountedProfileKeyedService>(
882 new FileBrowserEventRouter(profile)); 878 new FileBrowserEventRouter(profile));
883 } 879 }
884 880
885 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() const { 881 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() const {
886 // Explicitly and always allow this router in guest login mode. see 882 // Explicitly and always allow this router in guest login mode. see
887 // chrome/browser/profiles/profile_keyed_base_factory.h comment 883 // chrome/browser/profiles/profile_keyed_base_factory.h comment
888 // for the details. 884 // for the details.
889 return true; 885 return true;
890 } 886 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_manager_extension_api.cc ('k') | chrome/browser/chromeos/extensions/file_handler_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698