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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/event_router.cc

Issue 22150005: file_manager: Rename file_manager_event_router.h to event_router.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 4 months 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_manager/file_manager_event_rou ter.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"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 const char kFileTransferStateStarted[] = "started"; 141 const char kFileTransferStateStarted[] = "started";
142 const char kFileTransferStateInProgress[] = "in_progress"; 142 const char kFileTransferStateInProgress[] = "in_progress";
143 const char kFileTransferStateCompleted[] = "completed"; 143 const char kFileTransferStateCompleted[] = "completed";
144 const char kFileTransferStateFailed[] = "failed"; 144 const char kFileTransferStateFailed[] = "failed";
145 145
146 // Frequency of sending onFileTransferUpdated. 146 // Frequency of sending onFileTransferUpdated.
147 const int64 kFileTransferEventFrequencyInMilliseconds = 1000; 147 const int64 kFileTransferEventFrequencyInMilliseconds = 1000;
148 148
149 // Utility function to check if |job_info| is a file uploading job. 149 // Utility function to check if |job_info| is a file uploading job.
150 bool IsUploadJob(drive::JobType type) { 150 bool IsUploadJob(drive::JobType type) {
151 return type == drive::TYPE_UPLOAD_NEW_FILE || 151 return (type == drive::TYPE_UPLOAD_NEW_FILE ||
152 type == drive::TYPE_UPLOAD_EXISTING_FILE; 152 type == drive::TYPE_UPLOAD_EXISTING_FILE);
153 } 153 }
154 154
155 // Utility function to check if |job_info| is a file downloading job. 155 // Utility function to check if |job_info| is a file downloading job.
156 bool IsDownloadJob(drive::JobType type) { 156 bool IsDownloadJob(drive::JobType type) {
157 return type == drive::TYPE_DOWNLOAD_FILE; 157 return type == drive::TYPE_DOWNLOAD_FILE;
158 } 158 }
159 159
160 // Converts the job info to its JSON (Value) form. 160 // Converts the job info to its JSON (Value) form.
161 scoped_ptr<base::DictionaryValue> JobInfoToDictionaryValue( 161 scoped_ptr<base::DictionaryValue> JobInfoToDictionaryValue(
162 const std::string& extension_id, 162 const std::string& extension_id,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 false /* include_disable */) != NULL) 197 false /* include_disable */) != NULL)
198 return true; 198 return true;
199 } 199 }
200 200
201 return false; 201 return false;
202 } 202 }
203 203
204 } // namespace 204 } // namespace
205 205
206 // Pass dummy value to JobInfo's constructor for make it default constructible. 206 // Pass dummy value to JobInfo's constructor for make it default constructible.
207 FileManagerEventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus() 207 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus()
208 : job_info(drive::TYPE_DOWNLOAD_FILE) { 208 : job_info(drive::TYPE_DOWNLOAD_FILE) {
209 } 209 }
210 210
211 FileManagerEventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( 211 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus(
212 const drive::JobInfo& info, const std::string& status) 212 const drive::JobInfo& info, const std::string& status)
213 : job_info(info), status(status) { 213 : job_info(info), status(status) {
214 } 214 }
215 215
216 FileManagerEventRouter::FileManagerEventRouter( 216 EventRouter::EventRouter(
217 Profile* profile) 217 Profile* profile)
218 : notifications_(new DesktopNotifications(profile)), 218 : notifications_(new DesktopNotifications(profile)),
219 pref_change_registrar_(new PrefChangeRegistrar), 219 pref_change_registrar_(new PrefChangeRegistrar),
220 profile_(profile), 220 profile_(profile),
221 weak_factory_(this) { 221 weak_factory_(this) {
222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
223 223
224 file_watcher_callback_ = 224 file_watcher_callback_ =
225 base::Bind(&FileManagerEventRouter::HandleFileWatchNotification, 225 base::Bind(&EventRouter::HandleFileWatchNotification,
226 weak_factory_.GetWeakPtr()); 226 weak_factory_.GetWeakPtr());
227 } 227 }
228 228
229 FileManagerEventRouter::~FileManagerEventRouter() { 229 EventRouter::~EventRouter() {
230 } 230 }
231 231
232 void FileManagerEventRouter::Shutdown() { 232 void EventRouter::Shutdown() {
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
234 234
235 DLOG_IF(WARNING, !file_watchers_.empty()) << "Not all file watchers are " 235 DLOG_IF(WARNING, !file_watchers_.empty())
236 << "Not all file watchers are "
236 << "removed. This can happen when Files.app is open during shutdown."; 237 << "removed. This can happen when Files.app is open during shutdown.";
237 STLDeleteValues(&file_watchers_); 238 STLDeleteValues(&file_watchers_);
238 if (!profile_) { 239 if (!profile_) {
239 NOTREACHED(); 240 NOTREACHED();
240 return; 241 return;
241 } 242 }
242 243
243 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); 244 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
244 if (disk_mount_manager) 245 if (disk_mount_manager)
245 disk_mount_manager->RemoveObserver(this); 246 disk_mount_manager->RemoveObserver(this);
246 247
247 DriveIntegrationService* integration_service = 248 DriveIntegrationService* integration_service =
248 DriveIntegrationServiceFactory::FindForProfileRegardlessOfStates( 249 DriveIntegrationServiceFactory::FindForProfileRegardlessOfStates(
249 profile_); 250 profile_);
250 if (integration_service) { 251 if (integration_service) {
251 integration_service->RemoveObserver(this); 252 integration_service->RemoveObserver(this);
252 integration_service->file_system()->RemoveObserver(this); 253 integration_service->file_system()->RemoveObserver(this);
253 integration_service->drive_service()->RemoveObserver(this); 254 integration_service->drive_service()->RemoveObserver(this);
254 integration_service->job_list()->RemoveObserver(this); 255 integration_service->job_list()->RemoveObserver(this);
255 } 256 }
256 257
257 if (chromeos::ConnectivityStateHelper::IsInitialized()) { 258 if (chromeos::ConnectivityStateHelper::IsInitialized()) {
258 chromeos::ConnectivityStateHelper::Get()-> 259 chromeos::ConnectivityStateHelper::Get()->
259 RemoveNetworkManagerObserver(this); 260 RemoveNetworkManagerObserver(this);
260 } 261 }
261 profile_ = NULL; 262 profile_ = NULL;
262 } 263 }
263 264
264 void FileManagerEventRouter::ObserveFileSystemEvents() { 265 void EventRouter::ObserveFileSystemEvents() {
265 if (!profile_) { 266 if (!profile_) {
266 NOTREACHED(); 267 NOTREACHED();
267 return; 268 return;
268 } 269 }
269 if (!chromeos::LoginState::IsInitialized() || 270 if (!chromeos::LoginState::IsInitialized() ||
270 !chromeos::LoginState::Get()->IsUserLoggedIn()) { 271 !chromeos::LoginState::Get()->IsUserLoggedIn()) {
271 return; 272 return;
272 } 273 }
273 274
274 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); 275 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
(...skipping 17 matching lines...) Expand all
292 chromeos::ConnectivityStateHelper::Get()-> 293 chromeos::ConnectivityStateHelper::Get()->
293 AddNetworkManagerObserver(this); 294 AddNetworkManagerObserver(this);
294 } 295 }
295 296
296 mounted_disk_monitor_.reset(new MountedDiskMonitor()); 297 mounted_disk_monitor_.reset(new MountedDiskMonitor());
297 298
298 pref_change_registrar_->Init(profile_->GetPrefs()); 299 pref_change_registrar_->Init(profile_->GetPrefs());
299 300
300 pref_change_registrar_->Add( 301 pref_change_registrar_->Add(
301 prefs::kExternalStorageDisabled, 302 prefs::kExternalStorageDisabled,
302 base::Bind(&FileManagerEventRouter::OnExternalStorageDisabledChanged, 303 base::Bind(&EventRouter::OnExternalStorageDisabledChanged,
303 weak_factory_.GetWeakPtr())); 304 weak_factory_.GetWeakPtr()));
304 305
305 base::Closure callback = 306 base::Closure callback =
306 base::Bind(&FileManagerEventRouter::OnFileManagerPrefsChanged, 307 base::Bind(&EventRouter::OnFileManagerPrefsChanged,
307 weak_factory_.GetWeakPtr()); 308 weak_factory_.GetWeakPtr());
308 pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback); 309 pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback);
309 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback); 310 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback);
310 pref_change_registrar_->Add(prefs::kDisableDrive, callback); 311 pref_change_registrar_->Add(prefs::kDisableDrive, callback);
311 pref_change_registrar_->Add(prefs::kUse24HourClock, callback); 312 pref_change_registrar_->Add(prefs::kUse24HourClock, callback);
312 } 313 }
313 314
314 // File watch setup routines. 315 // File watch setup routines.
315 void FileManagerEventRouter::AddFileWatch( 316 void EventRouter::AddFileWatch(const base::FilePath& local_path,
316 const base::FilePath& local_path, 317 const base::FilePath& virtual_path,
317 const base::FilePath& virtual_path, 318 const std::string& extension_id,
318 const std::string& extension_id, 319 const BoolCallback& callback) {
319 const BoolCallback& callback) {
320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
321 DCHECK(!callback.is_null()); 321 DCHECK(!callback.is_null());
322 322
323 base::FilePath watch_path = local_path; 323 base::FilePath watch_path = local_path;
324 bool is_remote_watch = false; 324 bool is_remote_watch = false;
325 // Tweak watch path for remote sources - we need to drop leading /special 325 // Tweak watch path for remote sources - we need to drop leading /special
326 // directory from there in order to be able to pair these events with 326 // directory from there in order to be able to pair these events with
327 // their change notifications. 327 // their change notifications.
328 if (drive::util::IsUnderDriveMountPoint(watch_path)) { 328 if (drive::util::IsUnderDriveMountPoint(watch_path)) {
329 watch_path = drive::util::ExtractDrivePath(watch_path); 329 watch_path = drive::util::ExtractDrivePath(watch_path);
(...skipping 10 matching lines...) Expand all
340 file_watcher_callback_, 340 file_watcher_callback_,
341 callback); 341 callback);
342 file_watchers_[watch_path] = watch.release(); 342 file_watchers_[watch_path] = watch.release();
343 } else { 343 } else {
344 iter->second->AddExtension(extension_id); 344 iter->second->AddExtension(extension_id);
345 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 345 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
346 base::Bind(callback, true)); 346 base::Bind(callback, true));
347 } 347 }
348 } 348 }
349 349
350 void FileManagerEventRouter::RemoveFileWatch( 350 void EventRouter::RemoveFileWatch(const base::FilePath& local_path,
351 const base::FilePath& local_path, 351 const std::string& extension_id) {
352 const std::string& extension_id) {
353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
354 353
355 base::FilePath watch_path = local_path; 354 base::FilePath watch_path = local_path;
356 // Tweak watch path for remote sources - we need to drop leading /special 355 // Tweak watch path for remote sources - we need to drop leading /special
357 // directory from there in order to be able to pair these events with 356 // directory from there in order to be able to pair these events with
358 // their change notifications. 357 // their change notifications.
359 if (drive::util::IsUnderDriveMountPoint(watch_path)) { 358 if (drive::util::IsUnderDriveMountPoint(watch_path)) {
360 watch_path = drive::util::ExtractDrivePath(watch_path); 359 watch_path = drive::util::ExtractDrivePath(watch_path);
361 } 360 }
362 WatcherMap::iterator iter = file_watchers_.find(watch_path); 361 WatcherMap::iterator iter = file_watchers_.find(watch_path);
363 if (iter == file_watchers_.end()) 362 if (iter == file_watchers_.end())
364 return; 363 return;
365 // Remove the renderer process for this watch. 364 // Remove the renderer process for this watch.
366 iter->second->RemoveExtension(extension_id); 365 iter->second->RemoveExtension(extension_id);
367 if (iter->second->ref_count() == 0) { 366 if (iter->second->ref_count() == 0) {
368 delete iter->second; 367 delete iter->second;
369 file_watchers_.erase(iter); 368 file_watchers_.erase(iter);
370 } 369 }
371 } 370 }
372 371
373 void FileManagerEventRouter::OnDiskEvent( 372 void EventRouter::OnDiskEvent(DiskMountManager::DiskEvent event,
374 DiskMountManager::DiskEvent event, 373 const DiskMountManager::Disk* disk) {
375 const DiskMountManager::Disk* disk) {
376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
377 375
378 // Disregard hidden devices. 376 // Disregard hidden devices.
379 if (disk->is_hidden()) 377 if (disk->is_hidden())
380 return; 378 return;
381 if (event == DiskMountManager::DISK_ADDED) { 379 if (event == DiskMountManager::DISK_ADDED) {
382 OnDiskAdded(disk); 380 OnDiskAdded(disk);
383 } else if (event == DiskMountManager::DISK_REMOVED) { 381 } else if (event == DiskMountManager::DISK_REMOVED) {
384 OnDiskRemoved(disk); 382 OnDiskRemoved(disk);
385 } 383 }
386 } 384 }
387 385
388 void FileManagerEventRouter::OnDeviceEvent( 386 void EventRouter::OnDeviceEvent(DiskMountManager::DeviceEvent event,
389 DiskMountManager::DeviceEvent event, 387 const std::string& device_path) {
390 const std::string& device_path) {
391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
392 389
393 if (event == DiskMountManager::DEVICE_ADDED) { 390 if (event == DiskMountManager::DEVICE_ADDED) {
394 OnDeviceAdded(device_path); 391 OnDeviceAdded(device_path);
395 } else if (event == DiskMountManager::DEVICE_REMOVED) { 392 } else if (event == DiskMountManager::DEVICE_REMOVED) {
396 OnDeviceRemoved(device_path); 393 OnDeviceRemoved(device_path);
397 } else if (event == DiskMountManager::DEVICE_SCANNED) { 394 } else if (event == DiskMountManager::DEVICE_SCANNED) {
398 OnDeviceScanned(device_path); 395 OnDeviceScanned(device_path);
399 } 396 }
400 } 397 }
401 398
402 void FileManagerEventRouter::OnMountEvent( 399 void EventRouter::OnMountEvent(
403 DiskMountManager::MountEvent event, 400 DiskMountManager::MountEvent event,
404 chromeos::MountError error_code, 401 chromeos::MountError error_code,
405 const DiskMountManager::MountPointInfo& mount_info) { 402 const DiskMountManager::MountPointInfo& mount_info) {
406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
407 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can 404 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can
408 // happen at shutdown. 405 // happen at shutdown.
409 if (!profile_) 406 if (!profile_)
410 return; 407 return;
411 408
412 DCHECK(mount_info.mount_type != chromeos::MOUNT_TYPE_INVALID); 409 DCHECK(mount_info.mount_type != chromeos::MOUNT_TYPE_INVALID);
(...skipping 30 matching lines...) Expand all
443 integration_service ? integration_service->file_system() : NULL; 440 integration_service ? integration_service->file_system() : NULL;
444 if (file_system) { 441 if (file_system) {
445 file_system->MarkCacheFileAsUnmounted( 442 file_system->MarkCacheFileAsUnmounted(
446 base::FilePath(mount_info.source_path), 443 base::FilePath(mount_info.source_path),
447 base::Bind(&OnMarkAsUnmounted)); 444 base::Bind(&OnMarkAsUnmounted));
448 } 445 }
449 } 446 }
450 } 447 }
451 } 448 }
452 449
453 void FileManagerEventRouter::OnFormatEvent( 450 void EventRouter::OnFormatEvent(DiskMountManager::FormatEvent event,
454 DiskMountManager::FormatEvent event, 451 chromeos::FormatError error_code,
455 chromeos::FormatError error_code, 452 const std::string& device_path) {
456 const std::string& device_path) {
457 if (event == DiskMountManager::FORMAT_STARTED) { 453 if (event == DiskMountManager::FORMAT_STARTED) {
458 OnFormatStarted(device_path, error_code == chromeos::FORMAT_ERROR_NONE); 454 OnFormatStarted(device_path, error_code == chromeos::FORMAT_ERROR_NONE);
459 } else if (event == DiskMountManager::FORMAT_COMPLETED) { 455 } else if (event == DiskMountManager::FORMAT_COMPLETED) {
460 OnFormatCompleted(device_path, error_code == chromeos::FORMAT_ERROR_NONE); 456 OnFormatCompleted(device_path, error_code == chromeos::FORMAT_ERROR_NONE);
461 } 457 }
462 } 458 }
463 459
464 void FileManagerEventRouter::NetworkManagerChanged() { 460 void EventRouter::NetworkManagerChanged() {
465 if (!profile_ || 461 if (!profile_ ||
466 !extensions::ExtensionSystem::Get(profile_)->event_router()) { 462 !extensions::ExtensionSystem::Get(profile_)->event_router()) {
467 NOTREACHED(); 463 NOTREACHED();
468 return; 464 return;
469 } 465 }
470 scoped_ptr<extensions::Event> event(new extensions::Event( 466 scoped_ptr<extensions::Event> event(new extensions::Event(
471 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, 467 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged,
472 scoped_ptr<ListValue>(new ListValue()))); 468 scoped_ptr<ListValue>(new ListValue())));
473 extensions::ExtensionSystem::Get(profile_)->event_router()-> 469 extensions::ExtensionSystem::Get(profile_)->event_router()->
474 BroadcastEvent(event.Pass()); 470 BroadcastEvent(event.Pass());
475 } 471 }
476 472
477 void FileManagerEventRouter::DefaultNetworkChanged() { 473 void EventRouter::DefaultNetworkChanged() {
478 NetworkManagerChanged(); 474 NetworkManagerChanged();
479 } 475 }
480 476
481 void FileManagerEventRouter::OnExternalStorageDisabledChanged() { 477 void EventRouter::OnExternalStorageDisabledChanged() {
482 // If the policy just got disabled we have to unmount every device currently 478 // If the policy just got disabled we have to unmount every device currently
483 // mounted. The opposite is fine - we can let the user re-plug her device to 479 // mounted. The opposite is fine - we can let the user re-plug her device to
484 // make it available. 480 // make it available.
485 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 481 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
486 DiskMountManager* manager = DiskMountManager::GetInstance(); 482 DiskMountManager* manager = DiskMountManager::GetInstance();
487 DiskMountManager::MountPointMap mounts(manager->mount_points()); 483 DiskMountManager::MountPointMap mounts(manager->mount_points());
488 for (DiskMountManager::MountPointMap::const_iterator it = mounts.begin(); 484 for (DiskMountManager::MountPointMap::const_iterator it = mounts.begin();
489 it != mounts.end(); ++it) { 485 it != mounts.end(); ++it) {
490 LOG(INFO) << "Unmounting " << it->second.mount_path 486 LOG(INFO) << "Unmounting " << it->second.mount_path
491 << " because of policy."; 487 << " because of policy.";
492 manager->UnmountPath(it->second.mount_path, 488 manager->UnmountPath(it->second.mount_path,
493 chromeos::UNMOUNT_OPTIONS_NONE, 489 chromeos::UNMOUNT_OPTIONS_NONE,
494 DiskMountManager::UnmountPathCallback()); 490 DiskMountManager::UnmountPathCallback());
495 } 491 }
496 } 492 }
497 } 493 }
498 494
499 void FileManagerEventRouter::OnFileManagerPrefsChanged() { 495 void EventRouter::OnFileManagerPrefsChanged() {
500 if (!profile_ || 496 if (!profile_ ||
501 !extensions::ExtensionSystem::Get(profile_)->event_router()) { 497 !extensions::ExtensionSystem::Get(profile_)->event_router()) {
502 NOTREACHED(); 498 NOTREACHED();
503 return; 499 return;
504 } 500 }
505 501
506 scoped_ptr<extensions::Event> event(new extensions::Event( 502 scoped_ptr<extensions::Event> event(new extensions::Event(
507 extensions::event_names::kOnFileBrowserPreferencesChanged, 503 extensions::event_names::kOnFileBrowserPreferencesChanged,
508 scoped_ptr<ListValue>(new ListValue()))); 504 scoped_ptr<ListValue>(new ListValue())));
509 extensions::ExtensionSystem::Get(profile_)->event_router()-> 505 extensions::ExtensionSystem::Get(profile_)->event_router()->
510 BroadcastEvent(event.Pass()); 506 BroadcastEvent(event.Pass());
511 } 507 }
512 508
513 void FileManagerEventRouter::OnJobAdded(const drive::JobInfo& job_info) { 509 void EventRouter::OnJobAdded(const drive::JobInfo& job_info) {
514 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
515 OnJobUpdated(job_info); 511 OnJobUpdated(job_info);
516 } 512 }
517 513
518 void FileManagerEventRouter::OnJobUpdated(const drive::JobInfo& job_info) { 514 void EventRouter::OnJobUpdated(const drive::JobInfo& job_info) {
519 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 515 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
520 if (!drive::IsActiveFileTransferJobInfo(job_info)) 516 if (!drive::IsActiveFileTransferJobInfo(job_info))
521 return; 517 return;
522 518
523 bool is_new_job = (drive_jobs_.find(job_info.job_id) == drive_jobs_.end()); 519 bool is_new_job = (drive_jobs_.find(job_info.job_id) == drive_jobs_.end());
524 520
525 // Replace with the latest job info. 521 // Replace with the latest job info.
526 drive_jobs_[job_info.job_id] = DriveJobInfoWithStatus( 522 drive_jobs_[job_info.job_id] = DriveJobInfoWithStatus(
527 job_info, 523 job_info,
528 is_new_job ? kFileTransferStateStarted : kFileTransferStateInProgress); 524 is_new_job ? kFileTransferStateStarted : kFileTransferStateInProgress);
529 525
530 // Fire event if needed. 526 // Fire event if needed.
531 bool always = is_new_job; 527 bool always = is_new_job;
532 SendDriveFileTransferEvent(always); 528 SendDriveFileTransferEvent(always);
533 } 529 }
534 530
535 void FileManagerEventRouter::OnJobDone(const drive::JobInfo& job_info, 531 void EventRouter::OnJobDone(const drive::JobInfo& job_info,
536 drive::FileError error) { 532 drive::FileError error) {
537 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
538 if (!drive::IsActiveFileTransferJobInfo(job_info)) 534 if (!drive::IsActiveFileTransferJobInfo(job_info))
539 return; 535 return;
540 536
541 // Replace with the latest job info. 537 // Replace with the latest job info.
542 drive_jobs_[job_info.job_id] = DriveJobInfoWithStatus( 538 drive_jobs_[job_info.job_id] = DriveJobInfoWithStatus(
543 job_info, 539 job_info,
544 error == drive::FILE_ERROR_OK ? kFileTransferStateCompleted 540 error == drive::FILE_ERROR_OK ? kFileTransferStateCompleted
545 : kFileTransferStateFailed); 541 : kFileTransferStateFailed);
546 542
547 // Fire event if needed. 543 // Fire event if needed.
548 bool always = true; 544 bool always = true;
549 SendDriveFileTransferEvent(always); 545 SendDriveFileTransferEvent(always);
550 546
551 // Forget about the job. 547 // Forget about the job.
552 drive_jobs_.erase(job_info.job_id); 548 drive_jobs_.erase(job_info.job_id);
553 } 549 }
554 550
555 void FileManagerEventRouter::SendDriveFileTransferEvent(bool always) { 551 void EventRouter::SendDriveFileTransferEvent(bool always) {
556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
557 553
558 const base::Time now = base::Time::Now(); 554 const base::Time now = base::Time::Now();
559 555
560 // When |always| flag is not set, we don't send the event until certain 556 // When |always| flag is not set, we don't send the event until certain
561 // amount of time passes after the previous one. This is to avoid 557 // amount of time passes after the previous one. This is to avoid
562 // flooding the IPC between extensions by many onFileTransferUpdated events. 558 // flooding the IPC between extensions by many onFileTransferUpdated events.
563 if (!always) { 559 if (!always) {
564 const int64 delta = (now - last_file_transfer_event_).InMilliseconds(); 560 const int64 delta = (now - last_file_transfer_event_).InMilliseconds();
565 // delta < 0 may rarely happen if system clock is synced and rewinded. 561 // delta < 0 may rarely happen if system clock is synced and rewinded.
566 // To be conservative, we don't skip in that case. 562 // To be conservative, we don't skip in that case.
567 if (0 <= delta && delta < kFileTransferEventFrequencyInMilliseconds) 563 if (0 <= delta && delta < kFileTransferEventFrequencyInMilliseconds)
568 return; 564 return;
569 } 565 }
570 566
571 // Convert the current |drive_jobs_| to a JSON value. 567 // Convert the current |drive_jobs_| to a JSON value.
572 scoped_ptr<base::ListValue> event_list(new base::ListValue); 568 scoped_ptr<base::ListValue> event_list(new base::ListValue);
573 for (std::map<drive::JobID, DriveJobInfoWithStatus>::iterator 569 for (std::map<drive::JobID, DriveJobInfoWithStatus>::iterator
574 iter = drive_jobs_.begin(); iter != drive_jobs_.end(); ++iter) { 570 iter = drive_jobs_.begin(); iter != drive_jobs_.end(); ++iter) {
575 571
576 scoped_ptr<base::DictionaryValue> job_info_dict( 572 scoped_ptr<base::DictionaryValue> job_info_dict(
577 JobInfoToDictionaryValue(kFileBrowserDomain, 573 JobInfoToDictionaryValue(kFileBrowserDomain,
578 iter->second.status, 574 iter->second.status,
579 iter->second.job_info)); 575 iter->second.job_info));
580 event_list->Append(job_info_dict.release()); 576 event_list->Append(job_info_dict.release());
581 } 577 }
582 578
583 scoped_ptr<ListValue> args(new ListValue()); 579 scoped_ptr<ListValue> args(new ListValue());
584 args->Append(event_list.release()); 580 args->Append(event_list.release());
585 scoped_ptr<extensions::Event> event(new extensions::Event( 581 scoped_ptr<extensions::Event> event(new extensions::Event(
586 extensions::event_names::kOnFileTransfersUpdated, args.Pass())); 582 extensions::event_names::kOnFileTransfersUpdated, args.Pass()));
587 extensions::ExtensionSystem::Get(profile_)->event_router()-> 583 extensions::ExtensionSystem::Get(profile_)->event_router()->
588 DispatchEventToExtension(kFileBrowserDomain, event.Pass()); 584 DispatchEventToExtension(kFileBrowserDomain, event.Pass());
589 585
590 last_file_transfer_event_ = now; 586 last_file_transfer_event_ = now;
591 } 587 }
592 588
593 void FileManagerEventRouter::OnDirectoryChanged( 589 void EventRouter::OnDirectoryChanged(const base::FilePath& directory_path) {
594 const base::FilePath& directory_path) {
595 HandleFileWatchNotification(directory_path, false); 590 HandleFileWatchNotification(directory_path, false);
596 } 591 }
597 592
598 void FileManagerEventRouter::OnFileSystemMounted() { 593 void EventRouter::OnFileSystemMounted() {
599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
600 595
601 const std::string& drive_path = drive::util::GetDriveMountPointPathAsString(); 596 const std::string& drive_path = drive::util::GetDriveMountPointPathAsString();
602 DiskMountManager::MountPointInfo mount_info( 597 DiskMountManager::MountPointInfo mount_info(
603 drive_path, 598 drive_path,
604 drive_path, 599 drive_path,
605 chromeos::MOUNT_TYPE_GOOGLE_DRIVE, 600 chromeos::MOUNT_TYPE_GOOGLE_DRIVE,
606 chromeos::disks::MOUNT_CONDITION_NONE); 601 chromeos::disks::MOUNT_CONDITION_NONE);
607 602
608 // Raise mount event. 603 // Raise mount event.
609 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed 604 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed
610 // or network is unreachable. These two errors will be handled later. 605 // or network is unreachable. These two errors will be handled later.
611 OnMountEvent(DiskMountManager::MOUNTING, chromeos::MOUNT_ERROR_NONE, 606 OnMountEvent(DiskMountManager::MOUNTING, chromeos::MOUNT_ERROR_NONE,
612 mount_info); 607 mount_info);
613 } 608 }
614 609
615 void FileManagerEventRouter::OnFileSystemBeingUnmounted() { 610 void EventRouter::OnFileSystemBeingUnmounted() {
616 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 611 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
617 612
618 // Raise a mount event to notify the File Manager. 613 // Raise a mount event to notify the File Manager.
619 const std::string& drive_path = drive::util::GetDriveMountPointPathAsString(); 614 const std::string& drive_path = drive::util::GetDriveMountPointPathAsString();
620 DiskMountManager::MountPointInfo mount_info( 615 DiskMountManager::MountPointInfo mount_info(
621 drive_path, 616 drive_path,
622 drive_path, 617 drive_path,
623 chromeos::MOUNT_TYPE_GOOGLE_DRIVE, 618 chromeos::MOUNT_TYPE_GOOGLE_DRIVE,
624 chromeos::disks::MOUNT_CONDITION_NONE); 619 chromeos::disks::MOUNT_CONDITION_NONE);
625 OnMountEvent(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, 620 OnMountEvent(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE,
626 mount_info); 621 mount_info);
627 } 622 }
628 623
629 void FileManagerEventRouter::OnRefreshTokenInvalid() { 624 void EventRouter::OnRefreshTokenInvalid() {
630 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
631 626
632 // Raise a DriveConnectionStatusChanged event to notify the status offline. 627 // Raise a DriveConnectionStatusChanged event to notify the status offline.
633 scoped_ptr<extensions::Event> event(new extensions::Event( 628 scoped_ptr<extensions::Event> event(new extensions::Event(
634 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, 629 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged,
635 scoped_ptr<ListValue>(new ListValue()))); 630 scoped_ptr<ListValue>(new ListValue())));
636 extensions::ExtensionSystem::Get(profile_)->event_router()-> 631 extensions::ExtensionSystem::Get(profile_)->event_router()->
637 BroadcastEvent(event.Pass()); 632 BroadcastEvent(event.Pass());
638 } 633 }
639 634
640 void FileManagerEventRouter::HandleFileWatchNotification( 635 void EventRouter::HandleFileWatchNotification(const base::FilePath& local_path,
641 const base::FilePath& local_path, bool got_error) { 636 bool got_error) {
642 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 637 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
643 638
644 WatcherMap::const_iterator iter = file_watchers_.find(local_path); 639 WatcherMap::const_iterator iter = file_watchers_.find(local_path);
645 if (iter == file_watchers_.end()) { 640 if (iter == file_watchers_.end()) {
646 return; 641 return;
647 } 642 }
648 DispatchDirectoryChangeEvent(iter->second->virtual_path(), got_error, 643 DispatchDirectoryChangeEvent(iter->second->virtual_path(), got_error,
649 iter->second->extensions()); 644 iter->second->extensions());
650 } 645 }
651 646
652 void FileManagerEventRouter::DispatchDirectoryChangeEvent( 647 void EventRouter::DispatchDirectoryChangeEvent(
653 const base::FilePath& virtual_path, 648 const base::FilePath& virtual_path,
654 bool got_error, 649 bool got_error,
655 const FileWatcherExtensions::ExtensionUsageRegistry& extensions) { 650 const FileWatcherExtensions::ExtensionUsageRegistry& extensions) {
656 if (!profile_) { 651 if (!profile_) {
657 NOTREACHED(); 652 NOTREACHED();
658 return; 653 return;
659 } 654 }
660 655
661 for (FileWatcherExtensions::ExtensionUsageRegistry::const_iterator iter = 656 for (FileWatcherExtensions::ExtensionUsageRegistry::const_iterator iter =
662 extensions.begin(); iter != extensions.end(); ++iter) { 657 extensions.begin(); iter != extensions.end(); ++iter) {
663 GURL target_origin_url(extensions::Extension::GetBaseURLFromExtensionId( 658 GURL target_origin_url(extensions::Extension::GetBaseURLFromExtensionId(
664 iter->first)); 659 iter->first));
665 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url, 660 GURL base_url = fileapi::GetFileSystemRootURI(
661 target_origin_url,
666 fileapi::kFileSystemTypeExternal); 662 fileapi::kFileSystemTypeExternal);
667 GURL target_directory_url = GURL(base_url.spec() + virtual_path.value()); 663 GURL target_directory_url = GURL(base_url.spec() + virtual_path.value());
668 scoped_ptr<ListValue> args(new ListValue()); 664 scoped_ptr<ListValue> args(new ListValue());
669 DictionaryValue* watch_info = new DictionaryValue(); 665 DictionaryValue* watch_info = new DictionaryValue();
670 args->Append(watch_info); 666 args->Append(watch_info);
671 watch_info->SetString("directoryUrl", target_directory_url.spec()); 667 watch_info->SetString("directoryUrl", target_directory_url.spec());
672 watch_info->SetString("eventType", 668 watch_info->SetString("eventType",
673 got_error ? kPathWatchError : kPathChanged); 669 got_error ? kPathWatchError : kPathChanged);
674 670
675 // TODO(mtomasz): Pass set of entries. http://crbug.com/157834 671 // TODO(mtomasz): Pass set of entries. http://crbug.com/157834
676 ListValue* watch_info_entries = new ListValue(); 672 ListValue* watch_info_entries = new ListValue();
677 watch_info->Set("changedEntries", watch_info_entries); 673 watch_info->Set("changedEntries", watch_info_entries);
678 674
679 scoped_ptr<extensions::Event> event(new extensions::Event( 675 scoped_ptr<extensions::Event> event(new extensions::Event(
680 extensions::event_names::kOnDirectoryChanged, args.Pass())); 676 extensions::event_names::kOnDirectoryChanged, args.Pass()));
681 extensions::ExtensionSystem::Get(profile_)->event_router()-> 677 extensions::ExtensionSystem::Get(profile_)->event_router()->
682 DispatchEventToExtension(iter->first, event.Pass()); 678 DispatchEventToExtension(iter->first, event.Pass());
683 } 679 }
684 } 680 }
685 681
686 void FileManagerEventRouter::DispatchMountEvent( 682 void EventRouter::DispatchMountEvent(
687 DiskMountManager::MountEvent event, 683 DiskMountManager::MountEvent event,
688 chromeos::MountError error_code, 684 chromeos::MountError error_code,
689 const DiskMountManager::MountPointInfo& mount_info) { 685 const DiskMountManager::MountPointInfo& mount_info) {
690 scoped_ptr<ListValue> args(new ListValue()); 686 scoped_ptr<ListValue> args(new ListValue());
691 DictionaryValue* mount_info_value = new DictionaryValue(); 687 DictionaryValue* mount_info_value = new DictionaryValue();
692 args->Append(mount_info_value); 688 args->Append(mount_info_value);
693 mount_info_value->SetString("eventType", 689 mount_info_value->SetString(
690 "eventType",
694 event == DiskMountManager::MOUNTING ? "mount" : "unmount"); 691 event == DiskMountManager::MOUNTING ? "mount" : "unmount");
695 mount_info_value->SetString("status", MountErrorToString(error_code)); 692 mount_info_value->SetString("status", MountErrorToString(error_code));
696 mount_info_value->SetString( 693 mount_info_value->SetString(
697 "mountType", 694 "mountType",
698 DiskMountManager::MountTypeToString(mount_info.mount_type)); 695 DiskMountManager::MountTypeToString(mount_info.mount_type));
699 696
700 // Add sourcePath to the event. 697 // Add sourcePath to the event.
701 mount_info_value->SetString("sourcePath", mount_info.source_path); 698 mount_info_value->SetString("sourcePath", mount_info.source_path);
702 699
703 base::FilePath relative_mount_path; 700 base::FilePath relative_mount_path;
704 701
705 // If there were no error or some special conditions occurred, add mountPath 702 // If there were no error or some special conditions occurred, add mountPath
706 // to the event. 703 // to the event.
707 if (event == DiskMountManager::UNMOUNTING || 704 if (event == DiskMountManager::UNMOUNTING ||
708 error_code == chromeos::MOUNT_ERROR_NONE || 705 error_code == chromeos::MOUNT_ERROR_NONE ||
709 mount_info.mount_condition) { 706 mount_info.mount_condition) {
710 // Convert mount point path to relative path with the external file system 707 // Convert mount point path to relative path with the external file system
711 // exposed within File API. 708 // exposed within File API.
712 if (util::ConvertFileToRelativeFileSystemPath( 709 if (util::ConvertFileToRelativeFileSystemPath(
713 profile_, 710 profile_,
714 kFileBrowserDomain, 711 kFileBrowserDomain,
715 base::FilePath(mount_info.mount_path), 712 base::FilePath(mount_info.mount_path),
716 &relative_mount_path)) { 713 &relative_mount_path)) {
717 mount_info_value->SetString("mountPath", 714 mount_info_value->SetString("mountPath",
718 "/" + relative_mount_path.value()); 715 "/" + relative_mount_path.value());
719 } else { 716 } else {
720 mount_info_value->SetString("status", 717 mount_info_value->SetString(
718 "status",
721 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED)); 719 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED));
722 } 720 }
723 } 721 }
724 722
725 scoped_ptr<extensions::Event> extension_event(new extensions::Event( 723 scoped_ptr<extensions::Event> extension_event(new extensions::Event(
726 extensions::event_names::kOnFileBrowserMountCompleted, args.Pass())); 724 extensions::event_names::kOnFileBrowserMountCompleted, args.Pass()));
727 extensions::ExtensionSystem::Get(profile_)->event_router()-> 725 extensions::ExtensionSystem::Get(profile_)->event_router()->
728 BroadcastEvent(extension_event.Pass()); 726 BroadcastEvent(extension_event.Pass());
729 } 727 }
730 728
731 void FileManagerEventRouter::ShowRemovableDeviceInFileManager( 729 void EventRouter::ShowRemovableDeviceInFileManager(
732 const DiskMountManager::Disk& disk, const base::FilePath& mount_path) { 730 const DiskMountManager::Disk& disk,
731 const base::FilePath& mount_path) {
733 // Do not attempt to open File Manager while the login is in progress or 732 // Do not attempt to open File Manager while the login is in progress or
734 // the screen is locked. 733 // the screen is locked.
735 if (chromeos::LoginDisplayHostImpl::default_host() || 734 if (chromeos::LoginDisplayHostImpl::default_host() ||
736 chromeos::ScreenLocker::default_screen_locker()) 735 chromeos::ScreenLocker::default_screen_locker())
737 return; 736 return;
738 737
739 // According to DCF (Design rule of Camera File system) by JEITA / CP-3461 738 // According to DCF (Design rule of Camera File system) by JEITA / CP-3461
740 // cameras should have pictures located in the DCIM root directory. 739 // cameras should have pictures located in the DCIM root directory.
741 const base::FilePath dcim_path = mount_path.Append( 740 const base::FilePath dcim_path = mount_path.Append(
742 FILE_PATH_LITERAL("DCIM")); 741 FILE_PATH_LITERAL("DCIM"));
743 742
744 // If there is no DCIM folder or an external photo importer is not available, 743 // If there is no DCIM folder or an external photo importer is not available,
745 // then launch Files.app. 744 // then launch Files.app.
746 DirectoryExistsOnUIThread( 745 DirectoryExistsOnUIThread(
747 dcim_path, 746 dcim_path,
748 IsGooglePhotosInstalled(profile_) ? 747 IsGooglePhotosInstalled(profile_) ?
749 base::Bind(&base::DoNothing) : 748 base::Bind(&base::DoNothing) :
750 base::Bind(&util::ViewRemovableDrive, mount_path), 749 base::Bind(&util::ViewRemovableDrive, mount_path),
751 base::Bind(&util::ViewRemovableDrive, mount_path)); 750 base::Bind(&util::ViewRemovableDrive, mount_path));
752 } 751 }
753 752
754 void FileManagerEventRouter::OnDiskAdded( 753 void EventRouter::OnDiskAdded(const DiskMountManager::Disk* disk) {
755 const DiskMountManager::Disk* disk) {
756 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 754 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
757 755
758 VLOG(1) << "Disk added: " << disk->device_path(); 756 VLOG(1) << "Disk added: " << disk->device_path();
759 if (disk->device_path().empty()) { 757 if (disk->device_path().empty()) {
760 VLOG(1) << "Empty system path for " << disk->device_path(); 758 VLOG(1) << "Empty system path for " << disk->device_path();
761 return; 759 return;
762 } 760 }
763 761
764 // If disk is not mounted yet and it has media and there is no policy 762 // If disk is not mounted yet and it has media and there is no policy
765 // forbidding external storage, give it a try. 763 // forbidding external storage, give it a try.
766 if (disk->mount_path().empty() && disk->has_media() && 764 if (disk->mount_path().empty() && disk->has_media() &&
767 !profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 765 !profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
768 // Initiate disk mount operation. MountPath auto-detects the filesystem 766 // Initiate disk mount operation. MountPath auto-detects the filesystem
769 // format if the second argument is empty. The third argument (mount label) 767 // format if the second argument is empty. The third argument (mount label)
770 // is not used in a disk mount operation. 768 // is not used in a disk mount operation.
771 DiskMountManager::GetInstance()->MountPath( 769 DiskMountManager::GetInstance()->MountPath(
772 disk->device_path(), std::string(), std::string(), 770 disk->device_path(), std::string(), std::string(),
773 chromeos::MOUNT_TYPE_DEVICE); 771 chromeos::MOUNT_TYPE_DEVICE);
774 } else { 772 } else {
775 // Either the disk was mounted or it has no media. In both cases we don't 773 // Either the disk was mounted or it has no media. In both cases we don't
776 // want the Scanning notification to persist. 774 // want the Scanning notification to persist.
777 notifications_->HideNotification(DesktopNotifications::DEVICE, 775 notifications_->HideNotification(DesktopNotifications::DEVICE,
778 disk->system_path_prefix()); 776 disk->system_path_prefix());
779 } 777 }
780 } 778 }
781 779
782 void FileManagerEventRouter::OnDiskRemoved( 780 void EventRouter::OnDiskRemoved(const DiskMountManager::Disk* disk) {
783 const DiskMountManager::Disk* disk) {
784 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 781 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
785 782
786 VLOG(1) << "Disk removed: " << disk->device_path(); 783 VLOG(1) << "Disk removed: " << disk->device_path();
787 784
788 if (!disk->mount_path().empty()) { 785 if (!disk->mount_path().empty()) {
789 DiskMountManager::GetInstance()->UnmountPath( 786 DiskMountManager::GetInstance()->UnmountPath(
790 disk->mount_path(), 787 disk->mount_path(),
791 chromeos::UNMOUNT_OPTIONS_LAZY, 788 chromeos::UNMOUNT_OPTIONS_LAZY,
792 DiskMountManager::UnmountPathCallback()); 789 DiskMountManager::UnmountPathCallback());
793 } 790 }
794 } 791 }
795 792
796 void FileManagerEventRouter::OnDeviceAdded( 793 void EventRouter::OnDeviceAdded(const std::string& device_path) {
797 const std::string& device_path) {
798 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 794 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
799 795
800 VLOG(1) << "Device added : " << device_path; 796 VLOG(1) << "Device added : " << device_path;
801 797
802 // If the policy is set instead of showing the new device notification we show 798 // If the policy is set instead of showing the new device notification we show
803 // a notification that the operation is not permitted. 799 // a notification that the operation is not permitted.
804 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 800 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
805 notifications_->ShowNotification( 801 notifications_->ShowNotification(
806 DesktopNotifications::DEVICE_EXTERNAL_STORAGE_DISABLED, 802 DesktopNotifications::DEVICE_EXTERNAL_STORAGE_DISABLED,
807 device_path); 803 device_path);
808 return; 804 return;
809 } 805 }
810 806
811 notifications_->RegisterDevice(device_path); 807 notifications_->RegisterDevice(device_path);
812 notifications_->ShowNotificationDelayed(DesktopNotifications::DEVICE, 808 notifications_->ShowNotificationDelayed(DesktopNotifications::DEVICE,
813 device_path, 809 device_path,
814 base::TimeDelta::FromSeconds(5)); 810 base::TimeDelta::FromSeconds(5));
815 } 811 }
816 812
817 void FileManagerEventRouter::OnDeviceRemoved( 813 void EventRouter::OnDeviceRemoved(const std::string& device_path) {
818 const std::string& device_path) {
819 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
820 815
821 VLOG(1) << "Device removed : " << device_path; 816 VLOG(1) << "Device removed : " << device_path;
822 notifications_->HideNotification(DesktopNotifications::DEVICE, 817 notifications_->HideNotification(DesktopNotifications::DEVICE,
823 device_path); 818 device_path);
824 notifications_->HideNotification(DesktopNotifications::DEVICE_FAIL, 819 notifications_->HideNotification(DesktopNotifications::DEVICE_FAIL,
825 device_path); 820 device_path);
826 notifications_->UnregisterDevice(device_path); 821 notifications_->UnregisterDevice(device_path);
827 } 822 }
828 823
829 void FileManagerEventRouter::OnDeviceScanned( 824 void EventRouter::OnDeviceScanned(const std::string& device_path) {
830 const std::string& device_path) {
831 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 825 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
832 VLOG(1) << "Device scanned : " << device_path; 826 VLOG(1) << "Device scanned : " << device_path;
833 } 827 }
834 828
835 void FileManagerEventRouter::OnFormatStarted( 829 void EventRouter::OnFormatStarted(const std::string& device_path,
836 const std::string& device_path, bool success) { 830 bool success) {
837 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 831 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
838 832
839 if (success) { 833 if (success) {
840 notifications_->ShowNotification(DesktopNotifications::FORMAT_START, 834 notifications_->ShowNotification(DesktopNotifications::FORMAT_START,
841 device_path); 835 device_path);
842 } else { 836 } else {
843 notifications_->ShowNotification( 837 notifications_->ShowNotification(
844 DesktopNotifications::FORMAT_START_FAIL, device_path); 838 DesktopNotifications::FORMAT_START_FAIL, device_path);
845 } 839 }
846 } 840 }
847 841
848 void FileManagerEventRouter::OnFormatCompleted( 842 void EventRouter::OnFormatCompleted(const std::string& device_path,
849 const std::string& device_path, bool success) { 843 bool success) {
850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
851 845
852 if (success) { 846 if (success) {
853 notifications_->HideNotification(DesktopNotifications::FORMAT_START, 847 notifications_->HideNotification(DesktopNotifications::FORMAT_START,
854 device_path); 848 device_path);
855 notifications_->ShowNotification(DesktopNotifications::FORMAT_SUCCESS, 849 notifications_->ShowNotification(DesktopNotifications::FORMAT_SUCCESS,
856 device_path); 850 device_path);
857 // Hide it after a couple of seconds. 851 // Hide it after a couple of seconds.
858 notifications_->HideNotificationDelayed( 852 notifications_->HideNotificationDelayed(
859 DesktopNotifications::FORMAT_SUCCESS, 853 DesktopNotifications::FORMAT_SUCCESS,
860 device_path, 854 device_path,
861 base::TimeDelta::FromSeconds(4)); 855 base::TimeDelta::FromSeconds(4));
862 // MountPath auto-detects filesystem format if second argument is empty. 856 // MountPath auto-detects filesystem format if second argument is empty.
863 // The third argument (mount label) is not used in a disk mount operation. 857 // The third argument (mount label) is not used in a disk mount operation.
864 DiskMountManager::GetInstance()->MountPath(device_path, std::string(), 858 DiskMountManager::GetInstance()->MountPath(device_path, std::string(),
865 std::string(), 859 std::string(),
866 chromeos::MOUNT_TYPE_DEVICE); 860 chromeos::MOUNT_TYPE_DEVICE);
867 } else { 861 } else {
868 notifications_->HideNotification(DesktopNotifications::FORMAT_START, 862 notifications_->HideNotification(DesktopNotifications::FORMAT_START,
869 device_path); 863 device_path);
870 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL, 864 notifications_->ShowNotification(DesktopNotifications::FORMAT_FAIL,
871 device_path); 865 device_path);
872 } 866 }
873 } 867 }
874 868
875 } // namespace file_manager 869 } // namespace file_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698