| 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_scan_result_dialog_cont
roller.h" | 5 #include "chrome/browser/media_galleries/media_galleries_scan_result_controller.
h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <list> | 8 #include <list> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/media_galleries/media_file_system_registry.h" | 16 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 17 #include "chrome/browser/media_galleries/media_galleries_histograms.h" | 17 #include "chrome/browser/media_galleries/media_galleries_histograms.h" |
| 18 #include "chrome/browser/media_galleries/media_gallery_context_menu.h" | 18 #include "chrome/browser/media_galleries/media_gallery_context_menu.h" |
| 19 #include "chrome/browser/platform_util.h" | 19 #include "chrome/browser/platform_util.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "components/storage_monitor/storage_info.h" | 21 #include "components/storage_monitor/storage_info.h" |
| 22 #include "components/storage_monitor/storage_monitor.h" | 22 #include "components/storage_monitor/storage_monitor.h" |
| 23 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 25 #include "extensions/common/permissions/media_galleries_permission.h" | 25 #include "extensions/common/permissions/media_galleries_permission.h" |
| 26 #include "extensions/common/permissions/permissions_data.h" | 26 #include "extensions/common/permissions/permissions_data.h" |
| 27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 29 | 29 |
| 30 using storage_monitor::StorageInfo; | 30 using storage_monitor::StorageInfo; |
| 31 using storage_monitor::StorageMonitor; | 31 using storage_monitor::StorageMonitor; |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 // Comparator for sorting OrderedScanResults -- more files first and then sorts | 35 // Comparator for sorting Entries -- more files first and then sorts by |
| 36 // by absolute path. | 36 // absolute path. |
| 37 bool ScanResultsComparator( | 37 bool ScanResultsComparator( |
| 38 const MediaGalleriesScanResultDialogController::ScanResult& a, | 38 const MediaGalleriesDialogController::Entry& a, |
| 39 const MediaGalleriesScanResultDialogController::ScanResult& b) { | 39 const MediaGalleriesDialogController::Entry& b) { |
| 40 int a_media_count = a.pref_info.audio_count + a.pref_info.image_count + | 40 int a_media_count = a.pref_info.audio_count + a.pref_info.image_count + |
| 41 a.pref_info.video_count; | 41 a.pref_info.video_count; |
| 42 int b_media_count = b.pref_info.audio_count + b.pref_info.image_count + | 42 int b_media_count = b.pref_info.audio_count + b.pref_info.image_count + |
| 43 b.pref_info.video_count; | 43 b.pref_info.video_count; |
| 44 if (a_media_count == b_media_count) | 44 if (a_media_count == b_media_count) |
| 45 return a.pref_info.AbsolutePath() < b.pref_info.AbsolutePath(); | 45 return a.pref_info.AbsolutePath() < b.pref_info.AbsolutePath(); |
| 46 return a_media_count > b_media_count; | 46 return a_media_count > b_media_count; |
| 47 } | 47 } |
| 48 | 48 |
| 49 } // namespace | 49 } // namespace |
| 50 | 50 |
| 51 // static | 51 // static |
| 52 size_t MediaGalleriesScanResultDialogController::ScanResultCountForExtension( | 52 size_t MediaGalleriesScanResultController::ScanResultCountForExtension( |
| 53 MediaGalleriesPreferences* preferences, | 53 MediaGalleriesPreferences* preferences, |
| 54 const extensions::Extension* extension) { | 54 const extensions::Extension* extension) { |
| 55 ScanResults scan_results; | 55 ScanResults scan_results; |
| 56 UpdateScanResultsFromPreferences(preferences, extension, | 56 UpdateScanResultsFromPreferences(preferences, extension, |
| 57 MediaGalleryPrefIdSet(), &scan_results); | 57 MediaGalleryPrefIdSet(), &scan_results); |
| 58 return scan_results.size(); | 58 return scan_results.size(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 MediaGalleriesScanResultDialogController:: | 61 MediaGalleriesScanResultController::MediaGalleriesScanResultController( |
| 62 MediaGalleriesScanResultDialogController( | |
| 63 content::WebContents* web_contents, | 62 content::WebContents* web_contents, |
| 64 const extensions::Extension& extension, | 63 const extensions::Extension& extension, |
| 65 const base::Closure& on_finish) | 64 const base::Closure& on_finish) |
| 66 : web_contents_(web_contents), | 65 : web_contents_(web_contents), |
| 67 extension_(&extension), | 66 extension_(&extension), |
| 68 on_finish_(on_finish) { | 67 on_finish_(on_finish), |
| 69 // TODO(vandebo): Put this in the intializer list after GTK is removed. | 68 create_dialog_callback_(base::Bind(&MediaGalleriesDialog::Create)) { |
| 70 #if defined(USE_AURA) || defined(OS_MACOSX) | |
| 71 create_dialog_callback_ = base::Bind(&MediaGalleriesScanResultDialog::Create); | |
| 72 #endif // USE_AURA || OS_MACOSX | |
| 73 preferences_ = | 69 preferences_ = |
| 74 g_browser_process->media_file_system_registry()->GetPreferences( | 70 g_browser_process->media_file_system_registry()->GetPreferences( |
| 75 GetProfile()); | 71 GetProfile()); |
| 76 // Passing unretained pointer is safe, since the dialog controller | 72 // Passing unretained pointer is safe, since the dialog controller |
| 77 // is self-deleting, and so won't be deleted until it can be shown | 73 // is self-deleting, and so won't be deleted until it can be shown |
| 78 // and then closed. | 74 // and then closed. |
| 79 preferences_->EnsureInitialized(base::Bind( | 75 preferences_->EnsureInitialized(base::Bind( |
| 80 &MediaGalleriesScanResultDialogController::OnPreferencesInitialized, | 76 &MediaGalleriesScanResultController::OnPreferencesInitialized, |
| 81 base::Unretained(this))); | 77 base::Unretained(this))); |
| 82 | 78 |
| 83 // Unretained is safe because |this| owns |context_menu_|. | 79 // Unretained is safe because |this| owns |context_menu_|. |
| 84 context_menu_.reset(new MediaGalleryContextMenu(base::Bind( | 80 context_menu_.reset(new MediaGalleryContextMenu(base::Bind( |
| 85 &MediaGalleriesScanResultDialogController::DidForgetGallery, | 81 &MediaGalleriesScanResultController::DidForgetEntry, |
| 86 base::Unretained(this)))); | 82 base::Unretained(this)))); |
| 87 } | 83 } |
| 88 | 84 |
| 89 MediaGalleriesScanResultDialogController:: | 85 MediaGalleriesScanResultController::MediaGalleriesScanResultController( |
| 90 MediaGalleriesScanResultDialogController( | |
| 91 const extensions::Extension& extension, | 86 const extensions::Extension& extension, |
| 92 MediaGalleriesPreferences* preferences, | 87 MediaGalleriesPreferences* preferences, |
| 93 const CreateDialogCallback& create_dialog_callback, | 88 const CreateDialogCallback& create_dialog_callback, |
| 94 const base::Closure& on_finish) | 89 const base::Closure& on_finish) |
| 95 : web_contents_(NULL), | 90 : web_contents_(NULL), |
| 96 extension_(&extension), | 91 extension_(&extension), |
| 97 on_finish_(on_finish), | 92 on_finish_(on_finish), |
| 98 preferences_(preferences), | 93 preferences_(preferences), |
| 99 create_dialog_callback_(create_dialog_callback) { | 94 create_dialog_callback_(create_dialog_callback) { |
| 100 OnPreferencesInitialized(); | 95 OnPreferencesInitialized(); |
| 101 } | 96 } |
| 102 | 97 |
| 103 MediaGalleriesScanResultDialogController:: | 98 MediaGalleriesScanResultController::~MediaGalleriesScanResultController() { |
| 104 ~MediaGalleriesScanResultDialogController() { | |
| 105 // |preferences_| may be NULL in tests. | 99 // |preferences_| may be NULL in tests. |
| 106 if (preferences_) | 100 if (preferences_) |
| 107 preferences_->RemoveGalleryChangeObserver(this); | 101 preferences_->RemoveGalleryChangeObserver(this); |
| 108 if (StorageMonitor::GetInstance()) | 102 if (StorageMonitor::GetInstance()) |
| 109 StorageMonitor::GetInstance()->RemoveObserver(this); | 103 StorageMonitor::GetInstance()->RemoveObserver(this); |
| 110 } | 104 } |
| 111 | 105 |
| 112 base::string16 MediaGalleriesScanResultDialogController::GetHeader() const { | 106 base::string16 MediaGalleriesScanResultController::GetHeader() const { |
| 113 return l10n_util::GetStringFUTF16( | 107 return l10n_util::GetStringFUTF16( |
| 114 IDS_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_HEADER, | 108 IDS_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_HEADER, |
| 115 base::UTF8ToUTF16(extension_->name())); | 109 base::UTF8ToUTF16(extension_->name())); |
| 116 } | 110 } |
| 117 | 111 |
| 118 base::string16 MediaGalleriesScanResultDialogController::GetSubtext() const { | 112 base::string16 MediaGalleriesScanResultController::GetSubtext() const { |
| 119 extensions::MediaGalleriesPermission::CheckParam copy_to_param( | 113 extensions::MediaGalleriesPermission::CheckParam copy_to_param( |
| 120 extensions::MediaGalleriesPermission::kCopyToPermission); | 114 extensions::MediaGalleriesPermission::kCopyToPermission); |
| 121 extensions::MediaGalleriesPermission::CheckParam delete_param( | 115 extensions::MediaGalleriesPermission::CheckParam delete_param( |
| 122 extensions::MediaGalleriesPermission::kDeletePermission); | 116 extensions::MediaGalleriesPermission::kDeletePermission); |
| 123 const extensions::PermissionsData* permissions_data = | 117 const extensions::PermissionsData* permissions_data = |
| 124 extension_->permissions_data(); | 118 extension_->permissions_data(); |
| 125 bool has_copy_to_permission = permissions_data->CheckAPIPermissionWithParam( | 119 bool has_copy_to_permission = permissions_data->CheckAPIPermissionWithParam( |
| 126 extensions::APIPermission::kMediaGalleries, ©_to_param); | 120 extensions::APIPermission::kMediaGalleries, ©_to_param); |
| 127 bool has_delete_permission = permissions_data->CheckAPIPermissionWithParam( | 121 bool has_delete_permission = permissions_data->CheckAPIPermissionWithParam( |
| 128 extensions::APIPermission::kMediaGalleries, &delete_param); | 122 extensions::APIPermission::kMediaGalleries, &delete_param); |
| 129 | 123 |
| 130 int id; | 124 int id; |
| 131 if (has_copy_to_permission) | 125 if (has_copy_to_permission) |
| 132 id = IDS_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_SUBTEXT_READ_WRITE; | 126 id = IDS_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_SUBTEXT_READ_WRITE; |
| 133 else if (has_delete_permission) | 127 else if (has_delete_permission) |
| 134 id = IDS_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_SUBTEXT_READ_DELETE; | 128 id = IDS_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_SUBTEXT_READ_DELETE; |
| 135 else | 129 else |
| 136 id = IDS_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_SUBTEXT_READ_ONLY; | 130 id = IDS_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_SUBTEXT_READ_ONLY; |
| 137 | 131 |
| 138 return l10n_util::GetStringFUTF16(id, base::UTF8ToUTF16(extension_->name())); | 132 return l10n_util::GetStringFUTF16(id, base::UTF8ToUTF16(extension_->name())); |
| 139 } | 133 } |
| 140 | 134 |
| 141 MediaGalleriesScanResultDialogController::OrderedScanResults | 135 bool MediaGalleriesScanResultController::IsAcceptAllowed() const { |
| 142 MediaGalleriesScanResultDialogController::GetGalleryList() const { | 136 return true; |
| 143 OrderedScanResults result; | 137 } |
| 138 |
| 139 bool MediaGalleriesScanResultController::ShouldShowFolderViewer( |
| 140 const Entry& entry) const { |
| 141 return entry.pref_info.IsGalleryAvailable(); |
| 142 } |
| 143 |
| 144 std::vector<base::string16> |
| 145 MediaGalleriesScanResultController::GetSectionHeaders() const { |
| 146 std::vector<base::string16> result; |
| 147 result.push_back(base::string16()); |
| 148 return result; |
| 149 } |
| 150 |
| 151 MediaGalleriesDialogController::Entries |
| 152 MediaGalleriesScanResultController::GetSectionEntries( |
| 153 size_t index) const { |
| 154 DCHECK_EQ(0U, index); |
| 155 Entries result; |
| 144 result.reserve(scan_results_.size()); | 156 result.reserve(scan_results_.size()); |
| 145 for (ScanResults::const_iterator it = scan_results_.begin(); | 157 for (ScanResults::const_iterator it = scan_results_.begin(); |
| 146 it != scan_results_.end(); | 158 it != scan_results_.end(); |
| 147 ++it) { | 159 ++it) { |
| 148 result.push_back(it->second); | 160 result.push_back(it->second); |
| 149 } | 161 } |
| 150 std::sort(result.begin(), result.end(), ScanResultsComparator); | 162 std::sort(result.begin(), result.end(), ScanResultsComparator); |
| 151 return result; | 163 return result; |
| 152 } | 164 } |
| 153 | 165 |
| 154 void MediaGalleriesScanResultDialogController::DidToggleGalleryId( | 166 base::string16 |
| 167 MediaGalleriesScanResultController::GetAuxiliaryButtonText() const { |
| 168 return base::string16(); |
| 169 } |
| 170 |
| 171 void MediaGalleriesScanResultController::DidClickAuxiliaryButton() { |
| 172 NOTREACHED(); |
| 173 } |
| 174 |
| 175 void MediaGalleriesScanResultController::DidToggleEntry( |
| 155 MediaGalleryPrefId pref_id, bool selected) { | 176 MediaGalleryPrefId pref_id, bool selected) { |
| 156 DCHECK(ContainsKey(scan_results_, pref_id)); | 177 DCHECK(ContainsKey(scan_results_, pref_id)); |
| 157 ScanResults::iterator entry = scan_results_.find(pref_id); | 178 ScanResults::iterator entry = scan_results_.find(pref_id); |
| 158 entry->second.selected = selected; | 179 entry->second.selected = selected; |
| 159 } | 180 } |
| 160 | 181 |
| 161 void MediaGalleriesScanResultDialogController::DidClickOpenFolderViewer( | 182 void MediaGalleriesScanResultController::DidClickOpenFolderViewer( |
| 162 MediaGalleryPrefId pref_id) const { | 183 MediaGalleryPrefId pref_id) { |
| 163 ScanResults::const_iterator entry = scan_results_.find(pref_id); | 184 ScanResults::const_iterator entry = scan_results_.find(pref_id); |
| 164 if (entry == scan_results_.end()) { | 185 if (entry == scan_results_.end()) { |
| 165 NOTREACHED(); | 186 NOTREACHED(); |
| 166 return; | 187 return; |
| 167 } | 188 } |
| 168 platform_util::OpenItem(GetProfile(), entry->second.pref_info.AbsolutePath()); | 189 platform_util::OpenItem(GetProfile(), entry->second.pref_info.AbsolutePath()); |
| 169 } | 190 } |
| 170 | 191 |
| 171 void MediaGalleriesScanResultDialogController::DidForgetGallery( | 192 void MediaGalleriesScanResultController::DidForgetEntry( |
| 172 MediaGalleryPrefId pref_id) { | 193 MediaGalleryPrefId pref_id) { |
| 173 media_galleries::UsageCount(media_galleries::ADD_SCAN_RESULTS_FORGET_GALLERY); | 194 media_galleries::UsageCount(media_galleries::ADD_SCAN_RESULTS_FORGET_GALLERY); |
| 174 results_to_remove_.insert(pref_id); | 195 results_to_remove_.insert(pref_id); |
| 175 scan_results_.erase(pref_id); | 196 scan_results_.erase(pref_id); |
| 176 dialog_->UpdateResults(); | 197 dialog_->UpdateGalleries(); |
| 177 } | 198 } |
| 178 | 199 |
| 179 void MediaGalleriesScanResultDialogController::DialogFinished(bool accepted) { | 200 base::string16 MediaGalleriesScanResultController::GetAcceptButtonText() const { |
| 201 return l10n_util::GetStringUTF16( |
| 202 IDS_MEDIA_GALLERIES_SCAN_RESULT_DIALOG_CONFIRM); |
| 203 } |
| 204 |
| 205 void MediaGalleriesScanResultController::DialogFinished(bool accepted) { |
| 180 // No longer interested in preference updates (and the below code generates | 206 // No longer interested in preference updates (and the below code generates |
| 181 // some). | 207 // some). |
| 182 // |preferences_| may be NULL in tests. | 208 // |preferences_| may be NULL in tests. |
| 183 if (preferences_) | 209 if (preferences_) |
| 184 preferences_->RemoveGalleryChangeObserver(this); | 210 preferences_->RemoveGalleryChangeObserver(this); |
| 185 | 211 |
| 186 if (accepted) { | 212 if (accepted) { |
| 187 DCHECK(preferences_); | 213 DCHECK(preferences_); |
| 188 media_galleries::UsageCount(media_galleries::ADD_SCAN_RESULTS_ACCEPTED); | 214 media_galleries::UsageCount(media_galleries::ADD_SCAN_RESULTS_ACCEPTED); |
| 189 int granted = 0; | 215 int granted = 0; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 209 preferences_->ForgetGalleryById(*it); | 235 preferences_->ForgetGalleryById(*it); |
| 210 } | 236 } |
| 211 } else { | 237 } else { |
| 212 media_galleries::UsageCount(media_galleries::ADD_SCAN_RESULTS_CANCELLED); | 238 media_galleries::UsageCount(media_galleries::ADD_SCAN_RESULTS_CANCELLED); |
| 213 } | 239 } |
| 214 | 240 |
| 215 on_finish_.Run(); | 241 on_finish_.Run(); |
| 216 delete this; | 242 delete this; |
| 217 } | 243 } |
| 218 | 244 |
| 219 content::WebContents* MediaGalleriesScanResultDialogController::web_contents() { | 245 ui::MenuModel* MediaGalleriesScanResultController::GetContextMenu( |
| 220 return web_contents_; | |
| 221 } | |
| 222 | |
| 223 ui::MenuModel* MediaGalleriesScanResultDialogController::GetContextMenu( | |
| 224 MediaGalleryPrefId id) { | 246 MediaGalleryPrefId id) { |
| 225 context_menu_->set_pref_id(id); | 247 context_menu_->set_pref_id(id); |
| 226 return context_menu_.get(); | 248 return context_menu_.get(); |
| 227 } | 249 } |
| 228 | 250 |
| 251 content::WebContents* MediaGalleriesScanResultController::WebContents() { |
| 252 return web_contents_; |
| 253 } |
| 254 |
| 229 // static | 255 // static |
| 230 void MediaGalleriesScanResultDialogController::UpdateScanResultsFromPreferences( | 256 void MediaGalleriesScanResultController::UpdateScanResultsFromPreferences( |
| 231 MediaGalleriesPreferences* preferences, | 257 MediaGalleriesPreferences* preferences, |
| 232 const extensions::Extension* extension, | 258 const extensions::Extension* extension, |
| 233 MediaGalleryPrefIdSet ignore_list, ScanResults* scan_results) { | 259 MediaGalleryPrefIdSet ignore_list, |
| 260 ScanResults* scan_results) { |
| 234 DCHECK(preferences->IsInitialized()); | 261 DCHECK(preferences->IsInitialized()); |
| 235 const MediaGalleriesPrefInfoMap& galleries = preferences->known_galleries(); | 262 const MediaGalleriesPrefInfoMap& galleries = preferences->known_galleries(); |
| 236 MediaGalleryPrefIdSet permitted = | 263 MediaGalleryPrefIdSet permitted = |
| 237 preferences->GalleriesForExtension(*extension); | 264 preferences->GalleriesForExtension(*extension); |
| 238 | 265 |
| 239 // Add or update any scan results that the extension doesn't already have | 266 // Add or update any scan results that the extension doesn't already have |
| 240 // access to or isn't in |ignore_list|. | 267 // access to or isn't in |ignore_list|. |
| 241 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); | 268 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); |
| 242 it != galleries.end(); | 269 it != galleries.end(); |
| 243 ++it) { | 270 ++it) { |
| 244 const MediaGalleryPrefInfo& gallery = it->second; | 271 const MediaGalleryPrefInfo& gallery = it->second; |
| 245 if ((gallery.audio_count || gallery.image_count || gallery.video_count) && | 272 if ((gallery.audio_count || gallery.image_count || gallery.video_count) && |
| 246 !gallery.IsBlackListedType() && | 273 !gallery.IsBlackListedType() && |
| 247 !ContainsKey(permitted, gallery.pref_id) && | 274 !ContainsKey(permitted, gallery.pref_id) && |
| 248 !ContainsKey(ignore_list, gallery.pref_id)) { | 275 !ContainsKey(ignore_list, gallery.pref_id)) { |
| 249 ScanResults::iterator existing = scan_results->find(gallery.pref_id); | 276 ScanResults::iterator existing = scan_results->find(gallery.pref_id); |
| 250 if (existing == scan_results->end()) { | 277 if (existing == scan_results->end()) { |
| 251 // Default to selected. | 278 // Default to selected. |
| 252 (*scan_results)[gallery.pref_id] = ScanResult(gallery, true); | 279 (*scan_results)[gallery.pref_id] = Entry(gallery, true); |
| 253 } else { | 280 } else { |
| 254 // Update pref_info, in case anything has been updated. | 281 // Update pref_info, in case anything has been updated. |
| 255 existing->second.pref_info = gallery; | 282 existing->second.pref_info = gallery; |
| 256 } | 283 } |
| 257 } | 284 } |
| 258 } | 285 } |
| 259 | 286 |
| 260 // Remove anything from |scan_results| that's no longer valid or the user | 287 // Remove anything from |scan_results| that's no longer valid or the user |
| 261 // already has access to. | 288 // already has access to. |
| 262 std::list<ScanResults::iterator> to_remove; | 289 std::list<ScanResults::iterator> to_remove; |
| 263 for (ScanResults::iterator it = scan_results->begin(); | 290 for (ScanResults::iterator it = scan_results->begin(); |
| 264 it != scan_results->end(); | 291 it != scan_results->end(); |
| 265 ++it) { | 292 ++it) { |
| 266 MediaGalleriesPrefInfoMap::const_iterator pref_gallery = | 293 MediaGalleriesPrefInfoMap::const_iterator pref_gallery = |
| 267 galleries.find(it->first); | 294 galleries.find(it->first); |
| 268 if (pref_gallery == galleries.end() || | 295 if (pref_gallery == galleries.end() || |
| 269 pref_gallery->second.IsBlackListedType() || | 296 pref_gallery->second.IsBlackListedType() || |
| 270 ContainsKey(permitted, it->first)) { | 297 ContainsKey(permitted, it->first)) { |
| 271 to_remove.push_back(it); | 298 to_remove.push_back(it); |
| 272 } | 299 } |
| 273 } | 300 } |
| 274 while (!to_remove.empty()) { | 301 while (!to_remove.empty()) { |
| 275 scan_results->erase(to_remove.front()); | 302 scan_results->erase(to_remove.front()); |
| 276 to_remove.pop_front(); | 303 to_remove.pop_front(); |
| 277 } | 304 } |
| 278 } | 305 } |
| 279 | 306 |
| 280 void MediaGalleriesScanResultDialogController::OnPreferencesInitialized() { | 307 void MediaGalleriesScanResultController::OnPreferencesInitialized() { |
| 281 // These may be NULL in tests. | 308 // These may be NULL in tests. |
| 282 if (StorageMonitor::GetInstance()) | 309 if (StorageMonitor::GetInstance()) |
| 283 StorageMonitor::GetInstance()->AddObserver(this); | 310 StorageMonitor::GetInstance()->AddObserver(this); |
| 284 if (preferences_) { | 311 if (preferences_) { |
| 285 preferences_->AddGalleryChangeObserver(this); | 312 preferences_->AddGalleryChangeObserver(this); |
| 286 UpdateScanResultsFromPreferences(preferences_, extension_, | 313 UpdateScanResultsFromPreferences(preferences_, extension_, |
| 287 results_to_remove_, &scan_results_); | 314 results_to_remove_, &scan_results_); |
| 288 } | 315 } |
| 289 | 316 |
| 290 // TODO(vandebo): Remove the conditional after GTK is removed. | 317 dialog_.reset(create_dialog_callback_.Run(this)); |
| 291 if (!create_dialog_callback_.is_null()) | |
| 292 dialog_.reset(create_dialog_callback_.Run(this)); | |
| 293 } | 318 } |
| 294 | 319 |
| 295 void MediaGalleriesScanResultDialogController::OnPreferenceUpdate( | 320 void MediaGalleriesScanResultController::OnPreferenceUpdate( |
| 296 const std::string& extension_id) { | 321 const std::string& extension_id) { |
| 297 if (extension_id == extension_->id()) { | 322 if (extension_id == extension_->id()) { |
| 298 UpdateScanResultsFromPreferences(preferences_, extension_, | 323 UpdateScanResultsFromPreferences(preferences_, extension_, |
| 299 results_to_remove_, &scan_results_); | 324 results_to_remove_, &scan_results_); |
| 300 dialog_->UpdateResults(); | 325 dialog_->UpdateGalleries(); |
| 301 } | 326 } |
| 302 } | 327 } |
| 303 | 328 |
| 304 void MediaGalleriesScanResultDialogController::OnRemovableDeviceUpdate( | 329 void MediaGalleriesScanResultController::OnRemovableDeviceUpdate( |
| 305 const std::string device_id) { | 330 const std::string device_id) { |
| 306 for (ScanResults::const_iterator it = scan_results_.begin(); | 331 for (ScanResults::const_iterator it = scan_results_.begin(); |
| 307 it != scan_results_.end(); | 332 it != scan_results_.end(); |
| 308 ++it) { | 333 ++it) { |
| 309 if (it->second.pref_info.device_id == device_id) { | 334 if (it->second.pref_info.device_id == device_id) { |
| 310 dialog_->UpdateResults(); | 335 dialog_->UpdateGalleries(); |
| 311 return; | 336 return; |
| 312 } | 337 } |
| 313 } | 338 } |
| 314 } | 339 } |
| 315 | 340 |
| 316 Profile* MediaGalleriesScanResultDialogController::GetProfile() const { | 341 Profile* MediaGalleriesScanResultController::GetProfile() const { |
| 317 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | 342 return Profile::FromBrowserContext(web_contents_->GetBrowserContext()); |
| 318 } | 343 } |
| 319 | 344 |
| 320 void MediaGalleriesScanResultDialogController::OnRemovableStorageAttached( | 345 void MediaGalleriesScanResultController::OnRemovableStorageAttached( |
| 321 const StorageInfo& info) { | 346 const StorageInfo& info) { |
| 322 OnRemovableDeviceUpdate(info.device_id()); | 347 OnRemovableDeviceUpdate(info.device_id()); |
| 323 } | 348 } |
| 324 | 349 |
| 325 void MediaGalleriesScanResultDialogController::OnRemovableStorageDetached( | 350 void MediaGalleriesScanResultController::OnRemovableStorageDetached( |
| 326 const StorageInfo& info) { | 351 const StorageInfo& info) { |
| 327 OnRemovableDeviceUpdate(info.device_id()); | 352 OnRemovableDeviceUpdate(info.device_id()); |
| 328 } | 353 } |
| 329 | 354 |
| 330 void MediaGalleriesScanResultDialogController::OnPermissionAdded( | 355 void MediaGalleriesScanResultController::OnPermissionAdded( |
| 331 MediaGalleriesPreferences* /*pref*/, | 356 MediaGalleriesPreferences* /*pref*/, |
| 332 const std::string& extension_id, | 357 const std::string& extension_id, |
| 333 MediaGalleryPrefId /*pref_id*/) { | 358 MediaGalleryPrefId /*pref_id*/) { |
| 334 OnPreferenceUpdate(extension_id); | 359 OnPreferenceUpdate(extension_id); |
| 335 } | 360 } |
| 336 | 361 |
| 337 void MediaGalleriesScanResultDialogController::OnPermissionRemoved( | 362 void MediaGalleriesScanResultController::OnPermissionRemoved( |
| 338 MediaGalleriesPreferences* /*pref*/, | 363 MediaGalleriesPreferences* /*pref*/, |
| 339 const std::string& extension_id, | 364 const std::string& extension_id, |
| 340 MediaGalleryPrefId /*pref_id*/) { | 365 MediaGalleryPrefId /*pref_id*/) { |
| 341 OnPreferenceUpdate(extension_id); | 366 OnPreferenceUpdate(extension_id); |
| 342 } | 367 } |
| 343 | 368 |
| 344 void MediaGalleriesScanResultDialogController::OnGalleryAdded( | 369 void MediaGalleriesScanResultController::OnGalleryAdded( |
| 345 MediaGalleriesPreferences* /*prefs*/, | 370 MediaGalleriesPreferences* /*prefs*/, |
| 346 MediaGalleryPrefId /*pref_id*/) { | 371 MediaGalleryPrefId /*pref_id*/) { |
| 347 OnPreferenceUpdate(extension_->id()); | 372 OnPreferenceUpdate(extension_->id()); |
| 348 } | 373 } |
| 349 | 374 |
| 350 void MediaGalleriesScanResultDialogController::OnGalleryRemoved( | 375 void MediaGalleriesScanResultController::OnGalleryRemoved( |
| 351 MediaGalleriesPreferences* /*prefs*/, | 376 MediaGalleriesPreferences* /*prefs*/, |
| 352 MediaGalleryPrefId /*pref_id*/) { | 377 MediaGalleryPrefId /*pref_id*/) { |
| 353 OnPreferenceUpdate(extension_->id()); | 378 OnPreferenceUpdate(extension_->id()); |
| 354 } | 379 } |
| 355 | 380 |
| 356 void MediaGalleriesScanResultDialogController::OnGalleryInfoUpdated( | 381 void MediaGalleriesScanResultController::OnGalleryInfoUpdated( |
| 357 MediaGalleriesPreferences* /*prefs*/, | 382 MediaGalleriesPreferences* /*prefs*/, |
| 358 MediaGalleryPrefId /*pref_id*/) { | 383 MediaGalleryPrefId /*pref_id*/) { |
| 359 OnPreferenceUpdate(extension_->id()); | 384 OnPreferenceUpdate(extension_->id()); |
| 360 } | 385 } |
| 361 | |
| 362 // MediaGalleriesScanResultDialog --------------------------------------------- | |
| 363 | |
| 364 MediaGalleriesScanResultDialog::~MediaGalleriesScanResultDialog() {} | |
| OLD | NEW |