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" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/chromeos/cros/cros_library.h" | 12 #include "chrome/browser/chromeos/cros/cros_library.h" |
13 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" | 13 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" |
14 #include "chrome/browser/chromeos/extensions/file_manager_util.h" | 14 #include "chrome/browser/chromeos/extensions/file_manager_util.h" |
15 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" | 15 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" |
16 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 16 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
17 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 17 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
18 #include "chrome/browser/chromeos/login/base_login_display_host.h" | 18 #include "chrome/browser/chromeos/login/base_login_display_host.h" |
19 #include "chrome/browser/chromeos/login/screen_locker.h" | 19 #include "chrome/browser/chromeos/login/screen_locker.h" |
20 #include "chrome/browser/chromeos/login/user_manager.h" | 20 #include "chrome/browser/chromeos/login/user_manager.h" |
21 #include "chrome/browser/extensions/extension_event_names.h" | 21 #include "chrome/browser/extensions/event_names.h" |
22 #include "chrome/browser/extensions/extension_event_router.h" | 22 #include "chrome/browser/extensions/event_router.h" |
23 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/prefs/pref_change_registrar.h" | 24 #include "chrome/browser/prefs/pref_change_registrar.h" |
25 #include "chrome/browser/prefs/pref_service.h" | 25 #include "chrome/browser/prefs/pref_service.h" |
26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
27 #include "chrome/browser/profiles/profile_dependency_manager.h" | 27 #include "chrome/browser/profiles/profile_dependency_manager.h" |
28 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
30 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
31 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
32 #include "webkit/fileapi/file_system_types.h" | 32 #include "webkit/fileapi/file_system_types.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 } | 325 } |
326 } | 326 } |
327 | 327 |
328 void FileBrowserEventRouter::OnNetworkManagerChanged( | 328 void FileBrowserEventRouter::OnNetworkManagerChanged( |
329 chromeos::NetworkLibrary* network_library) { | 329 chromeos::NetworkLibrary* network_library) { |
330 if (!profile_ || !profile_->GetExtensionEventRouter()) { | 330 if (!profile_ || !profile_->GetExtensionEventRouter()) { |
331 NOTREACHED(); | 331 NOTREACHED(); |
332 return; | 332 return; |
333 } | 333 } |
334 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 334 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
335 extension_event_names::kOnFileBrowserNetworkConnectionChanged, | 335 extensions::event_names::kOnFileBrowserNetworkConnectionChanged, |
336 "[]", NULL, GURL()); | 336 "[]", NULL, GURL()); |
337 } | 337 } |
338 | 338 |
339 void FileBrowserEventRouter::Observe( | 339 void FileBrowserEventRouter::Observe( |
340 int type, | 340 int type, |
341 const content::NotificationSource& source, | 341 const content::NotificationSource& source, |
342 const content::NotificationDetails& details) { | 342 const content::NotificationDetails& details) { |
343 if (!profile_ || !profile_->GetExtensionEventRouter()) { | 343 if (!profile_ || !profile_->GetExtensionEventRouter()) { |
344 NOTREACHED(); | 344 NOTREACHED(); |
345 return; | 345 return; |
346 } | 346 } |
347 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 347 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
348 extension_event_names::kOnFileBrowserGDataPreferencesChanged, | 348 extensions::event_names::kOnFileBrowserGDataPreferencesChanged, |
349 "[]", NULL, GURL()); | 349 "[]", NULL, GURL()); |
350 } | 350 } |
351 | 351 |
352 void FileBrowserEventRouter::OnProgressUpdate( | 352 void FileBrowserEventRouter::OnProgressUpdate( |
353 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) { | 353 const std::vector<gdata::GDataOperationRegistry::ProgressStatus>& list) { |
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
355 | 355 |
356 scoped_ptr<ListValue> event_list( | 356 scoped_ptr<ListValue> event_list( |
357 file_manager_util::ProgressStatusVectorToListValue( | 357 file_manager_util::ProgressStatusVectorToListValue( |
358 profile_, | 358 profile_, |
359 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), | 359 file_manager_util::GetFileBrowserExtensionUrl().GetOrigin(), |
360 list)); | 360 list)); |
361 | 361 |
362 ListValue args; | 362 ListValue args; |
363 args.Append(event_list.release()); | 363 args.Append(event_list.release()); |
364 | 364 |
365 std::string args_json; | 365 std::string args_json; |
366 base::JSONWriter::Write(&args, | 366 base::JSONWriter::Write(&args, |
367 &args_json); | 367 &args_json); |
368 | 368 |
369 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 369 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
370 std::string(kFileBrowserDomain), | 370 std::string(kFileBrowserDomain), |
371 extension_event_names::kOnFileTransfersUpdated, args_json, | 371 extensions::event_names::kOnFileTransfersUpdated, args_json, |
372 NULL, GURL()); | 372 NULL, GURL()); |
373 } | 373 } |
374 | 374 |
375 void FileBrowserEventRouter::OnDirectoryChanged( | 375 void FileBrowserEventRouter::OnDirectoryChanged( |
376 const FilePath& directory_path) { | 376 const FilePath& directory_path) { |
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
378 HandleFileWatchNotification(directory_path, false); | 378 HandleFileWatchNotification(directory_path, false); |
379 } | 379 } |
380 | 380 |
381 void FileBrowserEventRouter::OnDocumentFeedFetched( | 381 void FileBrowserEventRouter::OnDocumentFeedFetched( |
382 int num_accumulated_entries) { | 382 int num_accumulated_entries) { |
383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
384 | 384 |
385 ListValue args; | 385 ListValue args; |
386 args.Append(base::Value::CreateIntegerValue(num_accumulated_entries)); | 386 args.Append(base::Value::CreateIntegerValue(num_accumulated_entries)); |
387 std::string args_json; | 387 std::string args_json; |
388 base::JSONWriter::Write(&args, &args_json); | 388 base::JSONWriter::Write(&args, &args_json); |
389 | 389 |
390 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 390 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
391 std::string(kFileBrowserDomain), | 391 std::string(kFileBrowserDomain), |
392 extension_event_names::kOnDocumentFeedFetched, args_json, | 392 extensions::event_names::kOnDocumentFeedFetched, args_json, |
393 NULL, GURL()); | 393 NULL, GURL()); |
394 } | 394 } |
395 | 395 |
396 void FileBrowserEventRouter::OnAuthenticationFailed() { | 396 void FileBrowserEventRouter::OnAuthenticationFailed() { |
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
398 | 398 |
399 // Raise a MountCompleted event to notify the File Manager. | 399 // Raise a MountCompleted event to notify the File Manager. |
400 const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString(); | 400 const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString(); |
401 DiskMountManager::MountPointInfo mount_info( | 401 DiskMountManager::MountPointInfo mount_info( |
402 gdata_path, | 402 gdata_path, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 DictionaryValue* watch_info = new DictionaryValue(); | 437 DictionaryValue* watch_info = new DictionaryValue(); |
438 args.Append(watch_info); | 438 args.Append(watch_info); |
439 watch_info->SetString("fileUrl", target_file_url.spec()); | 439 watch_info->SetString("fileUrl", target_file_url.spec()); |
440 watch_info->SetString("eventType", | 440 watch_info->SetString("eventType", |
441 got_error ? kPathWatchError : kPathChanged); | 441 got_error ? kPathWatchError : kPathChanged); |
442 | 442 |
443 std::string args_json; | 443 std::string args_json; |
444 base::JSONWriter::Write(&args, &args_json); | 444 base::JSONWriter::Write(&args, &args_json); |
445 | 445 |
446 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 446 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
447 iter->first, extension_event_names::kOnFileChanged, args_json, | 447 iter->first, extensions::event_names::kOnFileChanged, args_json, |
448 NULL, GURL()); | 448 NULL, GURL()); |
449 } | 449 } |
450 } | 450 } |
451 | 451 |
452 // TODO(tbarzic): This is not used anymore. Remove it. | 452 // TODO(tbarzic): This is not used anymore. Remove it. |
453 void FileBrowserEventRouter::DispatchDiskEvent( | 453 void FileBrowserEventRouter::DispatchDiskEvent( |
454 const DiskMountManager::Disk* disk, bool added) { | 454 const DiskMountManager::Disk* disk, bool added) { |
455 if (!profile_) { | 455 if (!profile_) { |
456 NOTREACHED(); | 456 NOTREACHED(); |
457 return; | 457 return; |
458 } | 458 } |
459 | 459 |
460 ListValue args; | 460 ListValue args; |
461 DictionaryValue* mount_info = new DictionaryValue(); | 461 DictionaryValue* mount_info = new DictionaryValue(); |
462 args.Append(mount_info); | 462 args.Append(mount_info); |
463 mount_info->SetString("eventType", | 463 mount_info->SetString("eventType", |
464 added ? kDiskAddedEventType : kDiskRemovedEventType); | 464 added ? kDiskAddedEventType : kDiskRemovedEventType); |
465 DictionaryValue* disk_info = DiskToDictionaryValue(disk); | 465 DictionaryValue* disk_info = DiskToDictionaryValue(disk); |
466 mount_info->Set("volumeInfo", disk_info); | 466 mount_info->Set("volumeInfo", disk_info); |
467 | 467 |
468 std::string args_json; | 468 std::string args_json; |
469 base::JSONWriter::Write(&args, &args_json); | 469 base::JSONWriter::Write(&args, &args_json); |
470 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 470 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
471 extension_event_names::kOnFileBrowserDiskChanged, args_json, NULL, | 471 extensions::event_names::kOnFileBrowserDiskChanged, args_json, NULL, |
472 GURL()); | 472 GURL()); |
473 } | 473 } |
474 | 474 |
475 void FileBrowserEventRouter::DispatchMountCompletedEvent( | 475 void FileBrowserEventRouter::DispatchMountCompletedEvent( |
476 DiskMountManager::MountEvent event, | 476 DiskMountManager::MountEvent event, |
477 chromeos::MountError error_code, | 477 chromeos::MountError error_code, |
478 const DiskMountManager::MountPointInfo& mount_info) { | 478 const DiskMountManager::MountPointInfo& mount_info) { |
479 if (!profile_ || mount_info.mount_type == chromeos::MOUNT_TYPE_INVALID) { | 479 if (!profile_ || mount_info.mount_type == chromeos::MOUNT_TYPE_INVALID) { |
480 NOTREACHED(); | 480 NOTREACHED(); |
481 return; | 481 return; |
(...skipping 30 matching lines...) Expand all Loading... |
512 } else { | 512 } else { |
513 LOG(ERROR) << "Mount path is not accessible: " << mount_info.mount_path; | 513 LOG(ERROR) << "Mount path is not accessible: " << mount_info.mount_path; |
514 mount_info_value->SetString("status", | 514 mount_info_value->SetString("status", |
515 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED)); | 515 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED)); |
516 } | 516 } |
517 } | 517 } |
518 | 518 |
519 std::string args_json; | 519 std::string args_json; |
520 base::JSONWriter::Write(&args, &args_json); | 520 base::JSONWriter::Write(&args, &args_json); |
521 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 521 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
522 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, | 522 extensions::event_names::kOnFileBrowserMountCompleted, args_json, NULL, |
523 GURL()); | 523 GURL()); |
524 | 524 |
525 // Do not attempt to open File Manager while the login is in progress or | 525 // Do not attempt to open File Manager while the login is in progress or |
526 // the screen is locked. | 526 // the screen is locked. |
527 if (chromeos::BaseLoginDisplayHost::default_host() || | 527 if (chromeos::BaseLoginDisplayHost::default_host() || |
528 chromeos::ScreenLocker::default_screen_locker()) | 528 chromeos::ScreenLocker::default_screen_locker()) |
529 return; | 529 return; |
530 | 530 |
531 if (relative_mount_path_set && | 531 if (relative_mount_path_set && |
532 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && | 532 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 return scoped_refptr<RefcountedProfileKeyedService>( | 777 return scoped_refptr<RefcountedProfileKeyedService>( |
778 new FileBrowserEventRouter(profile)); | 778 new FileBrowserEventRouter(profile)); |
779 } | 779 } |
780 | 780 |
781 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { | 781 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() { |
782 // Explicitly and always allow this router in guest login mode. see | 782 // Explicitly and always allow this router in guest login mode. see |
783 // chrome/browser/profiles/profile_keyed_base_factory.h comment | 783 // chrome/browser/profiles/profile_keyed_base_factory.h comment |
784 // for the details. | 784 // for the details. |
785 return true; | 785 return true; |
786 } | 786 } |
OLD | NEW |