| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" | 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" |
| 6 | 6 |
| 7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 DictionaryValue* result = new DictionaryValue(); | 48 DictionaryValue* result = new DictionaryValue(); |
| 49 result->SetString("mountPath", disk->mount_path()); | 49 result->SetString("mountPath", disk->mount_path()); |
| 50 result->SetString("devicePath", disk->device_path()); | 50 result->SetString("devicePath", disk->device_path()); |
| 51 result->SetString("label", disk->device_label()); | 51 result->SetString("label", disk->device_label()); |
| 52 result->SetString("deviceType", DeviceTypeToString(disk->device_type())); | 52 result->SetString("deviceType", DeviceTypeToString(disk->device_type())); |
| 53 result->SetInteger("totalSizeKB", disk->total_size() / 1024); | 53 result->SetInteger("totalSizeKB", disk->total_size() / 1024); |
| 54 result->SetBoolean("readOnly", disk->is_read_only()); | 54 result->SetBoolean("readOnly", disk->is_read_only()); |
| 55 return result; | 55 return result; |
| 56 } | 56 } |
| 57 | 57 |
| 58 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter() | 58 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter( |
| 59 Profile* profile) |
| 59 : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate()), | 60 : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate()), |
| 60 profile_(NULL) { | 61 profile_(profile) { |
| 61 } | 62 } |
| 62 | 63 |
| 63 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { | 64 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { |
| 64 DCHECK(file_watchers_.empty()); | 65 DCHECK(file_watchers_.empty()); |
| 65 STLDeleteValues(&file_watchers_); | 66 STLDeleteValues(&file_watchers_); |
| 66 | 67 |
| 67 if (!profile_) | 68 if (!profile_) { |
| 69 NOTREACHED(); |
| 68 return; | 70 return; |
| 71 } |
| 69 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) | 72 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) |
| 70 return; | 73 return; |
| 71 chromeos::MountLibrary* lib = | 74 chromeos::MountLibrary* lib = |
| 72 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 75 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| 73 lib->RemoveObserver(this); | 76 lib->RemoveObserver(this); |
| 74 profile_ = NULL; | |
| 75 } | 77 } |
| 76 | 78 |
| 77 // static | 79 void ExtensionFileBrowserEventRouter::Init() { |
| 78 ExtensionFileBrowserEventRouter* | 80 if (!profile_) { |
| 79 ExtensionFileBrowserEventRouter::GetInstance() { | 81 NOTREACHED(); |
| 80 return Singleton<ExtensionFileBrowserEventRouter>::get(); | |
| 81 } | |
| 82 | |
| 83 void ExtensionFileBrowserEventRouter::ObserveFileSystemEvents( | |
| 84 Profile* profile) { | |
| 85 if (!profile) | |
| 86 return; | 82 return; |
| 87 profile_ = profile; | 83 } |
| 88 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) | 84 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) |
| 89 return; | 85 return; |
| 90 if (chromeos::UserManager::Get()->user_is_logged_in()) { | 86 if (chromeos::UserManager::Get()->user_is_logged_in()) { |
| 91 chromeos::MountLibrary* lib = | 87 chromeos::MountLibrary* lib = |
| 92 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 88 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| 93 lib->RemoveObserver(this); | 89 lib->RemoveObserver(this); |
| 94 lib->AddObserver(this); | 90 lib->AddObserver(this); |
| 95 lib->RequestMountInfoRefresh(); | 91 lib->RequestMountInfoRefresh(); |
| 96 } | 92 } |
| 97 } | 93 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 126 if (iter == file_watchers_.end()) | 122 if (iter == file_watchers_.end()) |
| 127 return; | 123 return; |
| 128 // Remove the renderer process for this watch. | 124 // Remove the renderer process for this watch. |
| 129 iter->second->extensions.erase(extension_id); | 125 iter->second->extensions.erase(extension_id); |
| 130 if (iter->second->extensions.empty()) { | 126 if (iter->second->extensions.empty()) { |
| 131 delete iter->second; | 127 delete iter->second; |
| 132 file_watchers_.erase(iter); | 128 file_watchers_.erase(iter); |
| 133 } | 129 } |
| 134 } | 130 } |
| 135 | 131 |
| 136 void ExtensionFileBrowserEventRouter::StopObservingFileSystemEvents() { | |
| 137 if (!profile_) | |
| 138 return; | |
| 139 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) | |
| 140 return; | |
| 141 chromeos::MountLibrary* lib = | |
| 142 chromeos::CrosLibrary::Get()->GetMountLibrary(); | |
| 143 lib->RemoveObserver(this); | |
| 144 profile_ = NULL; | |
| 145 } | |
| 146 | |
| 147 void ExtensionFileBrowserEventRouter::DiskChanged( | 132 void ExtensionFileBrowserEventRouter::DiskChanged( |
| 148 chromeos::MountLibraryEventType event, | 133 chromeos::MountLibraryEventType event, |
| 149 const chromeos::MountLibrary::Disk* disk) { | 134 const chromeos::MountLibrary::Disk* disk) { |
| 150 if (event == chromeos::MOUNT_DISK_ADDED) { | 135 if (event == chromeos::MOUNT_DISK_ADDED) { |
| 151 OnDiskAdded(disk); | 136 OnDiskAdded(disk); |
| 152 } else if (event == chromeos::MOUNT_DISK_REMOVED) { | 137 } else if (event == chromeos::MOUNT_DISK_REMOVED) { |
| 153 OnDiskRemoved(disk); | 138 OnDiskRemoved(disk); |
| 154 } else if (event == chromeos::MOUNT_DISK_CHANGED) { | 139 } else if (event == chromeos::MOUNT_DISK_CHANGED) { |
| 155 OnDiskChanged(disk); | 140 OnDiskChanged(disk); |
| 156 } | 141 } |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 local_path, | 368 local_path, |
| 384 true)); // got_error | 369 true)); // got_error |
| 385 } | 370 } |
| 386 | 371 |
| 387 void | 372 void |
| 388 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( | 373 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( |
| 389 const FilePath& local_path, bool got_error) { | 374 const FilePath& local_path, bool got_error) { |
| 390 ExtensionFileBrowserEventRouter::GetInstance()->HandleFileWatchNotification( | 375 ExtensionFileBrowserEventRouter::GetInstance()->HandleFileWatchNotification( |
| 391 local_path, got_error); | 376 local_path, got_error); |
| 392 } | 377 } |
| OLD | NEW |