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

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

Issue 14020002: chromeos: Move chrome/browser/chromeos/extensions/file_browser* to chrome/browser/chromeos/file_man… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sort Created 7 years, 8 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_browser_event_router.h" 5 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_event_rou ter.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/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/prefs/pref_change_registrar.h" 11 #include "base/prefs/pref_change_registrar.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/stl_util.h" 13 #include "base/stl_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/chromeos/drive/drive_cache.h" 15 #include "chrome/browser/chromeos/drive/drive_cache.h"
16 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" 16 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h"
17 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 17 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
18 #include "chrome/browser/chromeos/drive/drive_system_service.h" 18 #include "chrome/browser/chromeos/drive/drive_system_service.h"
19 #include "chrome/browser/chromeos/extensions/file_browser_notifications.h" 19 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_notificat ions.h"
20 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h" 20 #include "chrome/browser/chromeos/extensions/file_manager/file_manager_util.h"
21 #include "chrome/browser/chromeos/login/base_login_display_host.h" 21 #include "chrome/browser/chromeos/login/base_login_display_host.h"
22 #include "chrome/browser/chromeos/login/screen_locker.h" 22 #include "chrome/browser/chromeos/login/screen_locker.h"
23 #include "chrome/browser/chromeos/login/user_manager.h" 23 #include "chrome/browser/chromeos/login/user_manager.h"
24 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" 24 #include "chrome/browser/chromeos/net/connectivity_state_helper.h"
25 #include "chrome/browser/extensions/event_names.h" 25 #include "chrome/browser/extensions/event_names.h"
26 #include "chrome/browser/extensions/event_router.h" 26 #include "chrome/browser/extensions/event_router.h"
27 #include "chrome/browser/extensions/extension_service.h" 27 #include "chrome/browser/extensions/extension_service.h"
28 #include "chrome/browser/extensions/extension_system.h" 28 #include "chrome/browser/extensions/extension_system.h"
29 #include "chrome/browser/google_apis/drive_service_interface.h" 29 #include "chrome/browser/google_apis/drive_service_interface.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 // resumes. After the system resumes it will stay in "is_resuming" state for 5 129 // resumes. After the system resumes it will stay in "is_resuming" state for 5
130 // seconds. This is to give DiskManager time to process device removed/added 130 // seconds. This is to give DiskManager time to process device removed/added
131 // events (events for the devices that were present before suspend should not 131 // events (events for the devices that were present before suspend should not
132 // trigger any new notifications or file manager windows). 132 // trigger any new notifications or file manager windows).
133 // The delegate will go into the same state after screen is unlocked. Cros-disks 133 // The delegate will go into the same state after screen is unlocked. Cros-disks
134 // will not send events while the screen is locked. The events will be postponed 134 // will not send events while the screen is locked. The events will be postponed
135 // until the screen is unlocked. These have to be handled too. 135 // until the screen is unlocked. These have to be handled too.
136 class SuspendStateDelegateImpl 136 class SuspendStateDelegateImpl
137 : public chromeos::PowerManagerClient::Observer, 137 : public chromeos::PowerManagerClient::Observer,
138 public chromeos::SessionManagerClient::Observer, 138 public chromeos::SessionManagerClient::Observer,
139 public FileBrowserEventRouter::SuspendStateDelegate { 139 public FileManagerEventRouter::SuspendStateDelegate {
140 public: 140 public:
141 SuspendStateDelegateImpl() 141 SuspendStateDelegateImpl()
142 : is_resuming_(false), 142 : is_resuming_(false),
143 weak_factory_(this) { 143 weak_factory_(this) {
144 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); 144 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this);
145 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this); 145 DBusThreadManager::Get()->GetSessionManagerClient()->AddObserver(this);
146 } 146 }
147 147
148 virtual ~SuspendStateDelegateImpl() { 148 virtual ~SuspendStateDelegateImpl() {
149 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); 149 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this);
(...skipping 23 matching lines...) Expand all
173 is_resuming_ = true; 173 is_resuming_ = true;
174 // Undo any previous resets. 174 // Undo any previous resets.
175 weak_factory_.InvalidateWeakPtrs(); 175 weak_factory_.InvalidateWeakPtrs();
176 base::MessageLoopProxy::current()->PostDelayedTask( 176 base::MessageLoopProxy::current()->PostDelayedTask(
177 FROM_HERE, 177 FROM_HERE,
178 base::Bind(&SuspendStateDelegateImpl::Reset, 178 base::Bind(&SuspendStateDelegateImpl::Reset,
179 weak_factory_.GetWeakPtr()), 179 weak_factory_.GetWeakPtr()),
180 base::TimeDelta::FromSeconds(5)); 180 base::TimeDelta::FromSeconds(5));
181 } 181 }
182 182
183 // FileBrowserEventRouter::SuspendStateDelegate implementation. 183 // FileManagerEventRouter::SuspendStateDelegate implementation.
184 virtual bool SystemIsResuming() const OVERRIDE { 184 virtual bool SystemIsResuming() const OVERRIDE {
185 return is_resuming_; 185 return is_resuming_;
186 } 186 }
187 187
188 // FileBrowserEventRouter::SuspendStateDelegate implementation. 188 // FileManagerEventRouter::SuspendStateDelegate implementation.
189 virtual bool DiskWasPresentBeforeSuspend( 189 virtual bool DiskWasPresentBeforeSuspend(
190 const DiskMountManager::Disk& disk) const OVERRIDE { 190 const DiskMountManager::Disk& disk) const OVERRIDE {
191 // TODO(tbarzic): Implement this. Blocked on http://crbug.com/153338. 191 // TODO(tbarzic): Implement this. Blocked on http://crbug.com/153338.
192 return false; 192 return false;
193 } 193 }
194 194
195 private: 195 private:
196 void Reset() { 196 void Reset() {
197 is_resuming_ = false; 197 is_resuming_ = false;
198 } 198 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 if (!watcher->Watch(watch_path, false /* recursive */, callback)) { 240 if (!watcher->Watch(watch_path, false /* recursive */, callback)) {
241 delete watcher; 241 delete watcher;
242 return NULL; 242 return NULL;
243 } 243 }
244 244
245 return watcher; 245 return watcher;
246 } 246 }
247 247
248 } // namespace 248 } // namespace
249 249
250 FileBrowserEventRouter::FileBrowserEventRouter( 250 FileManagerEventRouter::FileManagerEventRouter(
251 Profile* profile) 251 Profile* profile)
252 : weak_factory_(this), 252 : weak_factory_(this),
253 notifications_(new FileBrowserNotifications(profile)), 253 notifications_(new FileManagerNotifications(profile)),
254 pref_change_registrar_(new PrefChangeRegistrar), 254 pref_change_registrar_(new PrefChangeRegistrar),
255 profile_(profile), 255 profile_(profile),
256 num_remote_update_requests_(0), 256 num_remote_update_requests_(0),
257 shift_pressed_(false) { 257 shift_pressed_(false) {
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
259 259
260 file_watcher_callback_ = 260 file_watcher_callback_ =
261 base::Bind(&FileBrowserEventRouter::HandleFileWatchNotification, 261 base::Bind(&FileManagerEventRouter::HandleFileWatchNotification,
262 weak_factory_.GetWeakPtr()); 262 weak_factory_.GetWeakPtr());
263 263
264 // Listen for the Shift modifier's state changes. 264 // Listen for the Shift modifier's state changes.
265 chromeos::SystemKeyEventListener* key_event_listener = 265 chromeos::SystemKeyEventListener* key_event_listener =
266 chromeos::SystemKeyEventListener::GetInstance(); 266 chromeos::SystemKeyEventListener::GetInstance();
267 if (key_event_listener) 267 if (key_event_listener)
268 key_event_listener->AddModifiersObserver(this); 268 key_event_listener->AddModifiersObserver(this);
269 } 269 }
270 270
271 FileBrowserEventRouter::~FileBrowserEventRouter() { 271 FileManagerEventRouter::~FileManagerEventRouter() {
272 } 272 }
273 273
274 void FileBrowserEventRouter::Shutdown() { 274 void FileManagerEventRouter::Shutdown() {
275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
276 276
277 DLOG_IF(WARNING, !file_watchers_.empty()) << "Not all file watchers are " 277 DLOG_IF(WARNING, !file_watchers_.empty()) << "Not all file watchers are "
278 << "removed. This can happen when Files.app is open during shutdown."; 278 << "removed. This can happen when Files.app is open during shutdown.";
279 STLDeleteValues(&file_watchers_); 279 STLDeleteValues(&file_watchers_);
280 if (!profile_) { 280 if (!profile_) {
281 NOTREACHED(); 281 NOTREACHED();
282 return; 282 return;
283 } 283 }
284 284
(...skipping 13 matching lines...) Expand all
298 system_service->drive_service()->RemoveObserver(this); 298 system_service->drive_service()->RemoveObserver(this);
299 } 299 }
300 300
301 if (chromeos::ConnectivityStateHelper::IsInitialized()) { 301 if (chromeos::ConnectivityStateHelper::IsInitialized()) {
302 chromeos::ConnectivityStateHelper::Get()-> 302 chromeos::ConnectivityStateHelper::Get()->
303 RemoveNetworkManagerObserver(this); 303 RemoveNetworkManagerObserver(this);
304 } 304 }
305 profile_ = NULL; 305 profile_ = NULL;
306 } 306 }
307 307
308 void FileBrowserEventRouter::ObserveFileSystemEvents() { 308 void FileManagerEventRouter::ObserveFileSystemEvents() {
309 if (!profile_) { 309 if (!profile_) {
310 NOTREACHED(); 310 NOTREACHED();
311 return; 311 return;
312 } 312 }
313 if (!chromeos::UserManager::Get()->IsUserLoggedIn()) 313 if (!chromeos::UserManager::Get()->IsUserLoggedIn())
314 return; 314 return;
315 315
316 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance(); 316 DiskMountManager* disk_mount_manager = DiskMountManager::GetInstance();
317 if (disk_mount_manager) { 317 if (disk_mount_manager) {
318 disk_mount_manager->RemoveObserver(this); 318 disk_mount_manager->RemoveObserver(this);
(...skipping 11 matching lines...) Expand all
330 if (chromeos::ConnectivityStateHelper::IsInitialized()) { 330 if (chromeos::ConnectivityStateHelper::IsInitialized()) {
331 chromeos::ConnectivityStateHelper::Get()-> 331 chromeos::ConnectivityStateHelper::Get()->
332 AddNetworkManagerObserver(this); 332 AddNetworkManagerObserver(this);
333 } 333 }
334 suspend_state_delegate_.reset(new SuspendStateDelegateImpl()); 334 suspend_state_delegate_.reset(new SuspendStateDelegateImpl());
335 335
336 pref_change_registrar_->Init(profile_->GetPrefs()); 336 pref_change_registrar_->Init(profile_->GetPrefs());
337 337
338 pref_change_registrar_->Add( 338 pref_change_registrar_->Add(
339 prefs::kExternalStorageDisabled, 339 prefs::kExternalStorageDisabled,
340 base::Bind(&FileBrowserEventRouter::OnExternalStorageDisabledChanged, 340 base::Bind(&FileManagerEventRouter::OnExternalStorageDisabledChanged,
341 weak_factory_.GetWeakPtr())); 341 weak_factory_.GetWeakPtr()));
342 342
343 base::Closure callback = 343 base::Closure callback =
344 base::Bind(&FileBrowserEventRouter::OnFileBrowserPrefsChanged, 344 base::Bind(&FileManagerEventRouter::OnFileManagerPrefsChanged,
345 weak_factory_.GetWeakPtr()); 345 weak_factory_.GetWeakPtr());
346 pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback); 346 pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback);
347 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback); 347 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback);
348 pref_change_registrar_->Add(prefs::kDisableDrive, callback); 348 pref_change_registrar_->Add(prefs::kDisableDrive, callback);
349 pref_change_registrar_->Add(prefs::kUse24HourClock, callback); 349 pref_change_registrar_->Add(prefs::kUse24HourClock, callback);
350 } 350 }
351 351
352 // File watch setup routines. 352 // File watch setup routines.
353 void FileBrowserEventRouter::AddFileWatch( 353 void FileManagerEventRouter::AddFileWatch(
354 const base::FilePath& local_path, 354 const base::FilePath& local_path,
355 const base::FilePath& virtual_path, 355 const base::FilePath& virtual_path,
356 const std::string& extension_id, 356 const std::string& extension_id,
357 const BoolCallback& callback) { 357 const BoolCallback& callback) {
358 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 358 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
359 DCHECK(!callback.is_null()); 359 DCHECK(!callback.is_null());
360 360
361 base::FilePath watch_path = local_path; 361 base::FilePath watch_path = local_path;
362 bool is_remote_watch = false; 362 bool is_remote_watch = false;
363 // Tweak watch path for remote sources - we need to drop leading /special 363 // Tweak watch path for remote sources - we need to drop leading /special
(...skipping 15 matching lines...) Expand all
379 file_watcher_callback_, 379 file_watcher_callback_,
380 callback); 380 callback);
381 file_watchers_[watch_path] = watch.release(); 381 file_watchers_[watch_path] = watch.release();
382 } else { 382 } else {
383 iter->second->AddExtension(extension_id); 383 iter->second->AddExtension(extension_id);
384 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 384 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
385 base::Bind(callback, true)); 385 base::Bind(callback, true));
386 } 386 }
387 } 387 }
388 388
389 void FileBrowserEventRouter::RemoveFileWatch( 389 void FileManagerEventRouter::RemoveFileWatch(
390 const base::FilePath& local_path, 390 const base::FilePath& local_path,
391 const std::string& extension_id) { 391 const std::string& extension_id) {
392 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 392 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
393 393
394 base::FilePath watch_path = local_path; 394 base::FilePath watch_path = local_path;
395 // Tweak watch path for remote sources - we need to drop leading /special 395 // Tweak watch path for remote sources - we need to drop leading /special
396 // directory from there in order to be able to pair these events with 396 // directory from there in order to be able to pair these events with
397 // their change notifications. 397 // their change notifications.
398 if (drive::util::GetSpecialRemoteRootPath().IsParent(watch_path)) { 398 if (drive::util::GetSpecialRemoteRootPath().IsParent(watch_path)) {
399 watch_path = drive::util::ExtractDrivePath(watch_path); 399 watch_path = drive::util::ExtractDrivePath(watch_path);
400 HandleRemoteUpdateRequestOnUIThread(false /* start */); 400 HandleRemoteUpdateRequestOnUIThread(false /* start */);
401 } 401 }
402 WatcherMap::iterator iter = file_watchers_.find(watch_path); 402 WatcherMap::iterator iter = file_watchers_.find(watch_path);
403 if (iter == file_watchers_.end()) 403 if (iter == file_watchers_.end())
404 return; 404 return;
405 // Remove the renderer process for this watch. 405 // Remove the renderer process for this watch.
406 iter->second->RemoveExtension(extension_id); 406 iter->second->RemoveExtension(extension_id);
407 if (iter->second->GetRefCount() == 0) { 407 if (iter->second->GetRefCount() == 0) {
408 delete iter->second; 408 delete iter->second;
409 file_watchers_.erase(iter); 409 file_watchers_.erase(iter);
410 } 410 }
411 } 411 }
412 412
413 void FileBrowserEventRouter::MountDrive( 413 void FileManagerEventRouter::MountDrive(
414 const base::Closure& callback) { 414 const base::Closure& callback) {
415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
416 416
417 // Pass back the gdata mount point path as source path. 417 // Pass back the gdata mount point path as source path.
418 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString(); 418 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString();
419 DiskMountManager::MountPointInfo mount_info( 419 DiskMountManager::MountPointInfo mount_info(
420 gdata_path, 420 gdata_path,
421 gdata_path, 421 gdata_path,
422 chromeos::MOUNT_TYPE_GOOGLE_DRIVE, 422 chromeos::MOUNT_TYPE_GOOGLE_DRIVE,
423 chromeos::disks::MOUNT_CONDITION_NONE); 423 chromeos::disks::MOUNT_CONDITION_NONE);
424 424
425 // Raise mount event. 425 // Raise mount event.
426 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed 426 // We can pass chromeos::MOUNT_ERROR_NONE even when authentication is failed
427 // or network is unreachable. These two errors will be handled later. 427 // or network is unreachable. These two errors will be handled later.
428 OnMountEvent(DiskMountManager::MOUNTING, 428 OnMountEvent(DiskMountManager::MOUNTING,
429 chromeos::MOUNT_ERROR_NONE, 429 chromeos::MOUNT_ERROR_NONE,
430 mount_info); 430 mount_info);
431 431
432 if (!callback.is_null()) 432 if (!callback.is_null())
433 callback.Run(); 433 callback.Run();
434 } 434 }
435 435
436 void FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) { 436 void FileManagerEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) {
437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
438 438
439 drive::DriveFileSystemInterface* file_system = GetRemoteFileSystem(); 439 drive::DriveFileSystemInterface* file_system = GetRemoteFileSystem();
440 // |file_system| is NULL if Drive is disabled. 440 // |file_system| is NULL if Drive is disabled.
441 if (!file_system) 441 if (!file_system)
442 return; 442 return;
443 443
444 if (start) { 444 if (start) {
445 file_system->CheckForUpdates(); 445 file_system->CheckForUpdates();
446 if (num_remote_update_requests_ == 0) 446 if (num_remote_update_requests_ == 0)
447 file_system->StartPolling(); 447 file_system->StartPolling();
448 ++num_remote_update_requests_; 448 ++num_remote_update_requests_;
449 } else { 449 } else {
450 DCHECK_LE(1, num_remote_update_requests_); 450 DCHECK_LE(1, num_remote_update_requests_);
451 --num_remote_update_requests_; 451 --num_remote_update_requests_;
452 if (num_remote_update_requests_ == 0) 452 if (num_remote_update_requests_ == 0)
453 file_system->StopPolling(); 453 file_system->StopPolling();
454 } 454 }
455 } 455 }
456 456
457 void FileBrowserEventRouter::OnDiskEvent( 457 void FileManagerEventRouter::OnDiskEvent(
458 DiskMountManager::DiskEvent event, 458 DiskMountManager::DiskEvent event,
459 const DiskMountManager::Disk* disk) { 459 const DiskMountManager::Disk* disk) {
460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
461 461
462 // Disregard hidden devices. 462 // Disregard hidden devices.
463 if (disk->is_hidden()) 463 if (disk->is_hidden())
464 return; 464 return;
465 if (event == DiskMountManager::DISK_ADDED) { 465 if (event == DiskMountManager::DISK_ADDED) {
466 OnDiskAdded(disk); 466 OnDiskAdded(disk);
467 } else if (event == DiskMountManager::DISK_REMOVED) { 467 } else if (event == DiskMountManager::DISK_REMOVED) {
468 OnDiskRemoved(disk); 468 OnDiskRemoved(disk);
469 } 469 }
470 } 470 }
471 471
472 void FileBrowserEventRouter::OnDeviceEvent( 472 void FileManagerEventRouter::OnDeviceEvent(
473 DiskMountManager::DeviceEvent event, 473 DiskMountManager::DeviceEvent event,
474 const std::string& device_path) { 474 const std::string& device_path) {
475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
476 476
477 if (event == DiskMountManager::DEVICE_ADDED) { 477 if (event == DiskMountManager::DEVICE_ADDED) {
478 OnDeviceAdded(device_path); 478 OnDeviceAdded(device_path);
479 } else if (event == DiskMountManager::DEVICE_REMOVED) { 479 } else if (event == DiskMountManager::DEVICE_REMOVED) {
480 OnDeviceRemoved(device_path); 480 OnDeviceRemoved(device_path);
481 } else if (event == DiskMountManager::DEVICE_SCANNED) { 481 } else if (event == DiskMountManager::DEVICE_SCANNED) {
482 OnDeviceScanned(device_path); 482 OnDeviceScanned(device_path);
483 } 483 }
484 } 484 }
485 485
486 void FileBrowserEventRouter::OnMountEvent( 486 void FileManagerEventRouter::OnMountEvent(
487 DiskMountManager::MountEvent event, 487 DiskMountManager::MountEvent event,
488 chromeos::MountError error_code, 488 chromeos::MountError error_code,
489 const DiskMountManager::MountPointInfo& mount_info) { 489 const DiskMountManager::MountPointInfo& mount_info) {
490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
491 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can 491 // profile_ is NULL if ShutdownOnUIThread() is called earlier. This can
492 // happen at shutdown. 492 // happen at shutdown.
493 if (!profile_) 493 if (!profile_)
494 return; 494 return;
495 495
496 DCHECK(mount_info.mount_type != chromeos::MOUNT_TYPE_INVALID); 496 DCHECK(mount_info.mount_type != chromeos::MOUNT_TYPE_INVALID);
(...skipping 30 matching lines...) Expand all
527 DriveSystemService* system_service = 527 DriveSystemService* system_service =
528 DriveSystemServiceFactory::GetForProfile(profile_); 528 DriveSystemServiceFactory::GetForProfile(profile_);
529 drive::DriveCache* cache = 529 drive::DriveCache* cache =
530 system_service ? system_service->cache() : NULL; 530 system_service ? system_service->cache() : NULL;
531 if (cache && cache->IsUnderDriveCacheDirectory(source_path)) 531 if (cache && cache->IsUnderDriveCacheDirectory(source_path))
532 cache->MarkAsUnmounted(source_path, base::Bind(&OnMarkAsUnmounted)); 532 cache->MarkAsUnmounted(source_path, base::Bind(&OnMarkAsUnmounted));
533 } 533 }
534 } 534 }
535 } 535 }
536 536
537 void FileBrowserEventRouter::OnFormatEvent( 537 void FileManagerEventRouter::OnFormatEvent(
538 DiskMountManager::FormatEvent event, 538 DiskMountManager::FormatEvent event,
539 chromeos::FormatError error_code, 539 chromeos::FormatError error_code,
540 const std::string& device_path) { 540 const std::string& device_path) {
541 if (event == DiskMountManager::FORMAT_STARTED) { 541 if (event == DiskMountManager::FORMAT_STARTED) {
542 OnFormatStarted(device_path, error_code == chromeos::FORMAT_ERROR_NONE); 542 OnFormatStarted(device_path, error_code == chromeos::FORMAT_ERROR_NONE);
543 } else if (event == DiskMountManager::FORMAT_COMPLETED) { 543 } else if (event == DiskMountManager::FORMAT_COMPLETED) {
544 OnFormatCompleted(device_path, error_code == chromeos::FORMAT_ERROR_NONE); 544 OnFormatCompleted(device_path, error_code == chromeos::FORMAT_ERROR_NONE);
545 } 545 }
546 } 546 }
547 547
548 void FileBrowserEventRouter::NetworkManagerChanged() { 548 void FileManagerEventRouter::NetworkManagerChanged() {
549 if (!profile_ || 549 if (!profile_ ||
550 !extensions::ExtensionSystem::Get(profile_)->event_router()) { 550 !extensions::ExtensionSystem::Get(profile_)->event_router()) {
551 NOTREACHED(); 551 NOTREACHED();
552 return; 552 return;
553 } 553 }
554 scoped_ptr<extensions::Event> event(new extensions::Event( 554 scoped_ptr<extensions::Event> event(new extensions::Event(
555 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, 555 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged,
556 scoped_ptr<ListValue>(new ListValue()))); 556 scoped_ptr<ListValue>(new ListValue())));
557 extensions::ExtensionSystem::Get(profile_)->event_router()-> 557 extensions::ExtensionSystem::Get(profile_)->event_router()->
558 BroadcastEvent(event.Pass()); 558 BroadcastEvent(event.Pass());
559 } 559 }
560 560
561 void FileBrowserEventRouter::OnExternalStorageDisabledChanged() { 561 void FileManagerEventRouter::OnExternalStorageDisabledChanged() {
562 // If the policy just got disabled we have to unmount every device currently 562 // If the policy just got disabled we have to unmount every device currently
563 // mounted. The opposite is fine - we can let the user re-plug her device to 563 // mounted. The opposite is fine - we can let the user re-plug her device to
564 // make it available. 564 // make it available.
565 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 565 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
566 DiskMountManager* manager = DiskMountManager::GetInstance(); 566 DiskMountManager* manager = DiskMountManager::GetInstance();
567 DiskMountManager::MountPointMap mounts(manager->mount_points()); 567 DiskMountManager::MountPointMap mounts(manager->mount_points());
568 for (DiskMountManager::MountPointMap::const_iterator it = mounts.begin(); 568 for (DiskMountManager::MountPointMap::const_iterator it = mounts.begin();
569 it != mounts.end(); ++it) { 569 it != mounts.end(); ++it) {
570 LOG(INFO) << "Unmounting " << it->second.mount_path 570 LOG(INFO) << "Unmounting " << it->second.mount_path
571 << " because of policy."; 571 << " because of policy.";
572 manager->UnmountPath(it->second.mount_path, 572 manager->UnmountPath(it->second.mount_path,
573 chromeos::UNMOUNT_OPTIONS_NONE, 573 chromeos::UNMOUNT_OPTIONS_NONE,
574 DiskMountManager::UnmountPathCallback()); 574 DiskMountManager::UnmountPathCallback());
575 } 575 }
576 } 576 }
577 } 577 }
578 578
579 void FileBrowserEventRouter::OnFileBrowserPrefsChanged() { 579 void FileManagerEventRouter::OnFileManagerPrefsChanged() {
580 if (!profile_ || 580 if (!profile_ ||
581 !extensions::ExtensionSystem::Get(profile_)->event_router()) { 581 !extensions::ExtensionSystem::Get(profile_)->event_router()) {
582 NOTREACHED(); 582 NOTREACHED();
583 return; 583 return;
584 } 584 }
585 585
586 scoped_ptr<extensions::Event> event(new extensions::Event( 586 scoped_ptr<extensions::Event> event(new extensions::Event(
587 extensions::event_names::kOnFileBrowserPreferencesChanged, 587 extensions::event_names::kOnFileBrowserPreferencesChanged,
588 scoped_ptr<ListValue>(new ListValue()))); 588 scoped_ptr<ListValue>(new ListValue())));
589 extensions::ExtensionSystem::Get(profile_)->event_router()-> 589 extensions::ExtensionSystem::Get(profile_)->event_router()->
590 BroadcastEvent(event.Pass()); 590 BroadcastEvent(event.Pass());
591 } 591 }
592 592
593 void FileBrowserEventRouter::OnProgressUpdate( 593 void FileManagerEventRouter::OnProgressUpdate(
594 const google_apis::OperationProgressStatusList& list) { 594 const google_apis::OperationProgressStatusList& list) {
595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
596 596
597 scoped_ptr<ListValue> event_list( 597 scoped_ptr<ListValue> event_list(
598 file_manager_util::ProgressStatusVectorToListValue( 598 file_manager_util::ProgressStatusVectorToListValue(
599 profile_, kFileBrowserDomain, list)); 599 profile_, kFileBrowserDomain, list));
600 600
601 scoped_ptr<ListValue> args(new ListValue()); 601 scoped_ptr<ListValue> args(new ListValue());
602 args->Append(event_list.release()); 602 args->Append(event_list.release());
603 scoped_ptr<extensions::Event> event(new extensions::Event( 603 scoped_ptr<extensions::Event> event(new extensions::Event(
604 extensions::event_names::kOnFileTransfersUpdated, args.Pass())); 604 extensions::event_names::kOnFileTransfersUpdated, args.Pass()));
605 extensions::ExtensionSystem::Get(profile_)->event_router()-> 605 extensions::ExtensionSystem::Get(profile_)->event_router()->
606 DispatchEventToExtension(kFileBrowserDomain, event.Pass()); 606 DispatchEventToExtension(kFileBrowserDomain, event.Pass());
607 } 607 }
608 608
609 void FileBrowserEventRouter::OnDirectoryChanged( 609 void FileManagerEventRouter::OnDirectoryChanged(
610 const base::FilePath& directory_path) { 610 const base::FilePath& directory_path) {
611 HandleFileWatchNotification(directory_path, false); 611 HandleFileWatchNotification(directory_path, false);
612 } 612 }
613 613
614 void FileBrowserEventRouter::OnFileSystemMounted() { 614 void FileManagerEventRouter::OnFileSystemMounted() {
615 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 615 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
616 616
617 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing. 617 MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing.
618 } 618 }
619 619
620 void FileBrowserEventRouter::OnModifiersChange(int pressed_modifiers) { 620 void FileManagerEventRouter::OnModifiersChange(int pressed_modifiers) {
621 shift_pressed_ = (pressed_modifiers & SHIFT_PRESSED); 621 shift_pressed_ = (pressed_modifiers & SHIFT_PRESSED);
622 } 622 }
623 623
624 void FileBrowserEventRouter::OnFileSystemBeingUnmounted() { 624 void FileManagerEventRouter::OnFileSystemBeingUnmounted() {
625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 625 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
626 626
627 // Raise a mount event to notify the File Manager. 627 // Raise a mount event to notify the File Manager.
628 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString(); 628 const std::string& gdata_path = drive::util::GetDriveMountPointPathAsString();
629 DiskMountManager::MountPointInfo mount_info( 629 DiskMountManager::MountPointInfo mount_info(
630 gdata_path, 630 gdata_path,
631 gdata_path, 631 gdata_path,
632 chromeos::MOUNT_TYPE_GOOGLE_DRIVE, 632 chromeos::MOUNT_TYPE_GOOGLE_DRIVE,
633 chromeos::disks::MOUNT_CONDITION_NONE); 633 chromeos::disks::MOUNT_CONDITION_NONE);
634 OnMountEvent(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE, 634 OnMountEvent(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE,
635 mount_info); 635 mount_info);
636 } 636 }
637 637
638 void FileBrowserEventRouter::OnRefreshTokenInvalid() { 638 void FileManagerEventRouter::OnRefreshTokenInvalid() {
639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 639 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
640 640
641 // Raise a DriveConnectionStatusChanged event to notify the status offline. 641 // Raise a DriveConnectionStatusChanged event to notify the status offline.
642 scoped_ptr<extensions::Event> event(new extensions::Event( 642 scoped_ptr<extensions::Event> event(new extensions::Event(
643 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged, 643 extensions::event_names::kOnFileBrowserDriveConnectionStatusChanged,
644 scoped_ptr<ListValue>(new ListValue()))); 644 scoped_ptr<ListValue>(new ListValue())));
645 extensions::ExtensionSystem::Get(profile_)->event_router()-> 645 extensions::ExtensionSystem::Get(profile_)->event_router()->
646 BroadcastEvent(event.Pass()); 646 BroadcastEvent(event.Pass());
647 } 647 }
648 648
649 void FileBrowserEventRouter::HandleFileWatchNotification( 649 void FileManagerEventRouter::HandleFileWatchNotification(
650 const base::FilePath& local_path, bool got_error) { 650 const base::FilePath& local_path, bool got_error) {
651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
652 652
653 WatcherMap::const_iterator iter = file_watchers_.find(local_path); 653 WatcherMap::const_iterator iter = file_watchers_.find(local_path);
654 if (iter == file_watchers_.end()) { 654 if (iter == file_watchers_.end()) {
655 return; 655 return;
656 } 656 }
657 DispatchDirectoryChangeEvent(iter->second->GetVirtualPath(), got_error, 657 DispatchDirectoryChangeEvent(iter->second->GetVirtualPath(), got_error,
658 iter->second->GetExtensions()); 658 iter->second->GetExtensions());
659 } 659 }
660 660
661 void FileBrowserEventRouter::DispatchDirectoryChangeEvent( 661 void FileManagerEventRouter::DispatchDirectoryChangeEvent(
662 const base::FilePath& virtual_path, 662 const base::FilePath& virtual_path,
663 bool got_error, 663 bool got_error,
664 const FileBrowserEventRouter::ExtensionUsageRegistry& extensions) { 664 const FileManagerEventRouter::ExtensionUsageRegistry& extensions) {
665 if (!profile_) { 665 if (!profile_) {
666 NOTREACHED(); 666 NOTREACHED();
667 return; 667 return;
668 } 668 }
669 669
670 for (ExtensionUsageRegistry::const_iterator iter = extensions.begin(); 670 for (ExtensionUsageRegistry::const_iterator iter = extensions.begin();
671 iter != extensions.end(); ++iter) { 671 iter != extensions.end(); ++iter) {
672 GURL target_origin_url(extensions::Extension::GetBaseURLFromExtensionId( 672 GURL target_origin_url(extensions::Extension::GetBaseURLFromExtensionId(
673 iter->first)); 673 iter->first));
674 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url, 674 GURL base_url = fileapi::GetFileSystemRootURI(target_origin_url,
(...skipping 10 matching lines...) Expand all
685 ListValue* watch_info_entries = new ListValue(); 685 ListValue* watch_info_entries = new ListValue();
686 watch_info->Set("changedEntries", watch_info_entries); 686 watch_info->Set("changedEntries", watch_info_entries);
687 687
688 scoped_ptr<extensions::Event> event(new extensions::Event( 688 scoped_ptr<extensions::Event> event(new extensions::Event(
689 extensions::event_names::kOnDirectoryChanged, args.Pass())); 689 extensions::event_names::kOnDirectoryChanged, args.Pass()));
690 extensions::ExtensionSystem::Get(profile_)->event_router()-> 690 extensions::ExtensionSystem::Get(profile_)->event_router()->
691 DispatchEventToExtension(iter->first, event.Pass()); 691 DispatchEventToExtension(iter->first, event.Pass());
692 } 692 }
693 } 693 }
694 694
695 void FileBrowserEventRouter::DispatchMountEvent( 695 void FileManagerEventRouter::DispatchMountEvent(
696 DiskMountManager::MountEvent event, 696 DiskMountManager::MountEvent event,
697 chromeos::MountError error_code, 697 chromeos::MountError error_code,
698 const DiskMountManager::MountPointInfo& mount_info) { 698 const DiskMountManager::MountPointInfo& mount_info) {
699 scoped_ptr<ListValue> args(new ListValue()); 699 scoped_ptr<ListValue> args(new ListValue());
700 DictionaryValue* mount_info_value = new DictionaryValue(); 700 DictionaryValue* mount_info_value = new DictionaryValue();
701 args->Append(mount_info_value); 701 args->Append(mount_info_value);
702 mount_info_value->SetString("eventType", 702 mount_info_value->SetString("eventType",
703 event == DiskMountManager::MOUNTING ? "mount" : "unmount"); 703 event == DiskMountManager::MOUNTING ? "mount" : "unmount");
704 mount_info_value->SetString("status", MountErrorToString(error_code)); 704 mount_info_value->SetString("status", MountErrorToString(error_code));
705 mount_info_value->SetString( 705 mount_info_value->SetString(
(...skipping 24 matching lines...) Expand all
730 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED)); 730 MountErrorToString(chromeos::MOUNT_ERROR_PATH_UNMOUNTED));
731 } 731 }
732 } 732 }
733 733
734 scoped_ptr<extensions::Event> extension_event(new extensions::Event( 734 scoped_ptr<extensions::Event> extension_event(new extensions::Event(
735 extensions::event_names::kOnFileBrowserMountCompleted, args.Pass())); 735 extensions::event_names::kOnFileBrowserMountCompleted, args.Pass()));
736 extensions::ExtensionSystem::Get(profile_)->event_router()-> 736 extensions::ExtensionSystem::Get(profile_)->event_router()->
737 BroadcastEvent(extension_event.Pass()); 737 BroadcastEvent(extension_event.Pass());
738 } 738 }
739 739
740 void FileBrowserEventRouter::ShowRemovableDeviceInFileManager( 740 void FileManagerEventRouter::ShowRemovableDeviceInFileManager(
741 const DiskMountManager::Disk& disk, const base::FilePath& mount_path) { 741 const DiskMountManager::Disk& disk, const base::FilePath& mount_path) {
742 // Do not attempt to open File Manager while the login is in progress or 742 // Do not attempt to open File Manager while the login is in progress or
743 // the screen is locked. 743 // the screen is locked.
744 if (chromeos::BaseLoginDisplayHost::default_host() || 744 if (chromeos::BaseLoginDisplayHost::default_host() ||
745 chromeos::ScreenLocker::default_screen_locker()) 745 chromeos::ScreenLocker::default_screen_locker())
746 return; 746 return;
747 747
748 // According to DCF (Design rule of Camera File system) by JEITA / CP-3461 748 // According to DCF (Design rule of Camera File system) by JEITA / CP-3461
749 // cameras should have pictures located in the DCIM root directory. 749 // cameras should have pictures located in the DCIM root directory.
750 const base::FilePath dcim_path = mount_path.Append( 750 const base::FilePath dcim_path = mount_path.Append(
(...skipping 15 matching lines...) Expand all
766 // If there is no DCIM folder or an external photo importer is not available, 766 // If there is no DCIM folder or an external photo importer is not available,
767 // then launch Files.app. 767 // then launch Files.app.
768 DirectoryExistsOnUIThread( 768 DirectoryExistsOnUIThread(
769 dcim_path, 769 dcim_path,
770 external_photo_importer_available ? 770 external_photo_importer_available ?
771 base::Bind(&base::DoNothing) : 771 base::Bind(&base::DoNothing) :
772 base::Bind(&file_manager_util::ViewRemovableDrive, mount_path), 772 base::Bind(&file_manager_util::ViewRemovableDrive, mount_path),
773 base::Bind(&file_manager_util::ViewRemovableDrive, mount_path)); 773 base::Bind(&file_manager_util::ViewRemovableDrive, mount_path));
774 } 774 }
775 775
776 void FileBrowserEventRouter::OnDiskAdded( 776 void FileManagerEventRouter::OnDiskAdded(
777 const DiskMountManager::Disk* disk) { 777 const DiskMountManager::Disk* disk) {
778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 778 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
779 779
780 VLOG(1) << "Disk added: " << disk->device_path(); 780 VLOG(1) << "Disk added: " << disk->device_path();
781 if (disk->device_path().empty()) { 781 if (disk->device_path().empty()) {
782 VLOG(1) << "Empty system path for " << disk->device_path(); 782 VLOG(1) << "Empty system path for " << disk->device_path();
783 return; 783 return;
784 } 784 }
785 785
786 // If disk is not mounted yet and it has media and there is no policy 786 // If disk is not mounted yet and it has media and there is no policy
787 // forbidding external storage, give it a try. 787 // forbidding external storage, give it a try.
788 if (disk->mount_path().empty() && disk->has_media() && 788 if (disk->mount_path().empty() && disk->has_media() &&
789 !profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 789 !profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
790 // Initiate disk mount operation. MountPath auto-detects the filesystem 790 // Initiate disk mount operation. MountPath auto-detects the filesystem
791 // format if the second argument is empty. The third argument (mount label) 791 // format if the second argument is empty. The third argument (mount label)
792 // is not used in a disk mount operation. 792 // is not used in a disk mount operation.
793 DiskMountManager::GetInstance()->MountPath( 793 DiskMountManager::GetInstance()->MountPath(
794 disk->device_path(), std::string(), std::string(), 794 disk->device_path(), std::string(), std::string(),
795 chromeos::MOUNT_TYPE_DEVICE); 795 chromeos::MOUNT_TYPE_DEVICE);
796 } else { 796 } else {
797 // Either the disk was mounted or it has no media. In both cases we don't 797 // Either the disk was mounted or it has no media. In both cases we don't
798 // want the Scanning notification to persist. 798 // want the Scanning notification to persist.
799 notifications_->HideNotification(FileBrowserNotifications::DEVICE, 799 notifications_->HideNotification(FileManagerNotifications::DEVICE,
800 disk->system_path_prefix()); 800 disk->system_path_prefix());
801 } 801 }
802 } 802 }
803 803
804 void FileBrowserEventRouter::OnDiskRemoved( 804 void FileManagerEventRouter::OnDiskRemoved(
805 const DiskMountManager::Disk* disk) { 805 const DiskMountManager::Disk* disk) {
806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 806 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
807 807
808 VLOG(1) << "Disk removed: " << disk->device_path(); 808 VLOG(1) << "Disk removed: " << disk->device_path();
809 809
810 if (!disk->mount_path().empty()) { 810 if (!disk->mount_path().empty()) {
811 DiskMountManager::GetInstance()->UnmountPath( 811 DiskMountManager::GetInstance()->UnmountPath(
812 disk->mount_path(), 812 disk->mount_path(),
813 chromeos::UNMOUNT_OPTIONS_LAZY, 813 chromeos::UNMOUNT_OPTIONS_LAZY,
814 DiskMountManager::UnmountPathCallback()); 814 DiskMountManager::UnmountPathCallback());
815 } 815 }
816 } 816 }
817 817
818 void FileBrowserEventRouter::OnDeviceAdded( 818 void FileManagerEventRouter::OnDeviceAdded(
819 const std::string& device_path) { 819 const std::string& device_path) {
820 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 820 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
821 821
822 VLOG(1) << "Device added : " << device_path; 822 VLOG(1) << "Device added : " << device_path;
823 823
824 // If the policy is set instead of showing the new device notification we show 824 // If the policy is set instead of showing the new device notification we show
825 // a notification that the operation is not permitted. 825 // a notification that the operation is not permitted.
826 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) { 826 if (profile_->GetPrefs()->GetBoolean(prefs::kExternalStorageDisabled)) {
827 notifications_->ShowNotification( 827 notifications_->ShowNotification(
828 FileBrowserNotifications::DEVICE_EXTERNAL_STORAGE_DISABLED, 828 FileManagerNotifications::DEVICE_EXTERNAL_STORAGE_DISABLED,
829 device_path); 829 device_path);
830 return; 830 return;
831 } 831 }
832 832
833 notifications_->RegisterDevice(device_path); 833 notifications_->RegisterDevice(device_path);
834 notifications_->ShowNotificationDelayed(FileBrowserNotifications::DEVICE, 834 notifications_->ShowNotificationDelayed(FileManagerNotifications::DEVICE,
835 device_path, 835 device_path,
836 base::TimeDelta::FromSeconds(5)); 836 base::TimeDelta::FromSeconds(5));
837 } 837 }
838 838
839 void FileBrowserEventRouter::OnDeviceRemoved( 839 void FileManagerEventRouter::OnDeviceRemoved(
840 const std::string& device_path) { 840 const std::string& device_path) {
841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 841 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
842 842
843 VLOG(1) << "Device removed : " << device_path; 843 VLOG(1) << "Device removed : " << device_path;
844 notifications_->HideNotification(FileBrowserNotifications::DEVICE, 844 notifications_->HideNotification(FileManagerNotifications::DEVICE,
845 device_path); 845 device_path);
846 notifications_->HideNotification(FileBrowserNotifications::DEVICE_FAIL, 846 notifications_->HideNotification(FileManagerNotifications::DEVICE_FAIL,
847 device_path); 847 device_path);
848 notifications_->UnregisterDevice(device_path); 848 notifications_->UnregisterDevice(device_path);
849 } 849 }
850 850
851 void FileBrowserEventRouter::OnDeviceScanned( 851 void FileManagerEventRouter::OnDeviceScanned(
852 const std::string& device_path) { 852 const std::string& device_path) {
853 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 853 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
854 VLOG(1) << "Device scanned : " << device_path; 854 VLOG(1) << "Device scanned : " << device_path;
855 } 855 }
856 856
857 void FileBrowserEventRouter::OnFormatStarted( 857 void FileManagerEventRouter::OnFormatStarted(
858 const std::string& device_path, bool success) { 858 const std::string& device_path, bool success) {
859 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 859 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
860 860
861 if (success) { 861 if (success) {
862 notifications_->ShowNotification(FileBrowserNotifications::FORMAT_START, 862 notifications_->ShowNotification(FileManagerNotifications::FORMAT_START,
863 device_path); 863 device_path);
864 } else { 864 } else {
865 notifications_->ShowNotification( 865 notifications_->ShowNotification(
866 FileBrowserNotifications::FORMAT_START_FAIL, device_path); 866 FileManagerNotifications::FORMAT_START_FAIL, device_path);
867 } 867 }
868 } 868 }
869 869
870 void FileBrowserEventRouter::OnFormatCompleted( 870 void FileManagerEventRouter::OnFormatCompleted(
871 const std::string& device_path, bool success) { 871 const std::string& device_path, bool success) {
872 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 872 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
873 873
874 if (success) { 874 if (success) {
875 notifications_->HideNotification(FileBrowserNotifications::FORMAT_START, 875 notifications_->HideNotification(FileManagerNotifications::FORMAT_START,
876 device_path); 876 device_path);
877 notifications_->ShowNotification(FileBrowserNotifications::FORMAT_SUCCESS, 877 notifications_->ShowNotification(FileManagerNotifications::FORMAT_SUCCESS,
878 device_path); 878 device_path);
879 // Hide it after a couple of seconds. 879 // Hide it after a couple of seconds.
880 notifications_->HideNotificationDelayed( 880 notifications_->HideNotificationDelayed(
881 FileBrowserNotifications::FORMAT_SUCCESS, 881 FileManagerNotifications::FORMAT_SUCCESS,
882 device_path, 882 device_path,
883 base::TimeDelta::FromSeconds(4)); 883 base::TimeDelta::FromSeconds(4));
884 // MountPath auto-detects filesystem format if second argument is empty. 884 // MountPath auto-detects filesystem format if second argument is empty.
885 // The third argument (mount label) is not used in a disk mount operation. 885 // The third argument (mount label) is not used in a disk mount operation.
886 DiskMountManager::GetInstance()->MountPath(device_path, std::string(), 886 DiskMountManager::GetInstance()->MountPath(device_path, std::string(),
887 std::string(), 887 std::string(),
888 chromeos::MOUNT_TYPE_DEVICE); 888 chromeos::MOUNT_TYPE_DEVICE);
889 } else { 889 } else {
890 notifications_->HideNotification(FileBrowserNotifications::FORMAT_START, 890 notifications_->HideNotification(FileManagerNotifications::FORMAT_START,
891 device_path); 891 device_path);
892 notifications_->ShowNotification(FileBrowserNotifications::FORMAT_FAIL, 892 notifications_->ShowNotification(FileManagerNotifications::FORMAT_FAIL,
893 device_path); 893 device_path);
894 } 894 }
895 } 895 }
896 896
897 FileBrowserEventRouter::FileWatcherExtensions::FileWatcherExtensions( 897 FileManagerEventRouter::FileWatcherExtensions::FileWatcherExtensions(
898 const base::FilePath& virtual_path, 898 const base::FilePath& virtual_path,
899 const std::string& extension_id, 899 const std::string& extension_id,
900 bool is_remote_file_system) 900 bool is_remote_file_system)
901 : file_watcher_(NULL), 901 : file_watcher_(NULL),
902 virtual_path_(virtual_path), 902 virtual_path_(virtual_path),
903 ref_count_(0), 903 ref_count_(0),
904 is_remote_file_system_(is_remote_file_system), 904 is_remote_file_system_(is_remote_file_system),
905 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 905 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
907 907
908 AddExtension(extension_id); 908 AddExtension(extension_id);
909 } 909 }
910 910
911 FileBrowserEventRouter::FileWatcherExtensions::~FileWatcherExtensions() { 911 FileManagerEventRouter::FileWatcherExtensions::~FileWatcherExtensions() {
912 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 912 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
913 913
914 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, file_watcher_); 914 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, file_watcher_);
915 } 915 }
916 916
917 void FileBrowserEventRouter::FileWatcherExtensions::AddExtension( 917 void FileManagerEventRouter::FileWatcherExtensions::AddExtension(
918 const std::string& extension_id) { 918 const std::string& extension_id) {
919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
920 920
921 ExtensionUsageRegistry::iterator it = extensions_.find(extension_id); 921 ExtensionUsageRegistry::iterator it = extensions_.find(extension_id);
922 if (it != extensions_.end()) { 922 if (it != extensions_.end()) {
923 it->second++; 923 it->second++;
924 } else { 924 } else {
925 extensions_.insert(ExtensionUsageRegistry::value_type(extension_id, 1)); 925 extensions_.insert(ExtensionUsageRegistry::value_type(extension_id, 1));
926 } 926 }
927 927
928 ref_count_++; 928 ref_count_++;
929 } 929 }
930 930
931 void FileBrowserEventRouter::FileWatcherExtensions::RemoveExtension( 931 void FileManagerEventRouter::FileWatcherExtensions::RemoveExtension(
932 const std::string& extension_id) { 932 const std::string& extension_id) {
933 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 933 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
934 934
935 ExtensionUsageRegistry::iterator it = extensions_.find(extension_id); 935 ExtensionUsageRegistry::iterator it = extensions_.find(extension_id);
936 936
937 if (it != extensions_.end()) { 937 if (it != extensions_.end()) {
938 // If entry found - decrease it's count and remove if necessary 938 // If entry found - decrease it's count and remove if necessary
939 if (0 == it->second--) { 939 if (0 == it->second--) {
940 extensions_.erase(it); 940 extensions_.erase(it);
941 } 941 }
942 942
943 ref_count_--; 943 ref_count_--;
944 } else { 944 } else {
945 // Might be reference counting problem - e.g. if some component of 945 // Might be reference counting problem - e.g. if some component of
946 // extension subscribes/unsubscribes correctly, but other component 946 // extension subscribes/unsubscribes correctly, but other component
947 // only unsubscribes, developer of first one might receive this message 947 // only unsubscribes, developer of first one might receive this message
948 LOG(FATAL) << " Extension [" << extension_id 948 LOG(FATAL) << " Extension [" << extension_id
949 << "] tries to unsubscribe from folder [" << local_path_.value() 949 << "] tries to unsubscribe from folder [" << local_path_.value()
950 << "] it isn't subscribed"; 950 << "] it isn't subscribed";
951 } 951 }
952 } 952 }
953 953
954 const FileBrowserEventRouter::ExtensionUsageRegistry& 954 const FileManagerEventRouter::ExtensionUsageRegistry&
955 FileBrowserEventRouter::FileWatcherExtensions::GetExtensions() const { 955 FileManagerEventRouter::FileWatcherExtensions::GetExtensions() const {
956 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 956 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
957 return extensions_; 957 return extensions_;
958 } 958 }
959 959
960 unsigned int 960 unsigned int
961 FileBrowserEventRouter::FileWatcherExtensions::GetRefCount() const { 961 FileManagerEventRouter::FileWatcherExtensions::GetRefCount() const {
962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 962 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
963 return ref_count_; 963 return ref_count_;
964 } 964 }
965 965
966 const base::FilePath& 966 const base::FilePath&
967 FileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { 967 FileManagerEventRouter::FileWatcherExtensions::GetVirtualPath() const {
968 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 968 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
969 return virtual_path_; 969 return virtual_path_;
970 } 970 }
971 971
972 drive::DriveFileSystemInterface* 972 drive::DriveFileSystemInterface*
973 FileBrowserEventRouter::GetRemoteFileSystem() const { 973 FileManagerEventRouter::GetRemoteFileSystem() const {
974 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 974 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
975 DriveSystemService* system_service = 975 DriveSystemService* system_service =
976 DriveSystemServiceFactory::GetForProfile(profile_); 976 DriveSystemServiceFactory::GetForProfile(profile_);
977 return (system_service ? system_service->file_system() : NULL); 977 return (system_service ? system_service->file_system() : NULL);
978 } 978 }
979 979
980 void FileBrowserEventRouter::FileWatcherExtensions::Watch( 980 void FileManagerEventRouter::FileWatcherExtensions::Watch(
981 const base::FilePath& local_path, 981 const base::FilePath& local_path,
982 const base::FilePathWatcher::Callback& file_watcher_callback, 982 const base::FilePathWatcher::Callback& file_watcher_callback,
983 const BoolCallback& callback) { 983 const BoolCallback& callback) {
984 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 984 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
985 DCHECK(!callback.is_null()); 985 DCHECK(!callback.is_null());
986 DCHECK(!file_watcher_); 986 DCHECK(!file_watcher_);
987 987
988 local_path_ = local_path; // For error message in RemoveExtension(). 988 local_path_ = local_path; // For error message in RemoveExtension().
989 989
990 if (is_remote_file_system_) { 990 if (is_remote_file_system_) {
991 base::MessageLoopProxy::current()->PostTask(FROM_HERE, 991 base::MessageLoopProxy::current()->PostTask(FROM_HERE,
992 base::Bind(callback, true)); 992 base::Bind(callback, true));
993 return; 993 return;
994 } 994 }
995 995
996 BrowserThread::PostTaskAndReplyWithResult( 996 BrowserThread::PostTaskAndReplyWithResult(
997 BrowserThread::FILE, 997 BrowserThread::FILE,
998 FROM_HERE, 998 FROM_HERE,
999 base::Bind(&CreateAndStartFilePathWatcher, 999 base::Bind(&CreateAndStartFilePathWatcher,
1000 local_path, 1000 local_path,
1001 base::Bind(&RelayFileWatcherCallbackToUIThread, 1001 base::Bind(&RelayFileWatcherCallbackToUIThread,
1002 file_watcher_callback)), 1002 file_watcher_callback)),
1003 base::Bind( 1003 base::Bind(
1004 &FileBrowserEventRouter::FileWatcherExtensions::OnWatcherStarted, 1004 &FileManagerEventRouter::FileWatcherExtensions::OnWatcherStarted,
1005 weak_ptr_factory_.GetWeakPtr(), 1005 weak_ptr_factory_.GetWeakPtr(),
1006 callback)); 1006 callback));
1007 } 1007 }
1008 1008
1009 void FileBrowserEventRouter::FileWatcherExtensions::OnWatcherStarted( 1009 void FileManagerEventRouter::FileWatcherExtensions::OnWatcherStarted(
1010 const BoolCallback& callback, 1010 const BoolCallback& callback,
1011 base::FilePathWatcher* file_watcher) { 1011 base::FilePathWatcher* file_watcher) {
1012 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1012 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1013 1013
1014 if (file_watcher) { 1014 if (file_watcher) {
1015 file_watcher_ = file_watcher; 1015 file_watcher_ = file_watcher;
1016 callback.Run(true); 1016 callback.Run(true);
1017 } else { 1017 } else {
1018 callback.Run(false); 1018 callback.Run(false);
1019 } 1019 }
1020 } 1020 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698