Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 } | 368 } |
| 369 | 369 |
| 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_ = 2; | 378 pre_initialization_callbacks_waiting_ = 3; |
| 379 | 379 |
| 380 // Ensure StorageMonitor is initialized. | 380 // Ensure StorageMonitor is initialized. |
| 381 StorageMonitor::GetInstance()->EnsureInitialized( | 381 StorageMonitor::GetInstance()->EnsureInitialized( |
| 382 base::Bind(&MediaGalleriesPreferences::OnInitializationCallbackReturned, | 382 base::Bind(&MediaGalleriesPreferences::OnInitializationCallbackReturned, |
| 383 weak_factory_.GetWeakPtr())); | 383 weak_factory_.GetWeakPtr())); |
| 384 | 384 |
| 385 // Look for optional default galleries every time. | 385 // Look for optional default galleries every time. |
| 386 itunes::ITunesFinder::FindITunesLibrary( | 386 itunes::ITunesFinder::FindITunesLibrary( |
| 387 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, | 387 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, |
| 388 weak_factory_.GetWeakPtr())); | 388 weak_factory_.GetWeakPtr())); |
| 389 | 389 |
| 390 picasa::FindPicasaDatabase( | |
| 391 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, | |
| 392 weak_factory_.GetWeakPtr())); | |
| 393 | |
| 390 #if 0 | 394 #if 0 |
| 391 iphoto::FindIPhotoLibrary( | 395 iphoto::FindIPhotoLibrary( |
| 392 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, | 396 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, |
| 393 weak_factory_.GetWeakPtr())); | 397 weak_factory_.GetWeakPtr())); |
| 394 #endif | 398 #endif |
| 395 | |
| 396 // TODO(tommycli): Turn on when Picasa code is ready. | |
| 397 #if 0 | |
| 398 picasa::PicasaFinder::FindPicasaDatabaseOnUIThread( | |
| 399 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, | |
| 400 weak_factory_.GetWeakPtr())); | |
| 401 #endif | |
| 402 } | 399 } |
| 403 | 400 |
| 404 bool MediaGalleriesPreferences::IsInitialized() const { return initialized_; } | 401 bool MediaGalleriesPreferences::IsInitialized() const { return initialized_; } |
| 405 | 402 |
| 406 Profile* MediaGalleriesPreferences::profile() { return profile_; } | 403 Profile* MediaGalleriesPreferences::profile() { return profile_; } |
| 407 | 404 |
| 408 void MediaGalleriesPreferences::OnInitializationCallbackReturned() { | 405 void MediaGalleriesPreferences::OnInitializationCallbackReturned() { |
| 409 DCHECK(!IsInitialized()); | 406 DCHECK(!IsInitialized()); |
| 410 DCHECK(pre_initialization_callbacks_waiting_ > 0); | 407 DCHECK(pre_initialization_callbacks_waiting_ > 0); |
| 411 if (--pre_initialization_callbacks_waiting_ == 0) | 408 if (--pre_initialization_callbacks_waiting_ == 0) |
| 412 FinishInitialization(); | 409 FinishInitialization(); |
| 413 } | 410 } |
| 414 | 411 |
| 415 void MediaGalleriesPreferences::FinishInitialization() { | 412 void MediaGalleriesPreferences::FinishInitialization() { |
| 416 DCHECK(!IsInitialized()); | 413 DCHECK(!IsInitialized()); |
| 417 | 414 |
| 418 initialized_ = true; | 415 initialized_ = true; |
| 419 | 416 |
| 420 StorageMonitor* monitor = StorageMonitor::GetInstance(); | 417 StorageMonitor* monitor = StorageMonitor::GetInstance(); |
| 421 DCHECK(monitor->IsInitialized()); | 418 DCHECK(monitor->IsInitialized()); |
| 422 | 419 |
| 423 AddDefaultGalleriesIfFreshProfile(); | 420 AddDefaultGalleriesIfFreshProfile(); |
|
vandebo (ex-Chrome)
2013/10/01 16:41:10
This won't work in this location. You may have ad
tommycli
2013/10/01 17:11:42
You're right. Fix in this CL:
https://codereview.c
vandebo (ex-Chrome)
2013/10/01 17:35:32
Don't include in this CL.
| |
| 424 InitFromPrefs(); | 421 InitFromPrefs(); |
| 425 | 422 |
| 426 StorageMonitor::GetInstance()->AddObserver(this); | 423 StorageMonitor::GetInstance()->AddObserver(this); |
| 427 | 424 |
| 428 std::vector<StorageInfo> existing_devices = | 425 std::vector<StorageInfo> existing_devices = |
| 429 monitor->GetAllAvailableStorages(); | 426 monitor->GetAllAvailableStorages(); |
| 430 for (size_t i = 0; i < existing_devices.size(); i++) { | 427 for (size_t i = 0; i < existing_devices.size(); i++) { |
| 431 if (!(StorageInfo::IsMediaDevice(existing_devices[i].device_id()) && | 428 if (!(StorageInfo::IsMediaDevice(existing_devices[i].device_id()) && |
| 432 StorageInfo::IsRemovableDevice(existing_devices[i].device_id()))) | 429 StorageInfo::IsRemovableDevice(existing_devices[i].device_id()))) |
| 433 continue; | 430 continue; |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 } |
| OLD | NEW |