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

Side by Side Diff: chrome/browser/chromeos/extensions/file_browser_event_router.cc

Issue 7457001: Adding support for mount point different from removable devices to MountLibrary (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: some compile issues Created 9 years, 5 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) 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/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/chromeos/cros/cros_library.h" 10 #include "chrome/browser/chromeos/cros/cros_library.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 DictionaryValue* result = new DictionaryValue(); 47 DictionaryValue* result = new DictionaryValue();
48 result->SetString("mountPath", disk->mount_path()); 48 result->SetString("mountPath", disk->mount_path());
49 result->SetString("devicePath", disk->device_path()); 49 result->SetString("devicePath", disk->device_path());
50 result->SetString("label", disk->device_label()); 50 result->SetString("label", disk->device_label());
51 result->SetString("deviceType", DeviceTypeToString(disk->device_type())); 51 result->SetString("deviceType", DeviceTypeToString(disk->device_type()));
52 result->SetInteger("totalSizeKB", disk->total_size() / 1024); 52 result->SetInteger("totalSizeKB", disk->total_size() / 1024);
53 result->SetBoolean("readOnly", disk->is_read_only()); 53 result->SetBoolean("readOnly", disk->is_read_only());
54 return result; 54 return result;
55 } 55 }
56 56
57 const char* MountErrorToString(chromeos::MountError error) {
58 switch (error) {
59 case chromeos::MOUNT_ERROR_NONE:
60 return "success";
61 case chromeos::MOUNT_ERROR_UNKNOWN:
62 return "error_unknown";
63 case chromeos::MOUNT_ERROR_INTERNAL:
64 return "error_internal";
65 case chromeos::MOUNT_ERROR_UNKNOWN_FILESYSTEM:
66 return "error_unknown_filesystem";
67 case chromeos::MOUNT_ERROR_UNSUPORTED_FILESYSTEM:
68 return "error_unsuported_filesystem";
69 case chromeos::MOUNT_ERROR_INVALID_ARCHIVE:
70 return "error_invalid_archive";
71 case chromeos::MOUNT_ERROR_LIBRARY_NOT_LOADED:
72 return "error_libcros_missing";
73 default:
74 NOTREACHED();
75 }
76 return "";
77 }
78
57 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter( 79 ExtensionFileBrowserEventRouter::ExtensionFileBrowserEventRouter(
58 Profile* profile) 80 Profile* profile)
59 : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate(this)), 81 : delegate_(new ExtensionFileBrowserEventRouter::FileWatcherDelegate(this)),
60 profile_(profile) { 82 profile_(profile) {
61 } 83 }
62 84
63 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() { 85 ExtensionFileBrowserEventRouter::~ExtensionFileBrowserEventRouter() {
64 DCHECK(file_watchers_.empty()); 86 DCHECK(file_watchers_.empty());
65 STLDeleteValues(&file_watchers_); 87 STLDeleteValues(&file_watchers_);
66 88
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 const std::string& device_path) { 168 const std::string& device_path) {
147 if (event == chromeos::MOUNT_DEVICE_ADDED) { 169 if (event == chromeos::MOUNT_DEVICE_ADDED) {
148 OnDeviceAdded(device_path); 170 OnDeviceAdded(device_path);
149 } else if (event == chromeos::MOUNT_DEVICE_REMOVED) { 171 } else if (event == chromeos::MOUNT_DEVICE_REMOVED) {
150 OnDeviceRemoved(device_path); 172 OnDeviceRemoved(device_path);
151 } else if (event == chromeos::MOUNT_DEVICE_SCANNED) { 173 } else if (event == chromeos::MOUNT_DEVICE_SCANNED) {
152 OnDeviceScanned(device_path); 174 OnDeviceScanned(device_path);
153 } 175 }
154 } 176 }
155 177
178 void ExtensionFileBrowserEventRouter::MountCompleted(
179 chromeos::MountLibrary::MountEvent event_type,
180 chromeos::MountError error_code,
181 const std::string& source_path,
182 chromeos::MountType type,
183 const std::string& mount_path) {
184 DispatchMountCompletedEvent(event_type, error_code, source_path, type,
185 mount_path);
186 }
187
156 void ExtensionFileBrowserEventRouter::HandleFileWatchNotification( 188 void ExtensionFileBrowserEventRouter::HandleFileWatchNotification(
157 const FilePath& local_path, bool got_error) { 189 const FilePath& local_path, bool got_error) {
158 base::AutoLock lock(lock_); 190 base::AutoLock lock(lock_);
159 WatcherMap::const_iterator iter = file_watchers_.find(local_path); 191 WatcherMap::const_iterator iter = file_watchers_.find(local_path);
160 if (iter == file_watchers_.end()) { 192 if (iter == file_watchers_.end()) {
161 NOTREACHED(); 193 NOTREACHED();
162 return; 194 return;
163 } 195 }
164 DispatchFolderChangeEvent(iter->second->virtual_path, got_error, 196 DispatchFolderChangeEvent(iter->second->virtual_path, got_error,
165 iter->second->extensions); 197 iter->second->extensions);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 DictionaryValue* disk_info = DiskToDictionaryValue(disk); 243 DictionaryValue* disk_info = DiskToDictionaryValue(disk);
212 mount_info->Set("volumeInfo", disk_info); 244 mount_info->Set("volumeInfo", disk_info);
213 245
214 std::string args_json; 246 std::string args_json;
215 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); 247 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json);
216 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( 248 profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
217 extension_event_names::kOnFileBrowserDiskChanged, args_json, NULL, 249 extension_event_names::kOnFileBrowserDiskChanged, args_json, NULL,
218 GURL()); 250 GURL());
219 } 251 }
220 252
253 void ExtensionFileBrowserEventRouter::DispatchMountCompletedEvent(
254 chromeos::MountLibrary::MountEvent event,
255 chromeos::MountError error_code, const std::string& source_path,
256 chromeos::MountType type, const std::string& mount_path ) {
257 if (!profile_ || type == chromeos::MOUNT_TYPE_INVALID) {
258 NOTREACHED();
259 return;
260 }
261
262 ListValue args;
263 DictionaryValue* mount_info = new DictionaryValue();
264 args.Append(mount_info);
265 mount_info->SetString("sourcePath", source_path);
266 if (event == chromeos::MountLibrary::MOUNTING) {
267 mount_info->SetString("eventType", "mount");
268 } else {
269 mount_info->SetString("eventType", "unmount");
270 }
271 mount_info->SetString("status", MountErrorToString(error_code));
272 chromeos::MountLibrary* lib = chromeos::CrosLibrary::Get()->GetMountLibrary();
273 mount_info->SetString("mountType", lib->MountTypeToString(type));
274 mount_info->SetString("mountPath", mount_path);
275
276 std::string args_json;
277 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json);
278 profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
279 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL,
280 GURL());
281 }
282
221 void ExtensionFileBrowserEventRouter::OnDiskAdded( 283 void ExtensionFileBrowserEventRouter::OnDiskAdded(
222 const chromeos::MountLibrary::Disk* disk) { 284 const chromeos::MountLibrary::Disk* disk) {
223 VLOG(1) << "Disk added: " << disk->device_path(); 285 VLOG(1) << "Disk added: " << disk->device_path();
224 if (disk->device_path().empty()) { 286 if (disk->device_path().empty()) {
225 VLOG(1) << "Empty system path for " << disk->device_path(); 287 VLOG(1) << "Empty system path for " << disk->device_path();
226 return; 288 return;
227 } 289 }
228 if (disk->is_parent()) { 290 if (disk->is_parent()) {
229 if (!disk->has_media()) { 291 if (!disk->has_media()) {
230 HideDeviceNotification(disk->system_path()); 292 HideDeviceNotification(disk->system_path());
231 return; 293 return;
232 } 294 }
233 } 295 }
234 296
235 // If disk is not mounted yet, give it a try. 297 // If disk is not mounted yet, give it a try.
236 if (disk->mount_path().empty()) { 298 if (disk->mount_path().empty()) {
237 // Initiate disk mount operation. 299 // Initiate disk mount operation.
238 chromeos::MountLibrary* lib = 300 chromeos::MountLibrary* lib =
239 chromeos::CrosLibrary::Get()->GetMountLibrary(); 301 chromeos::CrosLibrary::Get()->GetMountLibrary();
240 lib->MountPath(disk->device_path().c_str()); 302 lib->MountPath(disk->device_path().c_str(),
303 chromeos::MOUNT_TYPE_DEVICE,
304 chromeos::MountPathOptions()); // Unused.
241 } 305 }
242 } 306 }
243 307
244 void ExtensionFileBrowserEventRouter::OnDiskRemoved( 308 void ExtensionFileBrowserEventRouter::OnDiskRemoved(
245 const chromeos::MountLibrary::Disk* disk) { 309 const chromeos::MountLibrary::Disk* disk) {
246 VLOG(1) << "Disk removed: " << disk->device_path(); 310 VLOG(1) << "Disk removed: " << disk->device_path();
247 HideDeviceNotification(disk->system_path()); 311 HideDeviceNotification(disk->system_path());
248 MountPointMap::iterator iter = mounted_devices_.find(disk->device_path()); 312 MountPointMap::iterator iter = mounted_devices_.find(disk->device_path());
249 if (iter == mounted_devices_.end()) 313 if (iter == mounted_devices_.end())
250 return; 314 return;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 &FileWatcherDelegate::HandleFileWatchOnUIThread, 432 &FileWatcherDelegate::HandleFileWatchOnUIThread,
369 local_path, 433 local_path,
370 true)); // got_error 434 true)); // got_error
371 } 435 }
372 436
373 void 437 void
374 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( 438 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread(
375 const FilePath& local_path, bool got_error) { 439 const FilePath& local_path, bool got_error) {
376 router_->HandleFileWatchNotification(local_path, got_error); 440 router_->HandleFileWatchNotification(local_path, got_error);
377 } 441 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698