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_dialog_cont roller.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" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 const MediaGalleriesPrefInfoMap& galleries = preferences->known_galleries(); | 221 const MediaGalleriesPrefInfoMap& galleries = preferences->known_galleries(); |
222 MediaGalleryPrefIdSet permitted = | 222 MediaGalleryPrefIdSet permitted = |
223 preferences->GalleriesForExtension(*extension); | 223 preferences->GalleriesForExtension(*extension); |
224 | 224 |
225 // Add or update any scan results that the extension doesn't already have | 225 // Add or update any scan results that the extension doesn't already have |
226 // access to or isn't in |results_to_remove_|. | 226 // access to or isn't in |results_to_remove_|. |
227 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); | 227 for (MediaGalleriesPrefInfoMap::const_iterator it = galleries.begin(); |
228 it != galleries.end(); | 228 it != galleries.end(); |
229 ++it) { | 229 ++it) { |
230 const MediaGalleryPrefInfo& gallery = it->second; | 230 const MediaGalleryPrefInfo& gallery = it->second; |
231 if (gallery.type == MediaGalleryPrefInfo::kScanResult && | 231 if ((gallery.audio_count || gallery.image_count || gallery.video_count) && |
tommycli
2014/02/10 18:45:53
I believe this will cause galleries with zero audi
vandebo (ex-Chrome)
2014/02/11 19:19:31
Yes, it will hide galleries with no media files.
| |
232 !gallery.IsBlackListedType() && | |
232 !ContainsKey(permitted, gallery.pref_id) && | 233 !ContainsKey(permitted, gallery.pref_id) && |
233 !ContainsKey(ignore_list, gallery.pref_id)) { | 234 !ContainsKey(ignore_list, gallery.pref_id)) { |
234 ScanResults::iterator existing = scan_results->find(gallery.pref_id); | 235 ScanResults::iterator existing = scan_results->find(gallery.pref_id); |
235 if (existing == scan_results->end()) { | 236 if (existing == scan_results->end()) { |
236 // Default to selected. | 237 // Default to selected. |
237 (*scan_results)[gallery.pref_id] = ScanResult(gallery, true); | 238 (*scan_results)[gallery.pref_id] = ScanResult(gallery, true); |
238 } else { | 239 } else { |
239 // Update pref_info, in case anything has been updated. | 240 // Update pref_info, in case anything has been updated. |
240 existing->second.pref_info = gallery; | 241 existing->second.pref_info = gallery; |
241 } | 242 } |
242 } | 243 } |
243 } | 244 } |
244 | 245 |
245 // Remove anything from |scan_results_| that's no longer valid or the user | 246 // Remove anything from |scan_results_| that's no longer valid or the user |
246 // already has access to. | 247 // already has access to. |
247 std::list<ScanResults::iterator> to_remove; | 248 std::list<ScanResults::iterator> to_remove; |
248 for (ScanResults::iterator it = scan_results->begin(); | 249 for (ScanResults::iterator it = scan_results->begin(); |
249 it != scan_results->end(); | 250 it != scan_results->end(); |
250 ++it) { | 251 ++it) { |
251 MediaGalleriesPrefInfoMap::const_iterator pref_gallery = | 252 MediaGalleriesPrefInfoMap::const_iterator pref_gallery = |
252 galleries.find(it->first); | 253 galleries.find(it->first); |
253 if (pref_gallery == galleries.end() || | 254 if (pref_gallery == galleries.end() || |
254 pref_gallery->second.type != MediaGalleryPrefInfo::kScanResult || | 255 pref_gallery->second.IsBlackListedType() || |
255 permitted.find(it->first) != permitted.end()) { | 256 ContainsKey(permitted, it->first)) { |
256 to_remove.push_back(it); | 257 to_remove.push_back(it); |
257 } | 258 } |
258 } | 259 } |
259 while (!to_remove.empty()) { | 260 while (!to_remove.empty()) { |
260 scan_results->erase(to_remove.front()); | 261 scan_results->erase(to_remove.front()); |
261 to_remove.pop_front(); | 262 to_remove.pop_front(); |
262 } | 263 } |
263 } | 264 } |
264 | 265 |
265 void MediaGalleriesScanResultDialogController::OnPreferencesInitialized() { | 266 void MediaGalleriesScanResultDialogController::OnPreferencesInitialized() { |
266 // These may be NULL in tests. | 267 // These may be NULL in tests. |
267 if (StorageMonitor::GetInstance()) | 268 if (StorageMonitor::GetInstance()) |
268 StorageMonitor::GetInstance()->AddObserver(this); | 269 StorageMonitor::GetInstance()->AddObserver(this); |
269 if (preferences_) { | 270 if (preferences_) { |
270 preferences_->AddGalleryChangeObserver(this); | 271 preferences_->AddGalleryChangeObserver(this); |
271 UpdateScanResultsFromPreferences(preferences_, extension_, | 272 UpdateScanResultsFromPreferences(preferences_, extension_, |
272 results_to_remove_, &scan_results_); | 273 results_to_remove_, &scan_results_); |
273 } | 274 } |
274 | 275 |
275 // TODO(vandebo): Remove the conditional after GTK is removed. | 276 // TODO(vandebo): Remove the conditional after GTK is removed. |
276 if (!create_dialog_callback_.is_null()) | 277 if (!create_dialog_callback_.is_null()) |
277 dialog_.reset(create_dialog_callback_.Run(this)); | 278 dialog_.reset(create_dialog_callback_.Run(this)); |
278 } | 279 } |
279 | 280 |
280 void MediaGalleriesScanResultDialogController::OnPreferenceUpdate( | 281 void MediaGalleriesScanResultDialogController::OnPreferenceUpdate( |
281 const std::string& extension_id, MediaGalleryPrefId pref_id) { | 282 const std::string& extension_id, MediaGalleryPrefId pref_id) { |
282 if (extension_id == extension_->id()) { | 283 if (extension_id == extension_->id()) { |
283 const MediaGalleriesPrefInfoMap::const_iterator it = | 284 UpdateScanResultsFromPreferences(preferences_, extension_, |
284 preferences_->known_galleries().find(pref_id); | 285 results_to_remove_, &scan_results_); |
285 if (it == preferences_->known_galleries().end() || | 286 dialog_->UpdateResults(); |
286 it->second.type == MediaGalleryPrefInfo::kScanResult || | |
287 it->second.type == MediaGalleryPrefInfo::kRemovedScan) { | |
288 UpdateScanResultsFromPreferences(preferences_, extension_, | |
289 results_to_remove_, &scan_results_); | |
290 dialog_->UpdateResults(); | |
291 } | |
292 } | 287 } |
293 } | 288 } |
294 | 289 |
295 void MediaGalleriesScanResultDialogController::OnRemovableDeviceUpdate( | 290 void MediaGalleriesScanResultDialogController::OnRemovableDeviceUpdate( |
296 const std::string device_id) { | 291 const std::string device_id) { |
297 for (ScanResults::const_iterator it = scan_results_.begin(); | 292 for (ScanResults::const_iterator it = scan_results_.begin(); |
298 it != scan_results_.end(); | 293 it != scan_results_.end(); |
299 ++it) { | 294 ++it) { |
300 if (it->second.pref_info.device_id == device_id) { | 295 if (it->second.pref_info.device_id == device_id) { |
301 dialog_->UpdateResults(); | 296 dialog_->UpdateResults(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 | 341 |
347 void MediaGalleriesScanResultDialogController::OnGalleryInfoUpdated( | 342 void MediaGalleriesScanResultDialogController::OnGalleryInfoUpdated( |
348 MediaGalleriesPreferences* /* prefs */, | 343 MediaGalleriesPreferences* /* prefs */, |
349 MediaGalleryPrefId pref_id) { | 344 MediaGalleryPrefId pref_id) { |
350 OnPreferenceUpdate(extension_->id(), pref_id); | 345 OnPreferenceUpdate(extension_->id(), pref_id); |
351 } | 346 } |
352 | 347 |
353 // MediaGalleriesScanResultDialog --------------------------------------------- | 348 // MediaGalleriesScanResultDialog --------------------------------------------- |
354 | 349 |
355 MediaGalleriesScanResultDialog::~MediaGalleriesScanResultDialog() {} | 350 MediaGalleriesScanResultDialog::~MediaGalleriesScanResultDialog() {} |
OLD | NEW |