| 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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 } | 394 } |
| 395 | 395 |
| 396 on_initialize_callbacks_.push_back(callback); | 396 on_initialize_callbacks_.push_back(callback); |
| 397 if (on_initialize_callbacks_.size() > 1) | 397 if (on_initialize_callbacks_.size() > 1) |
| 398 return; | 398 return; |
| 399 | 399 |
| 400 // This counter must match the number of async methods dispatched below. | 400 // This counter must match the number of async methods dispatched below. |
| 401 // It cannot be incremented inline with each callback, as some may return | 401 // It cannot be incremented inline with each callback, as some may return |
| 402 // synchronously, decrement the counter to 0, and prematurely trigger | 402 // synchronously, decrement the counter to 0, and prematurely trigger |
| 403 // FinishInitialization. | 403 // FinishInitialization. |
| 404 pre_initialization_callbacks_waiting_ = 3; | 404 pre_initialization_callbacks_waiting_ = 4; |
| 405 | 405 |
| 406 // Check whether we should be initializing -- are there any extensions that | 406 // Check whether we should be initializing -- are there any extensions that |
| 407 // are using media galleries? | 407 // are using media galleries? |
| 408 media_galleries::UsageCount(media_galleries::PREFS_INITIALIZED); | 408 media_galleries::UsageCount(media_galleries::PREFS_INITIALIZED); |
| 409 if (NumberExtensionsUsingMediaGalleries(profile_) == 0) { | 409 if (NumberExtensionsUsingMediaGalleries(profile_) == 0) { |
| 410 media_galleries::UsageCount(media_galleries::PREFS_INITIALIZED_ERROR); | 410 media_galleries::UsageCount(media_galleries::PREFS_INITIALIZED_ERROR); |
| 411 } | 411 } |
| 412 | 412 |
| 413 // We determine the freshness of the profile here, before any of the finders | 413 // We determine the freshness of the profile here, before any of the finders |
| 414 // return and add media galleries to it. | 414 // return and add media galleries to it. |
| 415 StorageMonitor::GetInstance()->EnsureInitialized( | 415 StorageMonitor::GetInstance()->EnsureInitialized( |
| 416 base::Bind(&MediaGalleriesPreferences::OnStorageMonitorInit, | 416 base::Bind(&MediaGalleriesPreferences::OnStorageMonitorInit, |
| 417 weak_factory_.GetWeakPtr(), | 417 weak_factory_.GetWeakPtr(), |
| 418 !APIHasBeenUsed(profile_) /* add_default_galleries */)); | 418 !APIHasBeenUsed(profile_) /* add_default_galleries */)); |
| 419 | 419 |
| 420 // Look for optional default galleries every time. | 420 // Look for optional default galleries every time. |
| 421 iapps::FindITunesLibrary( | 421 iapps::FindITunesLibrary( |
| 422 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, | 422 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, |
| 423 weak_factory_.GetWeakPtr())); | 423 weak_factory_.GetWeakPtr())); |
| 424 | 424 |
| 425 picasa::FindPicasaDatabase( | 425 picasa::FindPicasaDatabase( |
| 426 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, | 426 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, |
| 427 weak_factory_.GetWeakPtr())); | 427 weak_factory_.GetWeakPtr())); |
| 428 | 428 |
| 429 #if 0 | |
| 430 iapps::FindIPhotoLibrary( | 429 iapps::FindIPhotoLibrary( |
| 431 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, | 430 base::Bind(&MediaGalleriesPreferences::OnFinderDeviceID, |
| 432 weak_factory_.GetWeakPtr())); | 431 weak_factory_.GetWeakPtr())); |
| 433 #endif | |
| 434 } | 432 } |
| 435 | 433 |
| 436 bool MediaGalleriesPreferences::IsInitialized() const { return initialized_; } | 434 bool MediaGalleriesPreferences::IsInitialized() const { return initialized_; } |
| 437 | 435 |
| 438 Profile* MediaGalleriesPreferences::profile() { return profile_; } | 436 Profile* MediaGalleriesPreferences::profile() { return profile_; } |
| 439 | 437 |
| 440 void MediaGalleriesPreferences::OnInitializationCallbackReturned() { | 438 void MediaGalleriesPreferences::OnInitializationCallbackReturned() { |
| 441 DCHECK(!IsInitialized()); | 439 DCHECK(!IsInitialized()); |
| 442 DCHECK(pre_initialization_callbacks_waiting_ > 0); | 440 DCHECK(pre_initialization_callbacks_waiting_ > 0); |
| 443 if (--pre_initialization_callbacks_waiting_ == 0) | 441 if (--pre_initialization_callbacks_waiting_ == 0) |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 if (extension_prefs_for_testing_) | 1104 if (extension_prefs_for_testing_) |
| 1107 return extension_prefs_for_testing_; | 1105 return extension_prefs_for_testing_; |
| 1108 return extensions::ExtensionPrefs::Get(profile_); | 1106 return extensions::ExtensionPrefs::Get(profile_); |
| 1109 } | 1107 } |
| 1110 | 1108 |
| 1111 void MediaGalleriesPreferences::SetExtensionPrefsForTesting( | 1109 void MediaGalleriesPreferences::SetExtensionPrefsForTesting( |
| 1112 extensions::ExtensionPrefs* extension_prefs) { | 1110 extensions::ExtensionPrefs* extension_prefs) { |
| 1113 DCHECK(IsInitialized()); | 1111 DCHECK(IsInitialized()); |
| 1114 extension_prefs_for_testing_ = extension_prefs; | 1112 extension_prefs_for_testing_ = extension_prefs; |
| 1115 } | 1113 } |
| OLD | NEW |