Chromium Code Reviews| 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 } | 52 : profile_(profile) { |
| 53 | 53 DCHECK(profile); |
| 54 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { | |
| 55 } | |
| 56 | |
| 57 void ExtensionFileBrowserEventRouter::ObserveFileSystemEvents( | |
| 58 Profile* profile) { | |
| 59 if (!profile) | |
| 60 return; | |
| 61 profile_ = profile; | |
| 62 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) | 54 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) |
| 63 return; | 55 return; |
| 64 if (chromeos::UserManager::Get()->user_is_logged_in()) { | 56 if (chromeos::UserManager::Get()->user_is_logged_in()) { |
| 65 chromeos::MountLibrary* lib = | 57 chromeos::MountLibrary* lib = |
| 66 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 58 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| 67 lib->RemoveObserver(this); | 59 lib->RemoveObserver(this); |
| 68 lib->AddObserver(this); | 60 lib->AddObserver(this); |
| 69 lib->RequestMountInfoRefresh(); | 61 lib->RequestMountInfoRefresh(); |
| 70 } | 62 } |
|
asargent_no_longer_on_chrome
2011/05/24 18:18:00
nit: I think this code block should be moved into
Yoyo Zhou
2011/05/24 19:17:55
Done.
| |
| 71 } | 63 } |
| 72 | 64 |
| 73 void ExtensionFileBrowserEventRouter::StopObservingFileSystemEvents() { | 65 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { |
| 74 if (!profile_) | 66 if (!profile_) |
| 75 return; | 67 return; |
| 76 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) | 68 if (!chromeos::CrosLibrary::Get()->EnsureLoaded()) |
| 77 return; | 69 return; |
| 78 chromeos::MountLibrary* lib = | 70 chromeos::MountLibrary* lib = |
| 79 chromeos::CrosLibrary::Get()->GetMountLibrary(); | 71 chromeos::CrosLibrary::Get()->GetMountLibrary(); |
| 80 lib->RemoveObserver(this); | 72 lib->RemoveObserver(this); |
| 81 profile_ = NULL; | 73 profile_ = NULL; |
| 82 } | 74 } |
| 83 | 75 |
| 84 // static | |
| 85 ExtensionFileBrowserEventRouter* | |
| 86 ExtensionFileBrowserEventRouter::GetInstance() { | |
| 87 return Singleton<ExtensionFileBrowserEventRouter>::get(); | |
| 88 } | |
| 89 | |
| 90 void ExtensionFileBrowserEventRouter::DiskChanged( | 76 void ExtensionFileBrowserEventRouter::DiskChanged( |
| 91 chromeos::MountLibraryEventType event, | 77 chromeos::MountLibraryEventType event, |
| 92 const chromeos::MountLibrary::Disk* disk) { | 78 const chromeos::MountLibrary::Disk* disk) { |
| 93 if (event == chromeos::MOUNT_DISK_ADDED) { | 79 if (event == chromeos::MOUNT_DISK_ADDED) { |
| 94 OnDiskAdded(disk); | 80 OnDiskAdded(disk); |
| 95 } else if (event == chromeos::MOUNT_DISK_REMOVED) { | 81 } else if (event == chromeos::MOUNT_DISK_REMOVED) { |
| 96 OnDiskRemoved(disk); | 82 OnDiskRemoved(disk); |
| 97 } else if (event == chromeos::MOUNT_DISK_CHANGED) { | 83 } else if (event == chromeos::MOUNT_DISK_CHANGED) { |
| 98 OnDiskChanged(disk); | 84 OnDiskChanged(disk); |
| 99 } | 85 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 ++iter) { | 236 ++iter) { |
| 251 const std::string& notification_device_path = iter->first; | 237 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 | 238 // Doing a sub string match so that we find if this new one is a subdevice |
| 253 // of another already inserted device. | 239 // of another already inserted device. |
| 254 if (StartsWithASCII(system_path, notification_device_path, true)) { | 240 if (StartsWithASCII(system_path, notification_device_path, true)) { |
| 255 return iter; | 241 return iter; |
| 256 } | 242 } |
| 257 } | 243 } |
| 258 return notifications_.end(); | 244 return notifications_.end(); |
| 259 } | 245 } |
| OLD | NEW |