| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/media_galleries/media_galleries_permission_controller.h
" | 5 #include "chrome/browser/media_galleries/media_galleries_permission_controller.h
" |
| 6 | 6 |
| 7 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 } | 282 } |
| 283 | 283 |
| 284 content::WebContents* MediaGalleriesPermissionController::WebContents() { | 284 content::WebContents* MediaGalleriesPermissionController::WebContents() { |
| 285 return web_contents_; | 285 return web_contents_; |
| 286 } | 286 } |
| 287 | 287 |
| 288 void MediaGalleriesPermissionController::FileSelected( | 288 void MediaGalleriesPermissionController::FileSelected( |
| 289 const base::FilePath& path, | 289 const base::FilePath& path, |
| 290 int /*index*/, | 290 int /*index*/, |
| 291 void* /*params*/) { | 291 void* /*params*/) { |
| 292 extensions::file_system_api::SetLastChooseEntryDirectory( | 292 // |web_contents_| is NULL in tests. |
| 293 extensions::ExtensionPrefs::Get(GetProfile()), | 293 if (web_contents_) { |
| 294 extension_->id(), | 294 extensions::file_system_api::SetLastChooseEntryDirectory( |
| 295 path); | 295 extensions::ExtensionPrefs::Get(GetProfile()), |
| 296 extension_->id(), |
| 297 path); |
| 298 } |
| 296 | 299 |
| 297 // Try to find it in the prefs. | 300 // Try to find it in the prefs. |
| 298 MediaGalleryPrefInfo gallery; | 301 MediaGalleryPrefInfo gallery; |
| 299 DCHECK(preferences_); | 302 DCHECK(preferences_); |
| 300 bool gallery_exists = preferences_->LookUpGalleryByPath(path, &gallery); | 303 bool gallery_exists = preferences_->LookUpGalleryByPath(path, &gallery); |
| 301 if (gallery_exists && !gallery.IsBlackListedType()) { | 304 if (gallery_exists && !gallery.IsBlackListedType()) { |
| 302 // The prefs are in sync with |known_galleries_|, so it should exist in | 305 // The prefs are in sync with |known_galleries_|, so it should exist in |
| 303 // |known_galleries_| as well. User selecting a known gallery effectively | 306 // |known_galleries_| as well. User selecting a known gallery effectively |
| 304 // just sets the gallery to permitted. | 307 // just sets the gallery to permitted. |
| 305 GalleryDialogId gallery_id = GetDialogId(gallery.pref_id); | 308 GalleryDialogId gallery_id = GetDialogId(gallery.pref_id); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 316 iter != new_galleries_.end(); ++iter) { | 319 iter != new_galleries_.end(); ++iter) { |
| 317 if (iter->second.pref_info.path == gallery.path && | 320 if (iter->second.pref_info.path == gallery.path && |
| 318 iter->second.pref_info.device_id == gallery.device_id) { | 321 iter->second.pref_info.device_id == gallery.device_id) { |
| 319 iter->second.selected = true; | 322 iter->second.selected = true; |
| 320 dialog_->UpdateGalleries(); | 323 dialog_->UpdateGalleries(); |
| 321 return; | 324 return; |
| 322 } | 325 } |
| 323 } | 326 } |
| 324 | 327 |
| 325 // Lastly, if not found, add a new gallery to |new_galleries_|. | 328 // Lastly, if not found, add a new gallery to |new_galleries_|. |
| 326 DCHECK_EQ(kInvalidMediaGalleryPrefId, gallery.pref_id); | 329 // prefId == kInvalidMediaGalleryPrefId for completely new galleries. |
| 327 gallery.pref_id = GetDialogId(kInvalidMediaGalleryPrefId); | 330 // The old prefId is retained for blacklisted galleries. |
| 331 gallery.pref_id = GetDialogId(gallery.pref_id); |
| 328 new_galleries_[gallery.pref_id] = Entry(gallery, true); | 332 new_galleries_[gallery.pref_id] = Entry(gallery, true); |
| 329 dialog_->UpdateGalleries(); | 333 dialog_->UpdateGalleries(); |
| 330 } | 334 } |
| 331 | 335 |
| 332 void MediaGalleriesPermissionController::OnRemovableStorageAttached( | 336 void MediaGalleriesPermissionController::OnRemovableStorageAttached( |
| 333 const StorageInfo& info) { | 337 const StorageInfo& info) { |
| 334 UpdateGalleriesOnDeviceEvent(info.device_id()); | 338 UpdateGalleriesOnDeviceEvent(info.device_id()); |
| 335 } | 339 } |
| 336 | 340 |
| 337 void MediaGalleriesPermissionController::OnRemovableStorageDetached( | 341 void MediaGalleriesPermissionController::OnRemovableStorageDetached( |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 MediaGalleryPrefId | 549 MediaGalleryPrefId |
| 546 MediaGalleriesPermissionController::DialogIdMap::GetPrefId( | 550 MediaGalleriesPermissionController::DialogIdMap::GetPrefId( |
| 547 GalleryDialogId id) const { | 551 GalleryDialogId id) const { |
| 548 DCHECK_LT(id, next_dialog_id_); | 552 DCHECK_LT(id, next_dialog_id_); |
| 549 return forward_mapping_[id]; | 553 return forward_mapping_[id]; |
| 550 } | 554 } |
| 551 | 555 |
| 552 // MediaGalleries dialog ------------------------------------------------------- | 556 // MediaGalleries dialog ------------------------------------------------------- |
| 553 | 557 |
| 554 MediaGalleriesDialog::~MediaGalleriesDialog() {} | 558 MediaGalleriesDialog::~MediaGalleriesDialog() {} |
| OLD | NEW |