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

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

Issue 7466046: Some filebrowser bugs and retiring DiskChanged event in filebrowser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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/utf_string_conversions.h"
9 #include "base/values.h" 10 #include "base/values.h"
10 #include "chrome/browser/chromeos/cros/cros_library.h" 11 #include "chrome/browser/chromeos/cros/cros_library.h"
11 #include "chrome/browser/chromeos/login/user_manager.h" 12 #include "chrome/browser/chromeos/login/user_manager.h"
12 #include "chrome/browser/chromeos/notifications/system_notification.h" 13 #include "chrome/browser/chromeos/notifications/system_notification.h"
13 #include "chrome/browser/extensions/extension_event_names.h" 14 #include "chrome/browser/extensions/extension_event_names.h"
14 #include "chrome/browser/extensions/extension_event_router.h" 15 #include "chrome/browser/extensions/extension_event_router.h"
15 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/file_manager_util.h" 17 #include "chrome/browser/extensions/file_manager_util.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "content/browser/browser_thread.h" 19 #include "content/browser/browser_thread.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 152 }
152 } 153 }
153 154
154 void ExtensionFileBrowserEventRouter::DiskChanged( 155 void ExtensionFileBrowserEventRouter::DiskChanged(
155 chromeos::MountLibraryEventType event, 156 chromeos::MountLibraryEventType event,
156 const chromeos::MountLibrary::Disk* disk) { 157 const chromeos::MountLibrary::Disk* disk) {
157 if (event == chromeos::MOUNT_DISK_ADDED) { 158 if (event == chromeos::MOUNT_DISK_ADDED) {
158 OnDiskAdded(disk); 159 OnDiskAdded(disk);
159 } else if (event == chromeos::MOUNT_DISK_REMOVED) { 160 } else if (event == chromeos::MOUNT_DISK_REMOVED) {
160 OnDiskRemoved(disk); 161 OnDiskRemoved(disk);
161 } else if (event == chromeos::MOUNT_DISK_CHANGED) {
162 OnDiskChanged(disk);
163 } 162 }
164 } 163 }
165 164
166 void ExtensionFileBrowserEventRouter::DeviceChanged( 165 void ExtensionFileBrowserEventRouter::DeviceChanged(
167 chromeos::MountLibraryEventType event, 166 chromeos::MountLibraryEventType event,
168 const std::string& device_path) { 167 const std::string& device_path) {
169 if (event == chromeos::MOUNT_DEVICE_ADDED) { 168 if (event == chromeos::MOUNT_DEVICE_ADDED) {
170 OnDeviceAdded(device_path); 169 OnDeviceAdded(device_path);
171 } else if (event == chromeos::MOUNT_DEVICE_REMOVED) { 170 } else if (event == chromeos::MOUNT_DEVICE_REMOVED) {
172 OnDeviceRemoved(device_path); 171 OnDeviceRemoved(device_path);
173 } else if (event == chromeos::MOUNT_DEVICE_SCANNED) { 172 } else if (event == chromeos::MOUNT_DEVICE_SCANNED) {
174 OnDeviceScanned(device_path); 173 OnDeviceScanned(device_path);
175 } 174 }
176 } 175 }
177 void ExtensionFileBrowserEventRouter::MountCompleted( 176 void ExtensionFileBrowserEventRouter::MountCompleted(
178 chromeos::MountLibrary::MountEvent event_type, 177 chromeos::MountLibrary::MountEvent event_type,
179 chromeos::MountError error_code, 178 chromeos::MountError error_code,
180 const chromeos::MountLibrary::MountPointInfo& mount_info) { 179 const chromeos::MountLibrary::MountPointInfo& mount_info) {
180 if (mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE &&
181 event_type == chromeos::MountLibrary::MOUNTING) {
182 chromeos::MountLibrary* mount_lib =
183 chromeos::CrosLibrary::Get()->GetMountLibrary();
184 chromeos::MountLibrary::Disk* disk =
185 mount_lib->disks().find(mount_info.source_path)->second;
186
187 if (!error_code) {
188 HideDeviceNotification(disk->system_path());
189 } else if (error_code != chromeos::MOUNT_ERROR_UNKNOWN_FILESYSTEM) {
190 // Partitions that are not supposed to be mounted raise unknown filesystem
191 // error.
192 HideDeviceNotification(disk->system_path());
193 if (!disk->drive_label().empty()) {
194 ShowDeviceNotification(disk->system_path(),
195 IDR_PAGEINFO_INFO,
196 // TODO(tbarzic): Find more suitable message.
197 l10n_util::GetStringFUTF16(
198 IDS_FILE_BROWSER_ARCHIVE_MOUNT_FAILED,
199 ASCIIToUTF16(disk->drive_label()),
200 ASCIIToUTF16(MountErrorToString(error_code))));
201 } else {
202 ShowDeviceNotification(disk->system_path(),
203 IDR_PAGEINFO_INFO,
204 // TODO(tbarzic): Find more suitable message.
205 l10n_util::GetStringFUTF16(
206 IDS_FILE_BROWSER_ARCHIVE_MOUNT_FAILED,
207 l10n_util::GetStringUTF16(
208 IDS_FILE_BROWSER_DEVICE_TYPE_UNDEFINED),
209 ASCIIToUTF16(MountErrorToString(error_code))));
210 }
211 }
212 }
213
181 DispatchMountCompletedEvent(event_type, error_code, mount_info); 214 DispatchMountCompletedEvent(event_type, error_code, mount_info);
182 } 215 }
183 216
184 void ExtensionFileBrowserEventRouter::HandleFileWatchNotification( 217 void ExtensionFileBrowserEventRouter::HandleFileWatchNotification(
185 const FilePath& local_path, bool got_error) { 218 const FilePath& local_path, bool got_error) {
186 base::AutoLock lock(lock_); 219 base::AutoLock lock(lock_);
187 WatcherMap::const_iterator iter = file_watchers_.find(local_path); 220 WatcherMap::const_iterator iter = file_watchers_.find(local_path);
188 if (iter == file_watchers_.end()) { 221 if (iter == file_watchers_.end()) {
189 NOTREACHED(); 222 NOTREACHED();
190 return; 223 return;
(...skipping 26 matching lines...) Expand all
217 250
218 std::string args_json; 251 std::string args_json;
219 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); 252 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json);
220 253
221 profile_->GetExtensionEventRouter()->DispatchEventToExtension( 254 profile_->GetExtensionEventRouter()->DispatchEventToExtension(
222 *iter, extension_event_names::kOnFileChanged, args_json, 255 *iter, extension_event_names::kOnFileChanged, args_json,
223 NULL, GURL()); 256 NULL, GURL());
224 } 257 }
225 } 258 }
226 259
227 void ExtensionFileBrowserEventRouter::DispatchMountEvent( 260 void ExtensionFileBrowserEventRouter::DispatchDiskEvent(
228 const chromeos::MountLibrary::Disk* disk, bool added) { 261 const chromeos::MountLibrary::Disk* disk, bool added) {
229 if (!profile_) { 262 if (!profile_) {
230 NOTREACHED(); 263 NOTREACHED();
231 return; 264 return;
232 } 265 }
233 266
234 ListValue args; 267 ListValue args;
235 DictionaryValue* mount_info = new DictionaryValue(); 268 DictionaryValue* mount_info = new DictionaryValue();
236 args.Append(mount_info); 269 args.Append(mount_info);
237 mount_info->SetString("eventType", 270 mount_info->SetString("eventType",
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 if (FileManagerUtil::ConvertFileToFileSystemUrl(profile_, 305 if (FileManagerUtil::ConvertFileToFileSystemUrl(profile_,
273 FilePath(mount_info.source_path), 306 FilePath(mount_info.source_path),
274 FileManagerUtil::GetFileBrowserExtensionUrl().GetOrigin(), 307 FileManagerUtil::GetFileBrowserExtensionUrl().GetOrigin(),
275 &source_url)) { 308 &source_url)) {
276 mount_info_value->SetString("sourceUrl", source_url.spec()); 309 mount_info_value->SetString("sourceUrl", source_url.spec());
277 } 310 }
278 } else { 311 } else {
279 mount_info_value->SetString("sourceUrl", mount_info.source_path); 312 mount_info_value->SetString("sourceUrl", mount_info.source_path);
280 } 313 }
281 314
315 FilePath relative_mount_path;
316 bool relative_mount_path_set = false;
282 // If there were no error, add mountPath to the event. 317 // If there were no error, add mountPath to the event.
283 if (error_code == chromeos::MOUNT_ERROR_NONE) { 318 if (error_code == chromeos::MOUNT_ERROR_NONE) {
284 FilePath relative_mount_path;
285 // Convert mount point path to relative path with the external file system 319 // Convert mount point path to relative path with the external file system
286 // exposed within File API. 320 // exposed within File API.
287 if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_, 321 if (FileManagerUtil::ConvertFileToRelativeFileSystemPath(profile_,
288 FilePath(mount_info.mount_path), 322 FilePath(mount_info.mount_path),
289 &relative_mount_path)) { 323 &relative_mount_path)) {
290 mount_info_value->SetString("mountPath", relative_mount_path.value()); 324 mount_info_value->SetString("mountPath",
325 "/" + relative_mount_path.value());
326 relative_mount_path_set = true;
291 } 327 }
292 } 328 }
293 329
294 std::string args_json; 330 std::string args_json;
295 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json); 331 base::JSONWriter::Write(&args, false /* pretty_print */, &args_json);
296 profile_->GetExtensionEventRouter()->DispatchEventToRenderers( 332 profile_->GetExtensionEventRouter()->DispatchEventToRenderers(
297 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL, 333 extension_event_names::kOnFileBrowserMountCompleted, args_json, NULL,
298 GURL()); 334 GURL());
335
336 if (relative_mount_path_set &&
337 mount_info.mount_type == chromeos::MOUNT_TYPE_DEVICE &&
338 event == chromeos::MountLibrary::MOUNTING) {
339 FileManagerUtil::ShowFullTabUrl(profile_, relative_mount_path);
340 }
299 } 341 }
300 342
301 void ExtensionFileBrowserEventRouter::OnDiskAdded( 343 void ExtensionFileBrowserEventRouter::OnDiskAdded(
302 const chromeos::MountLibrary::Disk* disk) { 344 const chromeos::MountLibrary::Disk* disk) {
303 VLOG(1) << "Disk added: " << disk->device_path(); 345 VLOG(1) << "Disk added: " << disk->device_path();
304 if (disk->device_path().empty()) { 346 if (disk->device_path().empty()) {
305 VLOG(1) << "Empty system path for " << disk->device_path(); 347 VLOG(1) << "Empty system path for " << disk->device_path();
306 return; 348 return;
307 } 349 }
308 if (disk->is_parent()) {
309 if (!disk->has_media()) {
310 HideDeviceNotification(disk->system_path());
311 return;
312 }
313 }
314 350
315 // If disk is not mounted yet, give it a try. 351 // If disk is not mounted yet, give it a try.
316 if (disk->mount_path().empty()) { 352 if (disk->mount_path().empty()) {
317 // Initiate disk mount operation. 353 // Initiate disk mount operation.
318 chromeos::MountLibrary* lib = 354 chromeos::MountLibrary* lib =
319 chromeos::CrosLibrary::Get()->GetMountLibrary(); 355 chromeos::CrosLibrary::Get()->GetMountLibrary();
320 lib->MountPath(disk->device_path().c_str(), 356 lib->MountPath(disk->device_path().c_str(),
321 chromeos::MOUNT_TYPE_DEVICE, 357 chromeos::MOUNT_TYPE_DEVICE,
322 chromeos::MountPathOptions()); // Unused. 358 chromeos::MountPathOptions()); // Unused.
323 } 359 }
360 DispatchDiskEvent(disk, true);
324 } 361 }
325 362
326 void ExtensionFileBrowserEventRouter::OnDiskRemoved( 363 void ExtensionFileBrowserEventRouter::OnDiskRemoved(
327 const chromeos::MountLibrary::Disk* disk) { 364 const chromeos::MountLibrary::Disk* disk) {
328 VLOG(1) << "Disk removed: " << disk->device_path(); 365 VLOG(1) << "Disk removed: " << disk->device_path();
329 HideDeviceNotification(disk->system_path()); 366 HideDeviceNotification(disk->system_path());
330 MountPointMap::iterator iter = mounted_devices_.find(disk->device_path());
331 if (iter == mounted_devices_.end())
332 return;
333 367
334 chromeos::MountLibrary* lib =
335 chromeos::CrosLibrary::Get()->GetMountLibrary();
336 // TODO(zelidrag): This for some reason does not work as advertized.
337 // we might need to clean up mount directory on FILE thread here as well.
338 lib->UnmountPath(disk->device_path().c_str());
339
340 DispatchMountEvent(disk, false);
341 mounted_devices_.erase(iter);
342 }
343
344 void ExtensionFileBrowserEventRouter::OnDiskChanged(
345 const chromeos::MountLibrary::Disk* disk) {
346 VLOG(1) << "Disk changed : " << disk->device_path();
347 if (!disk->mount_path().empty()) { 368 if (!disk->mount_path().empty()) {
348 HideDeviceNotification(disk->system_path()); 369 chromeos::MountLibrary* lib =
349 // Remember this mount point. 370 chromeos::CrosLibrary::Get()->GetMountLibrary();
350 if (mounted_devices_.find(disk->device_path()) == mounted_devices_.end()) { 371 lib->UnmountPath(disk->mount_path().c_str());
351 mounted_devices_.insert(
352 std::pair<std::string, std::string>(disk->device_path(),
353 disk->mount_path()));
354 DispatchMountEvent(disk, true);
355 HideDeviceNotification(disk->system_path());
356 FileManagerUtil::ShowFullTabUrl(profile_, FilePath(disk->mount_path()));
357 }
358 } 372 }
373 DispatchDiskEvent(disk, false);
359 } 374 }
360 375
361 void ExtensionFileBrowserEventRouter::OnDeviceAdded( 376 void ExtensionFileBrowserEventRouter::OnDeviceAdded(
362 const std::string& device_path) { 377 const std::string& device_path) {
363 VLOG(1) << "Device added : " << device_path; 378 VLOG(1) << "Device added : " << device_path;
364 // TODO(zelidrag): Find better icon here. 379 // TODO(zelidrag): Find better icon here.
365 ShowDeviceNotification(device_path, IDR_PAGEINFO_INFO, 380 ShowDeviceNotification(device_path, IDR_PAGEINFO_INFO,
366 l10n_util::GetStringUTF16(IDS_REMOVABLE_DEVICE_SCANNING_MESSAGE)); 381 l10n_util::GetStringUTF16(IDS_REMOVABLE_DEVICE_SCANNING_MESSAGE));
367 382
368 } 383 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 &FileWatcherDelegate::HandleFileWatchOnUIThread, 465 &FileWatcherDelegate::HandleFileWatchOnUIThread,
451 local_path, 466 local_path,
452 true)); // got_error 467 true)); // got_error
453 } 468 }
454 469
455 void 470 void
456 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread( 471 ExtensionFileBrowserEventRouter::FileWatcherDelegate::HandleFileWatchOnUIThread(
457 const FilePath& local_path, bool got_error) { 472 const FilePath& local_path, bool got_error) {
458 router_->HandleFileWatchNotification(local_path, got_error); 473 router_->HandleFileWatchNotification(local_path, got_error);
459 } 474 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698