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_gallery/media_galleries_preferences.h" | 5 #include "chrome/browser/media_gallery/media_galleries_preferences.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 if (!dict->GetString(kMediaGalleriesPrefIdKey, &string_id) || | 40 if (!dict->GetString(kMediaGalleriesPrefIdKey, &string_id) || |
| 41 !base::StringToUint64(string_id, value)) { | 41 !base::StringToUint64(string_id, value)) { |
| 42 return false; | 42 return false; |
| 43 } | 43 } |
| 44 | 44 |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool GetType(const DictionaryValue* dict, MediaGalleryPrefInfo::Type* type) { | 48 bool GetType(const DictionaryValue* dict, MediaGalleryPrefInfo::Type* type) { |
| 49 std::string string_type; | 49 std::string string_type; |
| 50 if (!dict->GetString(kMediaGalleriesPrefIdKey, &string_type)) | 50 if (!dict->GetString(kMediaGalleriesTypeKey, &string_type)) |
|
Evan Stade
2012/08/02 23:18:13
ignore changes in this file.
| |
| 51 return false; | 51 return false; |
| 52 | 52 |
| 53 if (string_type.compare(kMediaGalleriesTypeAutoDetectedValue) == 0) { | 53 if (string_type.compare(kMediaGalleriesTypeAutoDetectedValue) == 0) { |
| 54 *type = MediaGalleryPrefInfo::kAutoDetected; | 54 *type = MediaGalleryPrefInfo::kAutoDetected; |
| 55 return true; | 55 return true; |
| 56 } else if (string_type.compare(kMediaGalleriesTypeUserAddedValue) == 0) { | 56 } else if (string_type.compare(kMediaGalleriesTypeUserAddedValue) == 0) { |
| 57 *type = MediaGalleryPrefInfo::kUserAdded; | 57 *type = MediaGalleryPrefInfo::kUserAdded; |
| 58 return true; | 58 return true; |
| 59 } else if (string_type.compare(kMediaGalleriesTypeBlackListedValue) == 0) { | 59 } else if (string_type.compare(kMediaGalleriesTypeBlackListedValue) == 0) { |
| 60 *type = MediaGalleryPrefInfo::kBlackListed; | 60 *type = MediaGalleryPrefInfo::kBlackListed; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 MediaGalleriesPreferences::MediaGalleriesPreferences(Profile* profile) | 139 MediaGalleriesPreferences::MediaGalleriesPreferences(Profile* profile) |
| 140 : profile_(profile) { | 140 : profile_(profile) { |
| 141 DCHECK(UserInteractionIsEnabled()); | 141 DCHECK(UserInteractionIsEnabled()); |
| 142 | 142 |
| 143 // Populate the default galleries if this is a fresh profile. | 143 // Populate the default galleries if this is a fresh profile. |
| 144 MediaGalleryPrefId current_id = | 144 MediaGalleryPrefId current_id = |
| 145 profile_->GetPrefs()->GetUint64(prefs::kMediaGalleriesUniqueId); | 145 profile_->GetPrefs()->GetUint64(prefs::kMediaGalleriesUniqueId); |
| 146 if (current_id == MediaGalleryPrefInfo::kInvalidPrefId + 1) { | 146 if (current_id == MediaGalleryPrefInfo::kInvalidPrefId + 1) { |
| 147 FilePath pictures_path; | 147 FilePath pictures_path; |
| 148 if (PathService::Get(chrome::DIR_USER_PICTURES, &pictures_path)) { | 148 if (PathService::Get(chrome::DIR_USER_PICTURES, &pictures_path)) { |
| 149 | |
| 149 std::string device_id = MediaFileSystemRegistry::GetInstance()-> | 150 std::string device_id = MediaFileSystemRegistry::GetInstance()-> |
| 150 GetDeviceIdFromPath(pictures_path); | 151 GetDeviceIdFromPath(pictures_path); |
| 151 string16 display_name = ComputeDisplayName(pictures_path); | 152 string16 display_name = ComputeDisplayName(pictures_path); |
| 152 AddGallery(device_id, display_name, pictures_path, false /*user added*/); | 153 AddGallery(device_id, display_name, pictures_path, false /*user added*/); |
| 153 } | 154 } |
| 154 } | 155 } |
| 155 InitFromPrefs(); | 156 InitFromPrefs(); |
| 156 } | 157 } |
| 157 | 158 |
| 158 MediaGalleriesPreferences::~MediaGalleriesPreferences() {} | 159 MediaGalleriesPreferences::~MediaGalleriesPreferences() {} |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 } | 230 } |
| 230 return existing_id; | 231 return existing_id; |
| 231 } | 232 } |
| 232 | 233 |
| 233 PrefService* prefs = profile_->GetPrefs(); | 234 PrefService* prefs = profile_->GetPrefs(); |
| 234 | 235 |
| 235 MediaGalleryPrefInfo gallery_info; | 236 MediaGalleryPrefInfo gallery_info; |
| 236 gallery_info.pref_id = prefs->GetUint64(prefs::kMediaGalleriesUniqueId); | 237 gallery_info.pref_id = prefs->GetUint64(prefs::kMediaGalleriesUniqueId); |
| 237 prefs->SetUint64(prefs::kMediaGalleriesUniqueId, gallery_info.pref_id + 1); | 238 prefs->SetUint64(prefs::kMediaGalleriesUniqueId, gallery_info.pref_id + 1); |
| 238 gallery_info.display_name = display_name; | 239 gallery_info.display_name = display_name; |
| 240 gallery_info.device_id = device_id; | |
| 239 gallery_info.path = path; | 241 gallery_info.path = path; |
| 240 gallery_info.type = MediaGalleryPrefInfo::kAutoDetected; | 242 gallery_info.type = MediaGalleryPrefInfo::kAutoDetected; |
| 241 if (user_added) | 243 if (user_added) |
| 242 gallery_info.type = MediaGalleryPrefInfo::kUserAdded; | 244 gallery_info.type = MediaGalleryPrefInfo::kUserAdded; |
| 243 | 245 |
| 244 ListPrefUpdate update(prefs, prefs::kMediaGalleriesRememberedGalleries); | 246 ListPrefUpdate update(prefs, prefs::kMediaGalleriesRememberedGalleries); |
| 245 ListValue* list = update.Get(); | 247 ListValue* list = update.Get(); |
| 246 list->Append(CreateGalleryPrefInfoDictionary(gallery_info)); | 248 list->Append(CreateGalleryPrefInfoDictionary(gallery_info)); |
| 247 | 249 |
| 248 known_galleries_[gallery_info.pref_id] = gallery_info; | 250 known_galleries_[gallery_info.pref_id] = gallery_info; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 363 } | 365 } |
| 364 | 366 |
| 365 extensions::ExtensionPrefs* | 367 extensions::ExtensionPrefs* |
| 366 MediaGalleriesPreferences::GetExtensionPrefs() const { | 368 MediaGalleriesPreferences::GetExtensionPrefs() const { |
| 367 ExtensionService* extension_service = | 369 ExtensionService* extension_service = |
| 368 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 370 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 369 return extension_service->extension_prefs(); | 371 return extension_service->extension_prefs(); |
| 370 } | 372 } |
| 371 | 373 |
| 372 } // namespace chrome | 374 } // namespace chrome |
| OLD | NEW |