| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/event_router.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/files/file_util.h" | 8 #include "base/files/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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "chrome/browser/extensions/extension_util.h" | 31 #include "chrome/browser/extensions/extension_util.h" |
| 32 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 33 #include "chrome/browser/profiles/profile_manager.h" | 33 #include "chrome/browser/profiles/profile_manager.h" |
| 34 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 36 #include "chromeos/dbus/dbus_thread_manager.h" | 36 #include "chromeos/dbus/dbus_thread_manager.h" |
| 37 #include "chromeos/login/login_state.h" | 37 #include "chromeos/login/login_state.h" |
| 38 #include "chromeos/network/network_handler.h" | 38 #include "chromeos/network/network_handler.h" |
| 39 #include "chromeos/network/network_state_handler.h" | 39 #include "chromeos/network/network_state_handler.h" |
| 40 #include "content/public/browser/browser_thread.h" | 40 #include "content/public/browser/browser_thread.h" |
| 41 #include "content/public/browser/notification_source.h" | |
| 42 #include "content/public/browser/render_process_host.h" | 41 #include "content/public/browser/render_process_host.h" |
| 43 #include "content/public/browser/storage_partition.h" | 42 #include "content/public/browser/storage_partition.h" |
| 44 #include "extensions/browser/event_router.h" | 43 #include "extensions/browser/event_router.h" |
| 45 #include "extensions/browser/extension_host.h" | 44 #include "extensions/browser/extension_host.h" |
| 46 #include "extensions/browser/extension_prefs.h" | 45 #include "extensions/browser/extension_prefs.h" |
| 47 #include "extensions/browser/extension_system.h" | 46 #include "extensions/browser/extension_system.h" |
| 48 #include "webkit/common/fileapi/file_system_types.h" | 47 #include "webkit/common/fileapi/file_system_types.h" |
| 49 #include "webkit/common/fileapi/file_system_util.h" | 48 #include "webkit/common/fileapi/file_system_util.h" |
| 50 | 49 |
| 51 using chromeos::disks::DiskMountManager; | 50 using chromeos::disks::DiskMountManager; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 return "SecurityError"; | 243 return "SecurityError"; |
| 245 case base::File::FILE_ERROR_NO_SPACE: | 244 case base::File::FILE_ERROR_NO_SPACE: |
| 246 return "QuotaExceededError"; | 245 return "QuotaExceededError"; |
| 247 case base::File::FILE_ERROR_INVALID_URL: | 246 case base::File::FILE_ERROR_INVALID_URL: |
| 248 return "EncodingError"; | 247 return "EncodingError"; |
| 249 default: | 248 default: |
| 250 return "InvalidModificationError"; | 249 return "InvalidModificationError"; |
| 251 } | 250 } |
| 252 } | 251 } |
| 253 | 252 |
| 254 void GrantAccessForAddedProfileToRunningInstance(Profile* added_profile, | |
| 255 Profile* running_profile) { | |
| 256 extensions::ProcessManager* const process_manager = | |
| 257 extensions::ExtensionSystem::Get(running_profile)->process_manager(); | |
| 258 if (!process_manager) | |
| 259 return; | |
| 260 | |
| 261 extensions::ExtensionHost* const extension_host = | |
| 262 process_manager->GetBackgroundHostForExtension(kFileManagerAppId); | |
| 263 if (!extension_host || !extension_host->render_process_host()) | |
| 264 return; | |
| 265 | |
| 266 const int id = extension_host->render_process_host()->GetID(); | |
| 267 file_manager::util::SetupProfileFileAccessPermissions(id, added_profile); | |
| 268 } | |
| 269 | |
| 270 // Checks if we should send a progress event or not according to the | 253 // Checks if we should send a progress event or not according to the |
| 271 // |last_time| of sending an event. If |always| is true, the function always | 254 // |last_time| of sending an event. If |always| is true, the function always |
| 272 // returns true. If the function returns true, the function also updates | 255 // returns true. If the function returns true, the function also updates |
| 273 // |last_time|. | 256 // |last_time|. |
| 274 bool ShouldSendProgressEvent(bool always, base::Time* last_time) { | 257 bool ShouldSendProgressEvent(bool always, base::Time* last_time) { |
| 275 const base::Time now = base::Time::Now(); | 258 const base::Time now = base::Time::Now(); |
| 276 const int64 delta = (now - *last_time).InMilliseconds(); | 259 const int64 delta = (now - *last_time).InMilliseconds(); |
| 277 // delta < 0 may rarely happen if system clock is synced and rewinded. | 260 // delta < 0 may rarely happen if system clock is synced and rewinded. |
| 278 // To be conservative, we don't skip in that case. | 261 // To be conservative, we don't skip in that case. |
| 279 if (!always && 0 <= delta && delta < kProgressEventFrequencyInMilliseconds) { | 262 if (!always && 0 <= delta && delta < kProgressEventFrequencyInMilliseconds) { |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 } | 343 } |
| 361 | 344 |
| 362 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( | 345 EventRouter::DriveJobInfoWithStatus::DriveJobInfoWithStatus( |
| 363 const drive::JobInfo& info, const std::string& status) | 346 const drive::JobInfo& info, const std::string& status) |
| 364 : job_info(info), status(status) { | 347 : job_info(info), status(status) { |
| 365 } | 348 } |
| 366 | 349 |
| 367 EventRouter::EventRouter(Profile* profile) | 350 EventRouter::EventRouter(Profile* profile) |
| 368 : pref_change_registrar_(new PrefChangeRegistrar), | 351 : pref_change_registrar_(new PrefChangeRegistrar), |
| 369 profile_(profile), | 352 profile_(profile), |
| 370 multi_user_window_manager_observer_registered_(false), | |
| 371 device_event_router_(new DeviceEventRouterImpl(profile)), | 353 device_event_router_(new DeviceEventRouterImpl(profile)), |
| 372 weak_factory_(this) { | 354 weak_factory_(this) { |
| 373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 374 } | 356 } |
| 375 | 357 |
| 376 EventRouter::~EventRouter() { | 358 EventRouter::~EventRouter() { |
| 377 } | 359 } |
| 378 | 360 |
| 379 void EventRouter::Shutdown() { | 361 void EventRouter::Shutdown() { |
| 380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 406 VolumeManager* const volume_manager = VolumeManager::Get(profile_); | 388 VolumeManager* const volume_manager = VolumeManager::Get(profile_); |
| 407 if (volume_manager) { | 389 if (volume_manager) { |
| 408 volume_manager->RemoveObserver(this); | 390 volume_manager->RemoveObserver(this); |
| 409 volume_manager->RemoveObserver(device_event_router_.get()); | 391 volume_manager->RemoveObserver(device_event_router_.get()); |
| 410 } | 392 } |
| 411 | 393 |
| 412 chromeos::PowerManagerClient* const power_manager_client = | 394 chromeos::PowerManagerClient* const power_manager_client = |
| 413 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); | 395 chromeos::DBusThreadManager::Get()->GetPowerManagerClient(); |
| 414 power_manager_client->RemoveObserver(device_event_router_.get()); | 396 power_manager_client->RemoveObserver(device_event_router_.get()); |
| 415 | 397 |
| 416 chrome::MultiUserWindowManager* const multi_user_window_manager = | |
| 417 chrome::MultiUserWindowManager::GetInstance(); | |
| 418 if (multi_user_window_manager && | |
| 419 multi_user_window_manager_observer_registered_) { | |
| 420 multi_user_window_manager_observer_registered_ = false; | |
| 421 multi_user_window_manager->RemoveObserver(this); | |
| 422 } | |
| 423 | |
| 424 profile_ = NULL; | 398 profile_ = NULL; |
| 425 } | 399 } |
| 426 | 400 |
| 427 void EventRouter::ObserveEvents() { | 401 void EventRouter::ObserveEvents() { |
| 428 if (!profile_) { | 402 if (!profile_) { |
| 429 NOTREACHED(); | 403 NOTREACHED(); |
| 430 return; | 404 return; |
| 431 } | 405 } |
| 432 if (!chromeos::LoginState::IsInitialized() || | 406 if (!chromeos::LoginState::IsInitialized() || |
| 433 !chromeos::LoginState::Get()->IsUserLoggedIn()) { | 407 !chromeos::LoginState::Get()->IsUserLoggedIn()) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 464 } | 438 } |
| 465 | 439 |
| 466 pref_change_registrar_->Init(profile_->GetPrefs()); | 440 pref_change_registrar_->Init(profile_->GetPrefs()); |
| 467 base::Closure callback = | 441 base::Closure callback = |
| 468 base::Bind(&EventRouter::OnFileManagerPrefsChanged, | 442 base::Bind(&EventRouter::OnFileManagerPrefsChanged, |
| 469 weak_factory_.GetWeakPtr()); | 443 weak_factory_.GetWeakPtr()); |
| 470 pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback); | 444 pref_change_registrar_->Add(prefs::kDisableDriveOverCellular, callback); |
| 471 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback); | 445 pref_change_registrar_->Add(prefs::kDisableDriveHostedFiles, callback); |
| 472 pref_change_registrar_->Add(prefs::kDisableDrive, callback); | 446 pref_change_registrar_->Add(prefs::kDisableDrive, callback); |
| 473 pref_change_registrar_->Add(prefs::kUse24HourClock, callback); | 447 pref_change_registrar_->Add(prefs::kUse24HourClock, callback); |
| 474 | |
| 475 notification_registrar_.Add(this, | |
| 476 chrome::NOTIFICATION_PROFILE_ADDED, | |
| 477 content::NotificationService::AllSources()); | |
| 478 } | 448 } |
| 479 | 449 |
| 480 // File watch setup routines. | 450 // File watch setup routines. |
| 481 void EventRouter::AddFileWatch(const base::FilePath& local_path, | 451 void EventRouter::AddFileWatch(const base::FilePath& local_path, |
| 482 const base::FilePath& virtual_path, | 452 const base::FilePath& virtual_path, |
| 483 const std::string& extension_id, | 453 const std::string& extension_id, |
| 484 const BoolCallback& callback) { | 454 const BoolCallback& callback) { |
| 485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 486 DCHECK(!callback.is_null()); | 456 DCHECK(!callback.is_null()); |
| 487 | 457 |
| (...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 933 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 903 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 934 // Do nothing. | 904 // Do nothing. |
| 935 } | 905 } |
| 936 | 906 |
| 937 void EventRouter::OnFormatCompleted(const std::string& device_path, | 907 void EventRouter::OnFormatCompleted(const std::string& device_path, |
| 938 bool success) { | 908 bool success) { |
| 939 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 909 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 940 // Do nothing. | 910 // Do nothing. |
| 941 } | 911 } |
| 942 | 912 |
| 943 void EventRouter::Observe(int type, | |
| 944 const content::NotificationSource& source, | |
| 945 const content::NotificationDetails& details) { | |
| 946 if (type == chrome::NOTIFICATION_PROFILE_ADDED) { | |
| 947 Profile* const added_profile = content::Source<Profile>(source).ptr(); | |
| 948 if (!added_profile->IsOffTheRecord()) | |
| 949 GrantAccessForAddedProfileToRunningInstance(added_profile, profile_); | |
| 950 | |
| 951 BroadcastEvent(profile_, | |
| 952 file_browser_private::OnProfileAdded::kEventName, | |
| 953 file_browser_private::OnProfileAdded::Create()); | |
| 954 } | |
| 955 } | |
| 956 | |
| 957 void EventRouter::RegisterMultiUserWindowManagerObserver() { | |
| 958 if (multi_user_window_manager_observer_registered_) | |
| 959 return; | |
| 960 chrome::MultiUserWindowManager* const multi_user_window_manager = | |
| 961 chrome::MultiUserWindowManager::GetInstance(); | |
| 962 if (multi_user_window_manager) { | |
| 963 multi_user_window_manager->AddObserver(this); | |
| 964 multi_user_window_manager_observer_registered_ = true; | |
| 965 } | |
| 966 } | |
| 967 | |
| 968 void EventRouter::OnOwnerEntryChanged(aura::Window* window) { | |
| 969 BroadcastEvent(profile_, | |
| 970 file_browser_private::OnDesktopChanged::kEventName, | |
| 971 file_browser_private::OnDesktopChanged::Create()); | |
| 972 } | |
| 973 | |
| 974 } // namespace file_manager | 913 } // namespace file_manager |
| OLD | NEW |