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

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

Issue 11365142: Small refactoring in DiskMountManager (event reporting; format method). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: few lint nits Created 8 years, 1 month 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 18 matching lines...) Expand all
29 #include "chrome/browser/profiles/profile_dependency_manager.h" 29 #include "chrome/browser/profiles/profile_dependency_manager.h"
30 #include "chrome/common/chrome_notification_types.h" 30 #include "chrome/common/chrome_notification_types.h"
31 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
32 #include "content/public/browser/notification_source.h" 32 #include "content/public/browser/notification_source.h"
33 #include "grit/generated_resources.h" 33 #include "grit/generated_resources.h"
34 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
35 #include "webkit/fileapi/file_system_types.h" 35 #include "webkit/fileapi/file_system_types.h"
36 #include "webkit/fileapi/file_system_util.h" 36 #include "webkit/fileapi/file_system_util.h"
37 37
38 using chromeos::disks::DiskMountManager; 38 using chromeos::disks::DiskMountManager;
39 using chromeos::disks::DiskMountManagerEventType;
40 using content::BrowserThread; 39 using content::BrowserThread;
41 using drive::DriveSystemService; 40 using drive::DriveSystemService;
42 using drive::DriveSystemServiceFactory; 41 using drive::DriveSystemServiceFactory;
43 42
44 namespace { 43 namespace {
45 const char kDiskAddedEventType[] = "added"; 44 const char kDiskAddedEventType[] = "added";
46 const char kDiskRemovedEventType[] = "removed"; 45 const char kDiskRemovedEventType[] = "removed";
47 46
48 const char kPathChanged[] = "changed"; 47 const char kPathChanged[] = "changed";
49 const char kPathWatchError[] = "error"; 48 const char kPathWatchError[] = "error";
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString(); 235 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString();
237 DiskMountManager::MountPointInfo mount_info( 236 DiskMountManager::MountPointInfo mount_info(
238 gdata_path, 237 gdata_path,
239 gdata_path, 238 gdata_path,
240 chromeos::MOUNT_TYPE_GDATA, 239 chromeos::MOUNT_TYPE_GDATA,
241 chromeos::disks::MOUNT_CONDITION_NONE); 240 chromeos::disks::MOUNT_CONDITION_NONE);
242 241
243 // Raise mount event. 242 // Raise mount event.
244 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed 243 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed
245 // or network is unreachable. These two errors will be handled later. 244 // or network is unreachable. These two errors will be handled later.
246 MountCompleted(DiskMountManager::MOUNTING, 245 OnMountEvent(DiskMountManager::MOUNTING,
247 chromeos::MOUNT_ERROR_NONE, 246 chromeos::MOUNT_ERROR_NONE,
248 mount_info); 247 mount_info);
249 248
250 if (!callback.is_null()) 249 if (!callback.is_null())
251 callback.Run(); 250 callback.Run();
252 } 251 }
253 252
254 void FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) { 253 void FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) {
255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
256 255
257 drive::DriveFileSystemInterface* file_system = GetRemoteFileSystem(); 256 drive::DriveFileSystemInterface* file_system = GetRemoteFileSystem();
258 // |file_system| is NULL if Drive is disabled. 257 // |file_system| is NULL if Drive is disabled.
259 if (!file_system) 258 if (!file_system)
260 return; 259 return;
261 260
262 if (start) { 261 if (start) {
263 file_system->CheckForUpdates(); 262 file_system->CheckForUpdates();
264 if (num_remote_update_requests_ == 0) 263 if (num_remote_update_requests_ == 0)
265 file_system->StartPolling(); 264 file_system->StartPolling();
266 ++num_remote_update_requests_; 265 ++num_remote_update_requests_;
267 } else { 266 } else {
268 DCHECK_LE(1, num_remote_update_requests_); 267 DCHECK_LE(1, num_remote_update_requests_);
269 --num_remote_update_requests_; 268 --num_remote_update_requests_;
270 if (num_remote_update_requests_ == 0) 269 if (num_remote_update_requests_ == 0)
271 file_system->StopPolling(); 270 file_system->StopPolling();
272 } 271 }
273 } 272 }
274 273
275 void FileBrowserEventRouter::DiskChanged( 274 void FileBrowserEventRouter::OnDiskEvent(
276 DiskMountManagerEventType event, 275 DiskMountManager::DiskEvent event,
277 const DiskMountManager::Disk* disk) { 276 const DiskMountManager::Disk* disk) {
278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
279 278
280 // Disregard hidden devices. 279 // Disregard hidden devices.
281 if (disk->is_hidden()) 280 if (disk->is_hidden())
282 return; 281 return;
283 if (event == chromeos::disks::MOUNT_DISK_ADDED) { 282 if (event == DiskMountManager::DISK_ADDED) {
284 OnDiskAdded(disk); 283 OnDiskAdded(disk);
285 } else if (event == chromeos::disks::MOUNT_DISK_REMOVED) { 284 } else if (event == DiskMountManager::DISK_REMOVED) {
286 OnDiskRemoved(disk); 285 OnDiskRemoved(disk);
287 } 286 }
288 } 287 }
289 288
290 void FileBrowserEventRouter::DeviceChanged( 289 void FileBrowserEventRouter::OnDeviceEvent(
291 DiskMountManagerEventType event, 290 DiskMountManager::DeviceEvent event,
292 const std::string& device_path) { 291 const std::string& device_path) {
293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
294 293
295 if (event == chromeos::disks::MOUNT_DEVICE_ADDED) { 294 if (event == DiskMountManager::DEVICE_ADDED) {
296 OnDeviceAdded(device_path); 295 OnDeviceAdded(device_path);
297 } else if (event == chromeos::disks::MOUNT_DEVICE_REMOVED) { 296 } else if (event == DiskMountManager::DEVICE_REMOVED) {
298 OnDeviceRemoved(device_path); 297 OnDeviceRemoved(device_path);
299 } else if (event == chromeos::disks::MOUNT_DEVICE_SCANNED) { 298 } else if (event == DiskMountManager::DEVICE_SCANNED) {
300 OnDeviceScanned(device_path); 299 OnDeviceScanned(device_path);
301 } else if (event == chromeos::disks::MOUNT_FORMATTING_STARTED) {
302 // TODO(tbarzic): get rid of '!'.
303 if (device_path[0] == '!') {
304 OnFormattingStarted(device_path.substr(1), false);
305 } else {
306 OnFormattingStarted(device_path, true);
307 }
308 } else if (event == chromeos::disks::MOUNT_FORMATTING_FINISHED) {
309 if (device_path[0] == '!') {
310 OnFormattingFinished(device_path.substr(1), false);
311 } else {
312 OnFormattingFinished(device_path, true);
313 }
314 } 300 }
315 } 301 }
316 302
317 void FileBrowserEventRouter::MountCompleted( 303 void FileBrowserEventRouter::OnMountEvent(
318 DiskMountManager::MountEvent event_type, 304 DiskMountManager::MountEvent event,
319 chromeos::MountError error_code, 305 chromeos::MountError error_code,
320 const DiskMountManager::MountPointInfo& mount_info) { 306 const DiskMountManager::MountPointInfo& mount_info) {
321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
322 308
323 DispatchMountCompletedEvent(event_type, error_code, mount_info); 309 DispatchMountEvent(event, error_code, mount_info);
324 310
325 if (mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && 311 if (mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE &&
326 event_type == DiskMountManager::MOUNTING) { 312 event == DiskMountManager::MOUNTING) {
327 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); 313 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
328 const DiskMountManager::Disk* disk = 314 const DiskMountManager::Disk* disk =
329 disk_mount_manager->FindDiskBySourcePath(mount_info.source_path); 315 disk_mount_manager->FindDiskBySourcePath(mount_info.source_path);
330 if (!disk) 316 if (!disk)
331 return; 317 return;
332 318
333 notifications_->ManageNotificationsOnMountCompleted( 319 notifications_->ManageNotificationsOnMountCompleted(
334 disk->system_path_prefix(), disk->drive_label(), disk->is_parent(), 320 disk->system_path_prefix(), disk->drive_label(), disk->is_parent(),
335 error_code == chromeos::MOUNT_ERROR_NONE, 321 error_code == chromeos::MOUNT_ERROR_NONE,
336 error_code == chromeos::MOUNT_ERROR_UNSUPPORTED_FILESYSTEM); 322 error_code == chromeos::MOUNT_ERROR_UNSUPPORTED_FILESYSTEM);
337 } else if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) { 323 } else if (mount_info.mount_type == chromeos::MOUNT_TYPE_ARCHIVE) {
338 // Clear the "mounted" state for archive files in gdata cache 324 // Clear the "mounted" state for archive files in gdata cache
339 // when mounting failed or unmounting succeeded. 325 // when mounting failed or unmounting succeeded.
340 if ((event_type == DiskMountManager::MOUNTING) != 326 if ((event == DiskMountManager::MOUNTING) !=
341 (error_code == chromeos::MOUNT_ERROR_NONE)) { 327 (error_code == chromeos::MOUNT_ERROR_NONE)) {
342 FilePath source_path(mount_info.source_path); 328 FilePath source_path(mount_info.source_path);
343 DriveSystemService* system_service = 329 DriveSystemService* system_service =
344 DriveSystemServiceFactory::GetForProfile(profile_); 330 DriveSystemServiceFactory::GetForProfile(profile_);
345 drive::DriveCache* cache = 331 drive::DriveCache* cache =
346 system_service ? system_service->cache() : NULL; 332 system_service ? system_service->cache() : NULL;
347 if (cache) { 333 if (cache) {
348 cache->SetMountedState( 334 cache->SetMountedState(
349 source_path, false, drive::GetFileFromCacheCallback()); 335 source_path, false, drive::GetFileFromCacheCallback());
350 } 336 }
351 } 337 }
352 } 338 }
353 } 339 }
354 340
341 void FileBrowserEventRouter::OnFormatEvent(
342 DiskMountManager::FormatEvent event,
343 chromeos::FormatError error_code,
344 const std::string& device_path) {
345 if (event == DiskMountManager::FORMAT_STARTED) {
346 OnFormatStarted(device_path, error_code == chromeos::FORMAT_ERROR_NONE);
347 } else if (event == DiskMountManager::FORMAT_COMPLETED) {
348 OnFormatCompleted(device_path, error_code == chromeos::FORMAT_ERROR_NONE);
349 }
350 }
351
355 void FileBrowserEventRouter::OnNetworkManagerChanged( 352 void FileBrowserEventRouter::OnNetworkManagerChanged(
356 chromeos::NetworkLibrary* network_library) { 353 chromeos::NetworkLibrary* network_library) {
357 if (!profile_ || 354 if (!profile_ ||
358 !extensions::ExtensionSystem::Get(profile_)->event_router()) { 355 !extensions::ExtensionSystem::Get(profile_)->event_router()) {
359 NOTREACHED(); 356 NOTREACHED();
360 return; 357 return;
361 } 358 }
362 extensions::ExtensionSystem::Get(profile_)->event_router()-> 359 extensions::ExtensionSystem::Get(profile_)->event_router()->
363 DispatchEventToRenderers( 360 DispatchEventToRenderers(
364 extensions::event_names::kOnFileBrowserNetworkConnectionChanged, 361 extensions::event_names::kOnFileBrowserNetworkConnectionChanged,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 438
442 void FileBrowserEventRouter::OnFileSystemMounted() { 439 void FileBrowserEventRouter::OnFileSystemMounted() {
443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
444 441
445 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing. 442 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing.
446 } 443 }
447 444
448 void FileBrowserEventRouter::OnFileSystemBeingUnmounted() { 445 void FileBrowserEventRouter::OnFileSystemBeingUnmounted() {
449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
450 447
451 // Raise a MountCompleted event to notify the File Manager. 448 // Raise a mount event to notify the File Manager.
452 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString(); 449 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString();
453 DiskMountManager::MountPointInfo mount_info( 450 DiskMountManager::MountPointInfo mount_info(
454 gdata_path, 451 gdata_path,
455 gdata_path, 452 gdata_path,
456 chromeos::MOUNT_TYPE_GDATA, 453 chromeos::MOUNT_TYPE_GDATA,
457 chromeos::disks::MOUNT_CONDITION_NONE); 454 chromeos::disks::MOUNT_CONDITION_NONE);
458 MountCompleted(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, 455 OnMountEvent(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE,
459 mount_info); 456 mount_info);
460 } 457 }
461 458
462 void FileBrowserEventRouter::OnAuthenticationFailed( 459 void FileBrowserEventRouter::OnAuthenticationFailed(
463 google_apis::GDataErrorCode error) { 460 google_apis::GDataErrorCode error) {
464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
465 462
466 if (error == google_apis::GDATA_NO_CONNECTION) 463 if (error == google_apis::GDATA_NO_CONNECTION)
467 return; 464 return;
468 465
469 // Raise a MountCompleted event to notify the File Manager. 466 // Raise a mount event to notify the File Manager.
470 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString(); 467 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString();
471 DiskMountManager::MountPointInfo mount_info( 468 DiskMountManager::MountPointInfo mount_info(
472 gdata_path, 469 gdata_path,
473 gdata_path, 470 gdata_path,
474 chromeos::MOUNT_TYPE_GDATA, 471 chromeos::MOUNT_TYPE_GDATA,
475 chromeos::disks::MOUNT_CONDITION_NONE); 472 chromeos::disks::MOUNT_CONDITION_NONE);
476 MountCompleted(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, 473 OnMountEvent(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE,
477 mount_info); 474 mount_info);
478 } 475 }
479 476
480 void FileBrowserEventRouter::HandleFileWatchNotification( 477 void FileBrowserEventRouter::HandleFileWatchNotification(
481 const FilePath& local_path, bool got_error) { 478 const FilePath& local_path, bool got_error) {
482 base::AutoLock lock(lock_); 479 base::AutoLock lock(lock_);
483 WatcherMap::const_iterator iter = file_watchers_.find(local_path); 480 WatcherMap::const_iterator iter = file_watchers_.find(local_path);
484 if (iter == file_watchers_.end()) { 481 if (iter == file_watchers_.end()) {
485 return; 482 return;
486 } 483 }
487 DispatchDirectoryChangeEvent(iter->second->GetVirtualPath(), got_error, 484 DispatchDirectoryChangeEvent(iter->second->GetVirtualPath(), got_error,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 added ? kDiskAddedEventType : kDiskRemovedEventType); 537 added ? kDiskAddedEventType : kDiskRemovedEventType);
541 DictionaryValue* disk_info = DiskToDictionaryValue(disk); 538 DictionaryValue* disk_info = DiskToDictionaryValue(disk);
542 mount_info->Set("volumeInfo", disk_info); 539 mount_info->Set("volumeInfo", disk_info);
543 540
544 extensions::ExtensionSystem::Get(profile_)->event_router()-> 541 extensions::ExtensionSystem::Get(profile_)->event_router()->
545 DispatchEventToRenderers( 542 DispatchEventToRenderers(
546 extensions::event_names::kOnFileBrowserDiskChanged, args.Pass(), NULL, 543 extensions::event_names::kOnFileBrowserDiskChanged, args.Pass(), NULL,
547 GURL()); 544 GURL());
548 } 545 }
549 546
550 void FileBrowserEventRouter::DispatchMountCompletedEvent( 547 void FileBrowserEventRouter::DispatchMountEvent(
551 DiskMountManager::MountEvent event, 548 DiskMountManager::MountEvent event,
552 chromeos::MountError error_code, 549 chromeos::MountError error_code,
553 const DiskMountManager::MountPointInfo& mount_info) { 550 const DiskMountManager::MountPointInfo& mount_info) {
554 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can 551 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can
555 // happen at shutdown. 552 // happen at shutdown.
556 if (!profile_) 553 if (!profile_)
557 return; 554 return;
558 555
559 if (mount_info.mount_type == chromeos::MOUNT_TYPE_INVALID) { 556 if (mount_info.mount_type == chromeos::MOUNT_TYPE_INVALID) {
560 NOTREACHED(); 557 NOTREACHED();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 device_path); 690 device_path);
694 notifications_->UnregisterDevice(device_path); 691 notifications_->UnregisterDevice(device_path);
695 } 692 }
696 693
697 void FileBrowserEventRouter::OnDeviceScanned( 694 void FileBrowserEventRouter::OnDeviceScanned(
698 const std::string& device_path) { 695 const std::string& device_path) {
699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
700 VLOG(1) << "Device scanned : " << device_path; 697 VLOG(1) << "Device scanned : " << device_path;
701 } 698 }
702 699
703 void FileBrowserEventRouter::OnFormattingStarted( 700 void FileBrowserEventRouter::OnFormatStarted(
704 const std::string& device_path, bool success) { 701 const std::string& device_path, bool success) {
705 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 702 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
706 703
707 if (success) { 704 if (success) {
708 notifications_->ShowNotification(FileBrowserNotifications::FORMAT_START, 705 notifications_->ShowNotification(FileBrowserNotifications::FORMAT_START,
709 device_path); 706 device_path);
710 } else { 707 } else {
711 notifications_->ShowNotification( 708 notifications_->ShowNotification(
712 FileBrowserNotifications::FORMAT_START_FAIL, device_path); 709 FileBrowserNotifications::FORMAT_START_FAIL, device_path);
713 } 710 }
714 } 711 }
715 712
716 void FileBrowserEventRouter::OnFormattingFinished( 713 void FileBrowserEventRouter::OnFormatCompleted(
717 const std::string& device_path, bool success) { 714 const std::string& device_path, bool success) {
718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
719 716
720 if (success) { 717 if (success) {
721 notifications_->HideNotification(FileBrowserNotifications::FORMAT_START, 718 notifications_->HideNotification(FileBrowserNotifications::FORMAT_START,
722 device_path); 719 device_path);
723 notifications_->ShowNotification(FileBrowserNotifications::FORMAT_SUCCESS, 720 notifications_->ShowNotification(FileBrowserNotifications::FORMAT_SUCCESS,
724 device_path); 721 device_path);
725 // Hide it after a couple of seconds. 722 // Hide it after a couple of seconds.
726 notifications_->HideNotificationDelayed( 723 notifications_->HideNotificationDelayed(
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 return scoped_refptr<RefcountedProfileKeyedService>( 871 return scoped_refptr<RefcountedProfileKeyedService>(
875 new FileBrowserEventRouter(profile)); 872 new FileBrowserEventRouter(profile));
876 } 873 }
877 874
878 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() const { 875 bool FileBrowserEventRouterFactory::ServiceHasOwnInstanceInIncognito() const {
879 // Explicitly and always allow this router in guest login mode. see 876 // Explicitly and always allow this router in guest login mode. see
880 // chrome/browser/profiles/profile_keyed_base_factory.h comment 877 // chrome/browser/profiles/profile_keyed_base_factory.h comment
881 // for the details. 878 // for the details.
882 return true; 879 return true;
883 } 880 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/file_browser_event_router.h ('k') | chrome/browser/chromeos/imageburner/burn_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698