#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/api/media_galleries_private/media_galleries_private_api.h"
#include "chrome/browser/extensions/extension_service.h"
-#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/media_galleries/fileapi/iapps_finder.h"
#include "chrome/browser/media_galleries/fileapi/picasa_finder.h"
#include "chrome/browser/media_galleries/media_file_system_registry.h"
#include "chrome/browser/media_galleries/media_galleries_histograms.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/storage_monitor/media_storage_util.h"
-#include "chrome/browser/storage_monitor/storage_monitor.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/permissions/media_galleries_permission.h"
#include "chrome/common/pref_names.h"
+#include "components/storage_monitor/media_storage_util.h"
+#include "components/storage_monitor/storage_monitor.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "content/public/browser/browser_thread.h"
+#include "extensions/browser/extension_system.h"
#include "extensions/browser/pref_names.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
const char kMediaGalleriesModelNameKey[] = "modelName";
const char kMediaGalleriesSizeKey[] = "totalSize";
const char kMediaGalleriesLastAttachTimeKey[] = "lastAttachTime";
+const char kMediaGalleriesScanAudioCountKey[] = "audioCount";
const char kMediaGalleriesScanImageCountKey[] = "imageCount";
-const char kMediaGalleriesScanMusicCountKey[] = "musicCount";
const char kMediaGalleriesScanVideoCountKey[] = "videoCount";
const char kMediaGalleriesPrefsVersionKey[] = "preferencesVersion";
double total_size_in_bytes = 0.0;
double last_attach_time = 0.0;
bool volume_metadata_valid = false;
+ int audio_count = 0;
int image_count = 0;
- int music_count = 0;
int video_count = 0;
int prefs_version = 0;
volume_metadata_valid = true;
}
- if (type == MediaGalleryPrefInfo::kScanResult &&
+ if (dict.GetInteger(kMediaGalleriesScanAudioCountKey, &audio_count) &&
dict.GetInteger(kMediaGalleriesScanImageCountKey, &image_count) &&
- dict.GetInteger(kMediaGalleriesScanMusicCountKey, &music_count) &&
dict.GetInteger(kMediaGalleriesScanVideoCountKey, &video_count)) {
+ out_gallery_info->audio_count = audio_count;
out_gallery_info->image_count = image_count;
- out_gallery_info->music_count = music_count;
out_gallery_info->video_count = video_count;
+ } else {
+ out_gallery_info->audio_count = 0;
+ out_gallery_info->image_count = 0;
+ out_gallery_info->video_count = 0;
}
out_gallery_info->pref_id = pref_id;
dict->SetString(kMediaGalleriesDisplayNameKey, gallery.display_name);
}
- if (gallery.type == MediaGalleryPrefInfo::kScanResult) {
+ if (gallery.audio_count || gallery.image_count || gallery.video_count) {
+ dict->SetInteger(kMediaGalleriesScanAudioCountKey, gallery.audio_count);
dict->SetInteger(kMediaGalleriesScanImageCountKey, gallery.image_count);
- dict->SetInteger(kMediaGalleriesScanMusicCountKey, gallery.music_count);
dict->SetInteger(kMediaGalleriesScanVideoCountKey, gallery.video_count);
}
type(kInvalidType),
total_size_in_bytes(0),
volume_metadata_valid(false),
+ audio_count(0),
image_count(0),
- music_count(0),
video_count(0),
prefs_version(0) {
}
#if defined(OS_CHROMEOS)
// See chrome/browser/chromeos/fileapi/file_system_backend.cc
- base::FilePath home_path;
- if (PathService::Get(base::DIR_HOME, &home_path)) {
- home_path = home_path.AppendASCII("Downloads");
+ base::FilePath download_path;
+ if (PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS_SAFE, &download_path)) {
base::FilePath relative;
- if (home_path.AppendRelativePath(path, &relative))
+ if (download_path.AppendRelativePath(path, &relative))
return relative.LossyDisplayName();
}
return path.BaseName().LossyDisplayName();
void MediaGalleriesPreferences::OnInitializationCallbackReturned() {
DCHECK(!IsInitialized());
- DCHECK(pre_initialization_callbacks_waiting_ > 0);
+ DCHECK_GT(pre_initialization_callbacks_waiting_, 0);
if (--pre_initialization_callbacks_waiting_ == 0)
FinishInitialization();
}
const base::string16& model_name,
uint64 total_size_in_bytes,
base::Time last_attach_time,
+ int audio_count,
int image_count,
- int music_count,
int video_count) {
DCHECK(IsInitialized());
return AddGalleryInternal(device_id, base::string16(), relative_path,
type, volume_label, vendor_name, model_name,
total_size_in_bytes, last_attach_time, true,
- image_count, music_count, video_count,
+ audio_count, image_count, video_count,
kCurrentPrefsVersion);
}
const base::string16& volume_label, const base::string16& vendor_name,
const base::string16& model_name, uint64 total_size_in_bytes,
base::Time last_attach_time, bool volume_metadata_valid,
- int image_count, int music_count, int video_count, int prefs_version) {
+ int audio_count, int image_count, int video_count, int prefs_version) {
DCHECK(type == MediaGalleryPrefInfo::kUserAdded ||
type == MediaGalleryPrefInfo::kAutoDetected ||
type == MediaGalleryPrefInfo::kScanResult);
(existing.last_attach_time != last_attach_time));
bool update_scan_counts =
- (new_type == MediaGalleryPrefInfo::kScanResult) &&
- (image_count > 0 || music_count > 0 || video_count > 0);
+ new_type != MediaGalleryPrefInfo::kRemovedScan &&
+ new_type != MediaGalleryPrefInfo::kBlackListed &&
+ (audio_count > 0 || image_count > 0 || video_count > 0 ||
+ existing.audio_count || existing.image_count || existing.video_count);
if (!update_gallery_name && !update_gallery_type &&
!update_gallery_metadata && !update_scan_counts)
last_attach_time.ToInternalValue());
}
if (update_scan_counts) {
+ dict->SetInteger(kMediaGalleriesScanAudioCountKey, audio_count);
dict->SetInteger(kMediaGalleriesScanImageCountKey, image_count);
- dict->SetInteger(kMediaGalleriesScanMusicCountKey, music_count);
dict->SetInteger(kMediaGalleriesScanVideoCountKey, video_count);
}
dict->SetInteger(kMediaGalleriesPrefsVersionKey, prefs_version);
gallery_info.total_size_in_bytes = total_size_in_bytes;
gallery_info.last_attach_time = last_attach_time;
gallery_info.volume_metadata_valid = volume_metadata_valid;
+ gallery_info.audio_count = audio_count;
gallery_info.image_count = image_count;
- gallery_info.music_count = music_count;
gallery_info.video_count = video_count;
gallery_info.prefs_version = prefs_version;
kCurrentPrefsVersion);
}
-void MediaGalleriesPreferences::ForgetGalleryById(MediaGalleryPrefId pref_id) {
+void MediaGalleriesPreferences::ForgetGalleryById(MediaGalleryPrefId id) {
+ EraseOrBlacklistGalleryById(id, false);
+}
+
+void MediaGalleriesPreferences::EraseGalleryById(MediaGalleryPrefId id) {
+ EraseOrBlacklistGalleryById(id, true);
+}
+
+void MediaGalleriesPreferences::EraseOrBlacklistGalleryById(
+ MediaGalleryPrefId id, bool erase) {
DCHECK(IsInitialized());
PrefService* prefs = profile_->GetPrefs();
scoped_ptr<ListPrefUpdate> update(new ListPrefUpdate(
prefs, prefs::kMediaGalleriesRememberedGalleries));
base::ListValue* list = update->Get();
- if (!ContainsKey(known_galleries_, pref_id))
+ if (!ContainsKey(known_galleries_, id))
return;
for (base::ListValue::iterator iter = list->begin();
base::DictionaryValue* dict;
MediaGalleryPrefId iter_id;
if ((*iter)->GetAsDictionary(&dict) && GetPrefId(*dict, &iter_id) &&
- pref_id == iter_id) {
- RemoveGalleryPermissionsFromPrefs(pref_id);
+ id == iter_id) {
+ RemoveGalleryPermissionsFromPrefs(id);
MediaGalleryPrefInfo::Type type;
- if (GetType(*dict, &type) &&
+ if (!erase && GetType(*dict, &type) &&
(type == MediaGalleryPrefInfo::kAutoDetected ||
type == MediaGalleryPrefInfo::kScanResult)) {
if (type == MediaGalleryPrefInfo::kAutoDetected) {
} else {
dict->SetString(kMediaGalleriesTypeKey,
kMediaGalleriesTypeRemovedScanValue);
+ dict->SetInteger(kMediaGalleriesScanAudioCountKey, 0);
dict->SetInteger(kMediaGalleriesScanImageCountKey, 0);
- dict->SetInteger(kMediaGalleriesScanMusicCountKey, 0);
dict->SetInteger(kMediaGalleriesScanVideoCountKey, 0);
}
} else {
InitFromPrefs();
FOR_EACH_OBSERVER(GalleryChangeObserver,
gallery_change_observers_,
- OnGalleryRemoved(this, pref_id));
+ OnGalleryRemoved(this, id));
return;
}
}
}
+bool MediaGalleriesPreferences::NonAutoGalleryHasPermission(
+ MediaGalleryPrefId id) const {
+ DCHECK(IsInitialized());
+ DCHECK(!ContainsKey(known_galleries_, id) ||
+ known_galleries_.find(id)->second.type !=
+ MediaGalleryPrefInfo::kAutoDetected);
+ ExtensionPrefs* prefs = GetExtensionPrefs();
+ const base::DictionaryValue* extensions =
+ prefs->pref_service()->GetDictionary(extensions::pref_names::kExtensions);
+ if (!extensions)
+ return true;
+
+ for (base::DictionaryValue::Iterator iter(*extensions); !iter.IsAtEnd();
+ iter.Advance()) {
+ if (!extensions::Extension::IdIsValid(iter.key())) {
+ NOTREACHED();
+ continue;
+ }
+ std::vector<MediaGalleryPermission> permissions =
+ GetGalleryPermissionsFromPrefs(iter.key());
+ for (std::vector<MediaGalleryPermission>::const_iterator it =
+ permissions.begin(); it != permissions.end(); ++it) {
+ if (it->pref_id == id) {
+ if (it->has_permission)
+ return true;
+ break;
+ }
+ }
+ }
+ return false;
+}
+
MediaGalleryPrefIdSet MediaGalleriesPreferences::GalleriesForExtension(
const extensions::Extension& extension) const {
DCHECK(IsInitialized());
return known_galleries_;
}
+base::Time MediaGalleriesPreferences::GetLastScanCompletionTime() const {
+ int64 last_scan_time_internal =
+ profile_->GetPrefs()->GetInt64(prefs::kMediaGalleriesLastScanTime);
+ return base::Time::FromInternalValue(last_scan_time_internal);
+}
+
+void MediaGalleriesPreferences::SetLastScanCompletionTime(
+ const base::Time& time) {
+ profile_->GetPrefs()->SetInt64(prefs::kMediaGalleriesLastScanTime,
+ time.ToInternalValue());
+}
+
void MediaGalleriesPreferences::Shutdown() {
weak_factory_.InvalidateWeakPtrs();
profile_ = NULL;
prefs::kMediaGalleriesUniqueId,
kInvalidMediaGalleryPrefId + 1,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
+ registry->RegisterInt64Pref(
+ prefs::kMediaGalleriesLastScanTime,
+ base::Time().ToInternalValue(),
+ user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}
bool MediaGalleriesPreferences::SetGalleryPermissionInPrefs(