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

Side by Side Diff: trunk/src/chrome/browser/media_galleries/media_galleries_preferences.cc

Issue 25725004: Revert 226509 "Media Galleries API: Fix MediaGalleriesPreference..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 2 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
« no previous file with comments | « trunk/src/chrome/browser/media_galleries/media_galleries_preferences.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/media_galleries/media_galleries_preferences.h" 5 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
6 6
7 #include "base/base_paths_posix.h" 7 #include "base/base_paths_posix.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/i18n/time_formatting.h" 9 #include "base/i18n/time_formatting.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 on_initialize_callbacks_.push_back(callback); 370 on_initialize_callbacks_.push_back(callback);
371 if (on_initialize_callbacks_.size() > 1) 371 if (on_initialize_callbacks_.size() > 1)
372 return; 372 return;
373 373
374 // This counter must match the number of async methods dispatched below. 374 // This counter must match the number of async methods dispatched below.
375 // It cannot be incremented inline with each callback, as some may return 375 // It cannot be incremented inline with each callback, as some may return
376 // synchronously, decrement the counter to 0, and prematurely trigger 376 // synchronously, decrement the counter to 0, and prematurely trigger
377 // FinishInitialization. 377 // FinishInitialization.
378 pre_initialization_callbacks_waiting_ = 3; 378 pre_initialization_callbacks_waiting_ = 3;
379 379
380 // We determine the freshness of the profile here, before any of the finders 380 // Ensure StorageMonitor is initialized.
381 // return and add media galleries to it.
382 StorageMonitor::GetInstance()->EnsureInitialized( 381 StorageMonitor::GetInstance()->EnsureInitialized(
383 base::Bind(&MediaGalleriesPreferences::OnStorageMonitorInit, 382 base::Bind(&MediaGalleriesPreferences::OnInitializationCallbackReturned,
384 weak_factory_.GetWeakPtr(), 383 weak_factory_.GetWeakPtr()));
385 APIHasBeenUsed(profile_) /* add_default_galleries */));
386 384
387 // Look for optional default galleries every time. 385 // Look for optional default galleries every time.
388 itunes::ITunesFinder::FindITunesLibrary( 386 itunes::ITunesFinder::FindITunesLibrary(
389 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, 387 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID,
390 weak_factory_.GetWeakPtr())); 388 weak_factory_.GetWeakPtr()));
391 389
392 picasa::FindPicasaDatabase( 390 picasa::FindPicasaDatabase(
393 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, 391 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID,
394 weak_factory_.GetWeakPtr())); 392 weak_factory_.GetWeakPtr()));
395 393
(...skipping 16 matching lines...) Expand all
412 } 410 }
413 411
414 void MediaGalleriesPreferences::FinishInitialization() { 412 void MediaGalleriesPreferences::FinishInitialization() {
415 DCHECK(!IsInitialized()); 413 DCHECK(!IsInitialized());
416 414
417 initialized_ = true; 415 initialized_ = true;
418 416
419 StorageMonitor* monitor = StorageMonitor::GetInstance(); 417 StorageMonitor* monitor = StorageMonitor::GetInstance();
420 DCHECK(monitor->IsInitialized()); 418 DCHECK(monitor->IsInitialized());
421 419
420 AddDefaultGalleriesIfFreshProfile();
422 InitFromPrefs(); 421 InitFromPrefs();
423 422
424 StorageMonitor::GetInstance()->AddObserver(this); 423 StorageMonitor::GetInstance()->AddObserver(this);
425 424
426 std::vector<StorageInfo> existing_devices = 425 std::vector<StorageInfo> existing_devices =
427 monitor->GetAllAvailableStorages(); 426 monitor->GetAllAvailableStorages();
428 for (size_t i = 0; i < existing_devices.size(); i++) { 427 for (size_t i = 0; i < existing_devices.size(); i++) {
429 if (!(StorageInfo::IsMediaDevice(existing_devices[i].device_id()) && 428 if (!(StorageInfo::IsMediaDevice(existing_devices[i].device_id()) &&
430 StorageInfo::IsRemovableDevice(existing_devices[i].device_id()))) 429 StorageInfo::IsRemovableDevice(existing_devices[i].device_id())))
431 continue; 430 continue;
432 AddGallery(existing_devices[i].device_id(), 431 AddGallery(existing_devices[i].device_id(),
433 base::FilePath(), 432 base::FilePath(),
434 false, 433 false,
435 existing_devices[i].storage_label(), 434 existing_devices[i].storage_label(),
436 existing_devices[i].vendor_name(), 435 existing_devices[i].vendor_name(),
437 existing_devices[i].model_name(), 436 existing_devices[i].model_name(),
438 existing_devices[i].total_size_in_bytes(), 437 existing_devices[i].total_size_in_bytes(),
439 base::Time::Now()); 438 base::Time::Now());
440 } 439 }
441 440
442 for (std::vector<base::Closure>::iterator iter = 441 for (std::vector<base::Closure>::iterator iter =
443 on_initialize_callbacks_.begin(); 442 on_initialize_callbacks_.begin();
444 iter != on_initialize_callbacks_.end(); 443 iter != on_initialize_callbacks_.end();
445 ++iter) { 444 ++iter) {
446 iter->Run(); 445 iter->Run();
447 } 446 }
448 on_initialize_callbacks_.clear(); 447 on_initialize_callbacks_.clear();
449 } 448 }
450 449
451 void MediaGalleriesPreferences::AddDefaultGalleries() { 450 void MediaGalleriesPreferences::AddDefaultGalleriesIfFreshProfile() {
451 // Only add defaults the first time.
452 if (APIHasBeenUsed(profile_))
453 return;
454
455 // Fresh profile case.
452 const int kDirectoryKeys[] = { 456 const int kDirectoryKeys[] = {
453 chrome::DIR_USER_MUSIC, 457 chrome::DIR_USER_MUSIC,
454 chrome::DIR_USER_PICTURES, 458 chrome::DIR_USER_PICTURES,
455 chrome::DIR_USER_VIDEOS, 459 chrome::DIR_USER_VIDEOS,
456 }; 460 };
457 461
458 for (size_t i = 0; i < arraysize(kDirectoryKeys); ++i) { 462 for (size_t i = 0; i < arraysize(kDirectoryKeys); ++i) {
459 base::FilePath path; 463 base::FilePath path;
460 if (!PathService::Get(kDirectoryKeys[i], &path)) 464 if (!PathService::Get(kDirectoryKeys[i], &path))
461 continue; 465 continue;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 FOR_EACH_OBSERVER(GalleryChangeObserver, 508 FOR_EACH_OBSERVER(GalleryChangeObserver,
505 gallery_change_observers_, 509 gallery_change_observers_,
506 OnGalleryInfoUpdated(this, pref_id)); 510 OnGalleryInfoUpdated(this, pref_id));
507 } 511 }
508 return true; 512 return true;
509 } 513 }
510 } 514 }
511 return false; 515 return false;
512 } 516 }
513 517
514 void MediaGalleriesPreferences::OnStorageMonitorInit(
515 bool need_to_add_default_galleries) {
516 if (need_to_add_default_galleries)
517 AddDefaultGalleries();
518 OnInitializationCallbackReturned();
519 }
520
521 void MediaGalleriesPreferences::OnFinderDeviceID(const std::string& device_id) { 518 void MediaGalleriesPreferences::OnFinderDeviceID(const std::string& device_id) {
522 if (!device_id.empty() && !UpdateDeviceIDForSingletonType(device_id)) { 519 if (!device_id.empty() && !UpdateDeviceIDForSingletonType(device_id)) {
523 std::string gallery_name; 520 std::string gallery_name;
524 if (StorageInfo::IsIPhotoDevice(device_id)) 521 if (StorageInfo::IsIPhotoDevice(device_id))
525 gallery_name = kIPhotoGalleryName; 522 gallery_name = kIPhotoGalleryName;
526 else if (StorageInfo::IsITunesDevice(device_id)) 523 else if (StorageInfo::IsITunesDevice(device_id))
527 gallery_name = kITunesGalleryName; 524 gallery_name = kITunesGalleryName;
528 else if (StorageInfo::IsPicasaDevice(device_id)) 525 else if (StorageInfo::IsPicasaDevice(device_id))
529 gallery_name = kPicasaGalleryName; 526 gallery_name = kPicasaGalleryName;
530 else 527 else
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 if (extension_prefs_for_testing_) 1068 if (extension_prefs_for_testing_)
1072 return extension_prefs_for_testing_; 1069 return extension_prefs_for_testing_;
1073 return extensions::ExtensionPrefs::Get(profile_); 1070 return extensions::ExtensionPrefs::Get(profile_);
1074 } 1071 }
1075 1072
1076 void MediaGalleriesPreferences::SetExtensionPrefsForTesting( 1073 void MediaGalleriesPreferences::SetExtensionPrefsForTesting(
1077 extensions::ExtensionPrefs* extension_prefs) { 1074 extensions::ExtensionPrefs* extension_prefs) {
1078 DCHECK(IsInitialized()); 1075 DCHECK(IsInitialized());
1079 extension_prefs_for_testing_ = extension_prefs; 1076 extension_prefs_for_testing_ = extension_prefs;
1080 } 1077 }
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/media_galleries/media_galleries_preferences.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698