OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 fileapi::kFileSystemTypeExternal); | 230 fileapi::kFileSystemTypeExternal); |
231 GURL target_file_url = GURL(base_url.spec() + virtual_path.value()); | 231 GURL target_file_url = GURL(base_url.spec() + virtual_path.value()); |
232 ListValue args; | 232 ListValue args; |
233 DictionaryValue* watch_info = new DictionaryValue(); | 233 DictionaryValue* watch_info = new DictionaryValue(); |
234 args.Append(watch_info); | 234 args.Append(watch_info); |
235 watch_info->SetString("fileUrl", target_file_url.spec()); | 235 watch_info->SetString("fileUrl", target_file_url.spec()); |
236 watch_info->SetString("eventType", | 236 watch_info->SetString("eventType", |
237 got_error ? kPathWatchError : kPathChanged); | 237 got_error ? kPathWatchError : kPathChanged); |
238 | 238 |
239 std::string args_json; | 239 std::string args_json; |
240 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 240 base::JSONWriter::Write(&args, &args_json); |
241 | 241 |
242 profile_->GetExtensionEventRouter()->DispatchEventToExtension( | 242 profile_->GetExtensionEventRouter()->DispatchEventToExtension( |
243 iter->first, extension_event_names::kOnFileChanged, args_json, | 243 iter->first, extension_event_names::kOnFileChanged, args_json, |
244 NULL, GURL()); | 244 NULL, GURL()); |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 void ExtensionFileBrowserEventRouter::DispatchDiskEvent( | 248 void ExtensionFileBrowserEventRouter::DispatchDiskEvent( |
249 const DiskMountManager::Disk* disk, bool added) { | 249 const DiskMountManager::Disk* disk, bool added) { |
250 if (!profile_) { | 250 if (!profile_) { |
251 NOTREACHED(); | 251 NOTREACHED(); |
252 return; | 252 return; |
253 } | 253 } |
254 | 254 |
255 ListValue args; | 255 ListValue args; |
256 DictionaryValue* mount_info = new DictionaryValue(); | 256 DictionaryValue* mount_info = new DictionaryValue(); |
257 args.Append(mount_info); | 257 args.Append(mount_info); |
258 mount_info->SetString("eventType", | 258 mount_info->SetString("eventType", |
259 added ? kDiskAddedEventType : kDiskRemovedEventType); | 259 added ? kDiskAddedEventType : kDiskRemovedEventType); |
260 DictionaryValue* disk_info = DiskToDictionaryValue(disk); | 260 DictionaryValue* disk_info = DiskToDictionaryValue(disk); |
261 mount_info->Set("volumeInfo", disk_info); | 261 mount_info->Set("volumeInfo", disk_info); |
262 | 262 |
263 std::string args_json; | 263 std::string args_json; |
264 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 264 base::JSONWriter::Write(&args, &args_json); |
265 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 265 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
266 extension_event_names::kOnFileBrowserDiskChanged, args_json, NULL, | 266 extension_event_names::kOnFileBrowserDiskChanged, args_json, NULL, |
267 GURL()); | 267 GURL()); |
268 } | 268 } |
269 | 269 |
270 void ExtensionFileBrowserEventRouter::DispatchMountCompletedEvent( | 270 void ExtensionFileBrowserEventRouter::DispatchMountCompletedEvent( |
271 DiskMountManager::MountEvent event, | 271 DiskMountManager::MountEvent event, |
272 chromeos::MountError error_code, | 272 chromeos::MountError error_code, |
273 const DiskMountManager::MountPointInfo& mount_info) { | 273 const DiskMountManager::MountPointInfo& mount_info) { |
274 if (!profile_ || mount_info.mount_type == chromeos::MOUNT_TYPE_INVALID) { | 274 if (!profile_ || mount_info.mount_type == chromeos::MOUNT_TYPE_INVALID) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 if (file_manager_util::ConvertFileToRelativeFileSystemPath(profile_, | 311 if (file_manager_util::ConvertFileToRelativeFileSystemPath(profile_, |
312 FilePath(mount_info.mount_path), | 312 FilePath(mount_info.mount_path), |
313 &relative_mount_path)) { | 313 &relative_mount_path)) { |
314 mount_info_value->SetString("mountPath", | 314 mount_info_value->SetString("mountPath", |
315 "/" + relative_mount_path.value()); | 315 "/" + relative_mount_path.value()); |
316 relative_mount_path_set = true; | 316 relative_mount_path_set = true; |
317 } | 317 } |
318 } | 318 } |
319 | 319 |
320 std::string args_json; | 320 std::string args_json; |
321 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); | 321 base::JSONWriter::Write(&args, &args_json); |
322 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( | 322 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( |
323 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, | 323 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, |
324 GURL()); | 324 GURL()); |
325 | 325 |
326 if (relative_mount_path_set && | 326 if (relative_mount_path_set && |
327 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && | 327 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE && |
328 !mount_info.mount_condition && | 328 !mount_info.mount_condition && |
329 event == DiskMountManager::MOUNTING) { | 329 event == DiskMountManager::MOUNTING) { |
330 file_manager_util::ViewRemovableDrive(FilePath(mount_info.mount_path)); | 330 file_manager_util::ViewRemovableDrive(FilePath(mount_info.mount_path)); |
331 } | 331 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 | 497 |
498 const FilePath& | 498 const FilePath& |
499 ExtensionFileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { | 499 ExtensionFileBrowserEventRouter::FileWatcherExtensions::GetVirtualPath() const { |
500 return virtual_path; | 500 return virtual_path; |
501 } | 501 } |
502 | 502 |
503 bool ExtensionFileBrowserEventRouter::FileWatcherExtensions::Watch | 503 bool ExtensionFileBrowserEventRouter::FileWatcherExtensions::Watch |
504 (const FilePath& path, FileWatcherDelegate* delegate) { | 504 (const FilePath& path, FileWatcherDelegate* delegate) { |
505 return file_watcher->Watch(path, delegate); | 505 return file_watcher->Watch(path, delegate); |
506 } | 506 } |
OLD | NEW |