| 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 29 matching lines...) Expand all Loading... |
| 40 const chromeos::MountLibrary::Disk* disk) { | 40 const chromeos::MountLibrary::Disk* disk) { |
| 41 DictionaryValue* result = new DictionaryValue(); | 41 DictionaryValue* result = new DictionaryValue(); |
| 42 result->SetString("mountPath", disk->mount_path()); | 42 result->SetString("mountPath", disk->mount_path()); |
| 43 result->SetString("label", disk->device_label()); | 43 result->SetString("label", disk->device_label()); |
| 44 result->SetString("deviceType", DeviceTypeToString(disk->device_type())); | 44 result->SetString("deviceType", DeviceTypeToString(disk->device_type())); |
| 45 result->SetInteger("totalSizeKB", disk->total_size() / 1024); | 45 result->SetInteger("totalSizeKB", disk->total_size() / 1024); |
| 46 result->SetBoolean("readOnly", disk->is_read_only()); | 46 result->SetBoolean("readOnly", disk->is_read_only()); |
| 47 return result; | 47 return result; |
| 48 } | 48 } |
| 49 | 49 |
| 50 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter() | 50 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter( |
| 51 : profile_(NULL) { | 51 Profile* profile) |
| 52 : profile_(profile) { |
| 53 DCHECK(profile); |
| 52 } | 54 } |
| 53 | 55 |
| 54 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { | 56 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { |
| 57 if (!profile_) |
| 58 return; |
| 59 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) |
| 60 return; |
| 61 chromeos::MountLibrary* lib = |
| 62 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| 63 lib->RemoveObserver(this); |
| 64 profile_ = NULL; |
| 55 } | 65 } |
| 56 | 66 |
| 57 void ExtensionFileBrowserEventRouter::ObserveFileSystemEvents( | 67 void ExtensionFileBrowserEventRouter::ObserveFileSystemEvents() { |
| 58 Profile* profile) { | |
| 59 if (!profile) | |
| 60 return; | |
| 61 profile_ = profile; | |
| 62 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) | 68 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) |
| 63 return; | 69 return; |
| 64 if (chromeos::UserManager::Get()->user_is_logged_in()) { | 70 if (chromeos::UserManager::Get()->user_is_logged_in()) { |
| 65 chromeos::MountLibrary* lib = | 71 chromeos::MountLibrary* lib = |
| 66 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 72 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| 67 lib->RemoveObserver(this); | 73 lib->RemoveObserver(this); |
| 68 lib->AddObserver(this); | 74 lib->AddObserver(this); |
| 69 lib->RequestMountInfoRefresh(); | 75 lib->RequestMountInfoRefresh(); |
| 70 } | 76 } |
| 71 } | 77 } |
| 72 | 78 |
| 73 void ExtensionFileBrowserEventRouter::StopObservingFileSystemEvents() { | |
| 74 if (!profile_) | |
| 75 return; | |
| 76 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) | |
| 77 return; | |
| 78 chromeos::MountLibrary* lib = | |
| 79 chromeos::CrosLibrary::Get()->GetMountLibrary(); | |
| 80 lib->RemoveObserver(this); | |
| 81 profile_ = NULL; | |
| 82 } | |
| 83 | |
| 84 // static | |
| 85 ExtensionFileBrowserEventRouter* | |
| 86 ExtensionFileBrowserEventRouter::GetInstance() { | |
| 87 return Singleton<ExtensionFileBrowserEventRouter>::get(); | |
| 88 } | |
| 89 | |
| 90 void ExtensionFileBrowserEventRouter::DiskChanged( | 79 void ExtensionFileBrowserEventRouter::DiskChanged( |
| 91 chromeos::MountLibraryEventType event, | 80 chromeos::MountLibraryEventType event, |
| 92 const chromeos::MountLibrary::Disk* disk) { | 81 const chromeos::MountLibrary::Disk* disk) { |
| 93 if (event == chromeos::MOUNT_DISK_ADDED) { | 82 if (event == chromeos::MOUNT_DISK_ADDED) { |
| 94 OnDiskAdded(disk); | 83 OnDiskAdded(disk); |
| 95 } else if (event == chromeos::MOUNT_DISK_REMOVED) { | 84 } else if (event == chromeos::MOUNT_DISK_REMOVED) { |
| 96 OnDiskRemoved(disk); | 85 OnDiskRemoved(disk); |
| 97 } else if (event == chromeos::MOUNT_DISK_CHANGED) { | 86 } else if (event == chromeos::MOUNT_DISK_CHANGED) { |
| 98 OnDiskChanged(disk); | 87 OnDiskChanged(disk); |
| 99 } | 88 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 ++iter) { | 239 ++iter) { |
| 251 const std::string& notification_device_path = iter->first; | 240 const std::string& notification_device_path = iter->first; |
| 252 // Doing a sub string match so that we find if this new one is a subdevice | 241 // Doing a sub string match so that we find if this new one is a subdevice |
| 253 // of another already inserted device. | 242 // of another already inserted device. |
| 254 if (StartsWithASCII(system_path, notification_device_path, true)) { | 243 if (StartsWithASCII(system_path, notification_device_path, true)) { |
| 255 return iter; | 244 return iter; |
| 256 } | 245 } |
| 257 } | 246 } |
| 258 return notifications_.end(); | 247 return notifications_.end(); |
| 259 } | 248 } |
| OLD | NEW |