| 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/profiles/profile_info_cache.h" | 5 #include "chrome/browser/profiles/profile_info_cache.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/i18n/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 33 #include "ui/gfx/image/image.h" | 33 #include "ui/gfx/image/image.h" |
| 34 #include "ui/gfx/image/image_util.h" | 34 #include "ui/gfx/image/image_util.h" |
| 35 | 35 |
| 36 using content::BrowserThread; | 36 using content::BrowserThread; |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 const char kNameKey[] = "name"; | 40 const char kNameKey[] = "name"; |
| 41 const char kShortcutNameKey[] = "shortcut_name"; | 41 //const char kShortcutNameKey[] = "shortcut_name"; |
| 42 const char kGAIANameKey[] = "gaia_name"; | 42 //const char kGAIANameKey[] = "gaia_name"; |
| 43 const char kGAIAGivenNameKey[] = "gaia_given_name"; | 43 //const char kGAIAGivenNameKey[] = "gaia_given_name"; |
| 44 const char kUseGAIANameKey[] = "use_gaia_name"; | 44 //const char kUseGAIANameKey[] = "use_gaia_name"; |
| 45 const char kUserNameKey[] = "user_name"; | 45 const char kUserNameKey[] = "user_name"; |
| 46 const char kAvatarIconKey[] = "avatar_icon"; | 46 const char kAvatarIconKey[] = "avatar_icon"; |
| 47 const char kUseGAIAPictureKey[] = "use_gaia_picture"; | 47 const char kUseGAIAPictureKey[] = "use_gaia_picture"; |
| 48 const char kBackgroundAppsKey[] = "background_apps"; | 48 const char kBackgroundAppsKey[] = "background_apps"; |
| 49 const char kHasMigratedToGAIAInfoKey[] = "has_migrated_to_gaia_info"; | 49 const char kHasMigratedToGAIAInfoKey[] = "has_migrated_to_gaia_info"; |
| 50 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; | 50 const char kGAIAPictureFileNameKey[] = "gaia_picture_file_name"; |
| 51 const char kIsManagedKey[] = "is_managed"; | 51 const char kIsManagedKey[] = "is_managed"; |
| 52 const char kSigninRequiredKey[] = "signin_required"; | 52 const char kSigninRequiredKey[] = "signin_required"; |
| 53 const char kManagedUserId[] = "managed_user_id"; | 53 const char kManagedUserId[] = "managed_user_id"; |
| 54 const char kProfileIsEphemeral[] = "is_ephemeral"; | 54 const char kProfileIsEphemeral[] = "is_ephemeral"; |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 173 |
| 174 } // namespace | 174 } // namespace |
| 175 | 175 |
| 176 ProfileInfoCache::ProfileInfoCache(PrefService* prefs, | 176 ProfileInfoCache::ProfileInfoCache(PrefService* prefs, |
| 177 const base::FilePath& user_data_dir) | 177 const base::FilePath& user_data_dir) |
| 178 : prefs_(prefs), | 178 : prefs_(prefs), |
| 179 user_data_dir_(user_data_dir) { | 179 user_data_dir_(user_data_dir) { |
| 180 // Populate the cache | 180 // Populate the cache |
| 181 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 181 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
| 182 DictionaryValue* cache = update.Get(); | 182 DictionaryValue* cache = update.Get(); |
| 183 |
| 183 for (DictionaryValue::Iterator it(*cache); !it.IsAtEnd(); it.Advance()) { | 184 for (DictionaryValue::Iterator it(*cache); !it.IsAtEnd(); it.Advance()) { |
| 184 DictionaryValue* info = NULL; | 185 DictionaryValue* info = NULL; |
| 185 cache->GetDictionaryWithoutPathExpansion(it.key(), &info); | 186 cache->GetDictionaryWithoutPathExpansion(it.key(), &info); |
| 186 string16 name; | 187 string16 name; |
| 187 info->GetString(kNameKey, &name); | 188 info->GetString(kNameKey, &name); |
| 188 sorted_keys_.insert(FindPositionForProfile(it.key(), name), it.key()); | |
| 189 // TODO(ibraaaa): delete this when 97% of our users are using M31. | 189 // TODO(ibraaaa): delete this when 97% of our users are using M31. |
| 190 // http://crbug.com/276163 | 190 // http://crbug.com/276163 |
| 191 bool is_managed = false; | 191 bool is_managed = false; |
| 192 if (info->GetBoolean(kIsManagedKey, &is_managed)) { | 192 if (info->GetBoolean(kIsManagedKey, &is_managed)) { |
| 193 info->Remove(kIsManagedKey, NULL); | 193 info->Remove(kIsManagedKey, NULL); |
| 194 info->SetString(kManagedUserId, is_managed ? "DUMMY_ID" : std::string()); | 194 info->SetString(kManagedUserId, is_managed ? "DUMMY_ID" : std::string()); |
| 195 } | 195 } |
| 196 if (info) { |
| 197 base::FilePath path = user_data_dir.AppendASCII(it.key()); |
| 198 cached_entries_[it.key()] = ProfileInfoEntry(path, *info); |
| 199 } |
| 200 |
| 201 //sorted_keys_.insert(FindPositionForProfile(it.key(), name), it.key()); |
| 196 } | 202 } |
| 197 } | 203 } |
| 198 | 204 |
| 199 ProfileInfoCache::~ProfileInfoCache() { | 205 ProfileInfoCache::~ProfileInfoCache() { |
| 200 STLDeleteContainerPairSecondPointers( | 206 STLDeleteContainerPairSecondPointers( |
| 201 gaia_pictures_.begin(), gaia_pictures_.end()); | 207 gaia_pictures_.begin(), gaia_pictures_.end()); |
| 202 } | 208 } |
| 203 | 209 |
| 204 void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path, | 210 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) { |
| 205 const string16& name, | 211 observer_list_.AddObserver(obs); |
| 206 const string16& username, | 212 } |
| 207 size_t icon_index, | 213 |
| 208 const std::string& managed_user_id) { | 214 void ProfileInfoCache::RemoveObserver(ProfileInfoCacheObserver* obs) { |
| 209 std::string key = CacheKeyFromProfilePath(profile_path); | 215 observer_list_.RemoveObserver(obs); |
| 216 } |
| 217 |
| 218 size_t ProfileInfoCache::GetNumberOfProfiles() const { |
| 219 return cached_entries_.size(); |
| 220 } |
| 221 |
| 222 std::vector<ProfileInfoEntry> ProfileInfoCache::GetProfilesSortedByName() |
| 223 const { |
| 224 std::vector<ProfileInfoEntry> entries; |
| 225 for (std::map<std::string, ProfileInfoEntry>::const_iterator it = |
| 226 cached_entries_.begin(); it != cached_entries_.end(); ++it) { |
| 227 entries.push_back(it->second); |
| 228 } |
| 229 std::sort(entries.begin(), entries.end()); |
| 230 return entries; |
| 231 } |
| 232 |
| 233 bool ProfileInfoCache::GetInfoForProfile(const base::FilePath& path, |
| 234 ProfileInfoEntry* entry) const { |
| 235 // If the info is not in the cache then the profile was deleted. |
| 236 std::string key = CacheKeyFromProfilePath(path); |
| 237 std::map<std::string, ProfileInfoEntry>::const_iterator it = |
| 238 cached_entries_.find(key); |
| 239 if (it == cached_entries_.end()) |
| 240 return false; |
| 241 |
| 242 *entry = it->second; |
| 243 return true; |
| 244 } |
| 245 |
| 246 void ProfileInfoCache::SetInfoForProfile(const ProfileInfoEntry& info) { |
| 247 std::string key = CacheKeyFromProfilePath(info.path()); |
| 248 cached_entries_[key] = info; |
| 249 |
| 210 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 250 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
| 211 DictionaryValue* cache = update.Get(); | 251 DictionaryValue* cache = update.Get(); |
| 212 | 252 |
| 213 scoped_ptr<DictionaryValue> info(new DictionaryValue); | 253 scoped_ptr<DictionaryValue> info_dict(new DictionaryValue); |
| 214 info->SetString(kNameKey, name); | 254 info_dict->SetString(kNameKey, info.name()); |
| 215 info->SetString(kUserNameKey, username); | 255 info_dict->SetString(kUserNameKey, info.user_name()); |
| 216 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); | 256 info_dict->SetString(kAvatarIconKey, |
| 257 GetDefaultAvatarIconUrl(info.icon_index())); |
| 217 // Default value for whether background apps are running is false. | 258 // Default value for whether background apps are running is false. |
| 218 info->SetBoolean(kBackgroundAppsKey, false); | 259 //info->SetBoolean(kBackgroundAppsKey, false); |
| 219 info->SetString(kManagedUserId, managed_user_id); | 260 //info->SetString(kManagedUserId, managed_user_id); |
| 220 info->SetBoolean(kProfileIsEphemeral, false); | 261 //info->SetBoolean(kProfileIsEphemeral, false); |
| 221 cache->SetWithoutPathExpansion(key, info.release()); | 262 //cache->SetWithoutPathExpansion(key, info.release()); |
| 263 info_dict->SetBoolean(kBackgroundAppsKey, false); |
| 264 info_dict->SetString(kManagedUserId, info.managed_user_id()); |
| 222 | 265 |
| 223 sorted_keys_.insert(FindPositionForProfile(key, name), key); | 266 cache->Set(key, info_dict.get()); |
| 224 | 267 |
| 225 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 268 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 226 observer_list_, | 269 observer_list_, |
| 227 OnProfileAdded(profile_path)); | 270 OnProfileAdded(info.path())); |
| 228 | 271 |
| 229 content::NotificationService::current()->Notify( | 272 content::NotificationService::current()->Notify( |
| 230 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 273 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 231 content::NotificationService::AllSources(), | 274 content::NotificationService::AllSources(), |
| 232 content::NotificationService::NoDetails()); | 275 content::NotificationService::NoDetails()); |
| 233 } | 276 } |
| 234 | 277 |
| 235 void ProfileInfoCache::AddObserver(ProfileInfoCacheObserver* obs) { | 278 void ProfileInfoCache::AddProfileToCache(const base::FilePath& profile_path, |
| 236 observer_list_.AddObserver(obs); | 279 const string16& name, |
| 237 } | 280 const string16& username, |
| 238 | 281 size_t icon_index, |
| 239 void ProfileInfoCache::RemoveObserver(ProfileInfoCacheObserver* obs) { | 282 const std::string& managed_user_id) { |
| 240 observer_list_.RemoveObserver(obs); | 283 ProfileInfoEntry entry; |
| 284 if (GetInfoForProfile(profile_path, &entry)) { |
| 285 // The profile is already in the cache, nothing to do. |
| 286 return; |
| 287 } |
| 288 entry.set_path(profile_path); |
| 289 entry.set_name(name); |
| 290 entry.set_user_name(username); |
| 291 entry.set_icon_index(icon_index); |
| 292 entry.set_managed_user_id(managed_user_id); |
| 293 SetInfoForProfile(entry); |
| 241 } | 294 } |
| 242 | 295 |
| 243 void ProfileInfoCache::DeleteProfileFromCache( | 296 void ProfileInfoCache::DeleteProfileFromCache( |
| 244 const base::FilePath& profile_path) { | 297 const base::FilePath& profile_path) { |
| 245 size_t profile_index = GetIndexOfProfileWithPath(profile_path); | |
| 246 if (profile_index == std::string::npos) { | |
| 247 NOTREACHED(); | |
| 248 return; | |
| 249 } | |
| 250 string16 name = GetNameOfProfileAtIndex(profile_index); | |
| 251 | 298 |
| 252 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 299 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 253 observer_list_, | 300 observer_list_, |
| 254 OnProfileWillBeRemoved(profile_path)); | 301 OnProfileWillBeRemoved(profile_path)); |
| 255 | 302 |
| 303 std::string key = CacheKeyFromProfilePath(profile_path); |
| 304 |
| 305 // This should be less suck |
| 306 ProfileInfoEntry p; |
| 307 if (!GetInfoForProfile(profile_path, &p)) |
| 308 return; |
| 309 |
| 310 string16 name = p.name(); |
| 311 |
| 312 if (cached_entries_.count(key)) |
| 313 cached_entries_.erase(key); |
| 314 |
| 256 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 315 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
| 257 DictionaryValue* cache = update.Get(); | 316 DictionaryValue* cache = update.Get(); |
| 258 std::string key = CacheKeyFromProfilePath(profile_path); | |
| 259 cache->Remove(key, NULL); | 317 cache->Remove(key, NULL); |
| 260 sorted_keys_.erase(std::find(sorted_keys_.begin(), sorted_keys_.end(), key)); | |
| 261 | 318 |
| 262 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 319 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 263 observer_list_, | 320 observer_list_, |
| 264 OnProfileWasRemoved(profile_path, name)); | 321 OnProfileWasRemoved(profile_path, name)); |
| 265 | 322 |
| 266 content::NotificationService::current()->Notify( | 323 content::NotificationService::current()->Notify( |
| 267 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 324 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 268 content::NotificationService::AllSources(), | 325 content::NotificationService::AllSources(), |
| 269 content::NotificationService::NoDetails()); | 326 content::NotificationService::NoDetails()); |
| 270 } | 327 } |
| 271 | 328 |
| 272 size_t ProfileInfoCache::GetNumberOfProfiles() const { | |
| 273 return sorted_keys_.size(); | |
| 274 } | |
| 275 | 329 |
| 276 size_t ProfileInfoCache::GetIndexOfProfileWithPath( | |
| 277 const base::FilePath& profile_path) const { | |
| 278 if (profile_path.DirName() != user_data_dir_) | |
| 279 return std::string::npos; | |
| 280 std::string search_key = CacheKeyFromProfilePath(profile_path); | |
| 281 for (size_t i = 0; i < sorted_keys_.size(); ++i) { | |
| 282 if (sorted_keys_[i] == search_key) | |
| 283 return i; | |
| 284 } | |
| 285 return std::string::npos; | |
| 286 } | |
| 287 | 330 |
| 288 string16 ProfileInfoCache::GetNameOfProfileAtIndex(size_t index) const { | |
| 289 string16 name; | |
| 290 if (IsUsingGAIANameOfProfileAtIndex(index)) { | |
| 291 string16 given_name = GetGAIAGivenNameOfProfileAtIndex(index); | |
| 292 name = given_name.empty() ? GetGAIANameOfProfileAtIndex(index) : given_name; | |
| 293 } | |
| 294 | 331 |
| 295 if (name.empty()) | |
| 296 GetInfoForProfileAtIndex(index)->GetString(kNameKey, &name); | |
| 297 return name; | |
| 298 } | |
| 299 | 332 |
| 300 string16 ProfileInfoCache::GetShortcutNameOfProfileAtIndex(size_t index) | |
| 301 const { | |
| 302 string16 shortcut_name; | |
| 303 GetInfoForProfileAtIndex(index)->GetString( | |
| 304 kShortcutNameKey, &shortcut_name); | |
| 305 return shortcut_name; | |
| 306 } | |
| 307 | 333 |
| 308 base::FilePath ProfileInfoCache::GetPathOfProfileAtIndex(size_t index) const { | |
| 309 return user_data_dir_.AppendASCII(sorted_keys_[index]); | |
| 310 } | |
| 311 | 334 |
| 312 string16 ProfileInfoCache::GetUserNameOfProfileAtIndex(size_t index) const { | |
| 313 string16 user_name; | |
| 314 GetInfoForProfileAtIndex(index)->GetString(kUserNameKey, &user_name); | |
| 315 return user_name; | |
| 316 } | |
| 317 | 335 |
| 318 const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfileAtIndex( | 336 // size_t ProfileInfoCache::GetIndexOfProfileWithPath( |
| 319 size_t index) const { | 337 // const base::FilePath& profile_path) const { |
| 320 if (IsUsingGAIAPictureOfProfileAtIndex(index)) { | 338 // if (profile_path.DirName() != user_data_dir_) |
| 321 const gfx::Image* image = GetGAIAPictureOfProfileAtIndex(index); | 339 // return std::string::npos; |
| 340 // std::string search_key = CacheKeyFromProfilePath(profile_path); |
| 341 // for (size_t i = 0; i < sorted_keys_.size(); ++i) { |
| 342 // if (sorted_keys_[i] == search_key) |
| 343 // return i; |
| 344 // } |
| 345 // return std::string::npos; |
| 346 // } |
| 347 |
| 348 // string16 ProfileInfoCache::GetNameOfProfileAtIndex(size_t index) const { |
| 349 // string16 name; |
| 350 // if (IsUsingGAIANameOfProfileAtIndex(index)) { |
| 351 // string16 given_name = GetGAIAGivenNameOfProfileAtIndex(index); |
| 352 // name = given_name.empty() ? GetGAIANameOfProfileAtIndex(index) : given_na
me; |
| 353 // } |
| 354 |
| 355 // if (name.empty()) |
| 356 // GetInfoForProfileAtIndex(index)->GetString(kNameKey, &name); |
| 357 // return name; |
| 358 // } |
| 359 |
| 360 // string16 ProfileInfoCache::GetShortcutNameOfProfileAtIndex(size_t index) |
| 361 // const { |
| 362 // string16 shortcut_name; |
| 363 // GetInfoForProfileAtIndex(index)->GetString( |
| 364 // kShortcutNameKey, &shortcut_name); |
| 365 // return shortcut_name; |
| 366 // } |
| 367 |
| 368 // base::FilePath ProfileInfoCache::GetPathOfProfileAtIndex(size_t index) const
{ |
| 369 // return user_data_dir_.AppendASCII(sorted_keys_[index]); |
| 370 // } |
| 371 |
| 372 // string16 ProfileInfoCache::GetUserNameOfProfileAtIndex(size_t index) const { |
| 373 // string16 user_name; |
| 374 // GetInfoForProfileAtIndex(index)->GetString(kUserNameKey, &user_name); |
| 375 // return user_name; |
| 376 // } |
| 377 |
| 378 const gfx::Image& ProfileInfoCache::GetAvatarIconOfProfile(const base::FilePath&
profile_path) const { |
| 379 ProfileInfoEntry info; |
| 380 |
| 381 // TODO(noms): What happens in the error case here? |
| 382 GetInfoForProfile(profile_path, &info); |
| 383 |
| 384 if (info.is_using_GAIA_picture()) { |
| 385 const gfx::Image* image = GetGAIAPictureOfProfile(profile_path); |
| 322 if (image) | 386 if (image) |
| 323 return *image; | 387 return *image; |
| 324 } | 388 } |
| 325 | 389 |
| 326 int resource_id = GetDefaultAvatarIconResourceIDAtIndex( | 390 int resource_id = GetDefaultAvatarIconResourceIDAtIndex(info.icon_index()); |
| 327 GetAvatarIconIndexOfProfileAtIndex(index)); | |
| 328 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); | 391 return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id); |
| 329 } | 392 } |
| 330 | 393 |
| 331 bool ProfileInfoCache::GetBackgroundStatusOfProfileAtIndex( | 394 // bool ProfileInfoCache::GetBackgroundStatusOfProfileAtIndex( |
| 332 size_t index) const { | 395 // size_t index) const { |
| 333 bool background_app_status; | 396 // bool background_app_status; |
| 334 if (!GetInfoForProfileAtIndex(index)->GetBoolean(kBackgroundAppsKey, | 397 // if (!GetInfoForProfileAtIndex(index)->GetBoolean(kBackgroundAppsKey, |
| 335 &background_app_status)) { | 398 // &background_app_status)) { |
| 336 return false; | 399 // return false; |
| 337 } | 400 // } |
| 338 return background_app_status; | 401 // return background_app_status; |
| 339 } | 402 // } |
| 340 | 403 |
| 341 string16 ProfileInfoCache::GetGAIANameOfProfileAtIndex(size_t index) const { | 404 // string16 ProfileInfoCache::GetGAIANameOfProfileAtIndex(size_t index) const { |
| 342 string16 name; | 405 // string16 name; |
| 343 GetInfoForProfileAtIndex(index)->GetString(kGAIANameKey, &name); | 406 // GetInfoForProfileAtIndex(index)->GetString(kGAIANameKey, &name); |
| 344 return name; | 407 // return name; |
| 345 } | 408 // } |
| 346 | 409 |
| 347 string16 ProfileInfoCache::GetGAIAGivenNameOfProfileAtIndex( | 410 // string16 ProfileInfoCache::GetGAIAGivenNameOfProfileAtIndex( |
| 348 size_t index) const { | 411 // size_t index) const { |
| 349 string16 name; | 412 // string16 name; |
| 350 GetInfoForProfileAtIndex(index)->GetString(kGAIAGivenNameKey, &name); | 413 // GetInfoForProfileAtIndex(index)->GetString(kGAIAGivenNameKey, &name); |
| 351 return name; | 414 // return name; |
| 352 } | 415 // } |
| 353 | 416 |
| 354 bool ProfileInfoCache::IsUsingGAIANameOfProfileAtIndex(size_t index) const { | 417 // bool ProfileInfoCache::IsUsingGAIANameOfProfileAtIndex(size_t index) const { |
| 355 bool value = false; | 418 // bool value = false; |
| 356 GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIANameKey, &value); | 419 // GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIANameKey, &value); |
| 357 return value; | 420 // return value; |
| 358 } | 421 // } |
| 359 | 422 |
| 360 const gfx::Image* ProfileInfoCache::GetGAIAPictureOfProfileAtIndex( | 423 const gfx::Image* ProfileInfoCache::GetGAIAPictureOfProfile( |
| 361 size_t index) const { | 424 const base::FilePath& profile_path) const { |
| 362 base::FilePath path = GetPathOfProfileAtIndex(index); | 425 ProfileInfoEntry info; |
| 363 std::string key = CacheKeyFromProfilePath(path); | 426 if (!GetInfoForProfile(profile_path, &info)) |
| 427 return NULL; |
| 428 |
| 429 std::string key = CacheKeyFromProfilePath(profile_path); |
| 364 | 430 |
| 365 // If the picture is already loaded then use it. | 431 // If the picture is already loaded then use it. |
| 366 if (gaia_pictures_.count(key)) { | 432 if (gaia_pictures_.count(key)) { |
| 367 if (gaia_pictures_[key]->IsEmpty()) | 433 if (gaia_pictures_[key]->IsEmpty()) |
| 368 return NULL; | 434 return NULL; |
| 369 return gaia_pictures_[key]; | 435 return gaia_pictures_[key]; |
| 370 } | 436 } |
| 371 | 437 |
| 372 std::string file_name; | 438 std::string file_name = info.GAIA_picture_file_name(); |
| 373 GetInfoForProfileAtIndex(index)->GetString( | |
| 374 kGAIAPictureFileNameKey, &file_name); | |
| 375 | 439 |
| 376 // If the picture is not on disk or it is already being loaded then return | 440 // If the picture is not on disk or it is already being loaded then return |
| 377 // NULL. | 441 // NULL. |
| 378 if (file_name.empty() || gaia_pictures_loading_[key]) | 442 if (file_name.empty() || gaia_pictures_loading_[key]) |
| 379 return NULL; | 443 return NULL; |
| 380 | 444 |
| 381 gaia_pictures_loading_[key] = true; | 445 gaia_pictures_loading_[key] = true; |
| 382 base::FilePath image_path = path.AppendASCII(file_name); | 446 base::FilePath image_path = profile_path.AppendASCII(file_name); |
| 383 gfx::Image** image = new gfx::Image*; | 447 gfx::Image** image = new gfx::Image*; |
| 384 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 448 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
| 385 base::Bind(&ReadBitmap, image_path, image), | 449 base::Bind(&ReadBitmap, image_path, image), |
| 386 base::Bind(&ProfileInfoCache::OnGAIAPictureLoaded, | 450 base::Bind(&ProfileInfoCache::OnGAIAPictureLoaded, |
| 387 const_cast<ProfileInfoCache*>(this)->AsWeakPtr(), path, image)); | 451 const_cast<ProfileInfoCache*>(this)->AsWeakPtr(), |
| 452 profile_path, image)); |
| 388 | 453 |
| 389 return NULL; | 454 return NULL; |
| 390 } | 455 } |
| 391 | 456 |
| 392 bool ProfileInfoCache::ProfileIsManagedAtIndex(size_t index) const { | 457 // bool ProfileInfoCache::ProfileIsManagedAtIndex(size_t index) const { |
| 393 return !GetManagedUserIdOfProfileAtIndex(index).empty(); | 458 // return !GetManagedUserIdOfProfileAtIndex(index).empty(); |
| 394 } | 459 // } |
| 395 | 460 |
| 396 bool ProfileInfoCache::ProfileIsSigninRequiredAtIndex(size_t index) const { | 461 // bool ProfileInfoCache::ProfileIsSigninRequiredAtIndex(size_t index) const { |
| 397 bool value = false; | 462 // bool value = false; |
| 398 GetInfoForProfileAtIndex(index)->GetBoolean(kSigninRequiredKey, &value); | 463 // GetInfoForProfileAtIndex(index)->GetBoolean(kSigninRequiredKey, &value); |
| 399 return value; | 464 // return value; |
| 400 } | 465 // } |
| 401 | 466 |
| 402 std::string ProfileInfoCache::GetManagedUserIdOfProfileAtIndex( | 467 // std::string ProfileInfoCache::GetManagedUserIdOfProfileAtIndex( |
| 403 size_t index) const { | 468 // size_t index) const { |
| 404 std::string managed_user_id; | 469 // std::string managed_user_id; |
| 405 GetInfoForProfileAtIndex(index)->GetString(kManagedUserId, &managed_user_id); | 470 // GetInfoForProfileAtIndex(index)->GetString(kManagedUserId, &managed_user_id
); |
| 406 return managed_user_id; | 471 // return managed_user_id; |
| 407 } | 472 // } |
| 408 | 473 |
| 409 bool ProfileInfoCache::ProfileIsEphemeralAtIndex(size_t index) const { | 474 bool ProfileInfoCache::ProfileIsEphemeralAtIndex(size_t index) const { |
| 410 bool value = false; | 475 bool value = false; |
| 411 GetInfoForProfileAtIndex(index)->GetBoolean(kProfileIsEphemeral, &value); | 476 GetInfoForProfileAtIndex(index)->GetBoolean(kProfileIsEphemeral, &value); |
| 412 return value; | 477 return value; |
| 413 } | 478 } |
| 414 | 479 |
| 415 void ProfileInfoCache::OnGAIAPictureLoaded(const base::FilePath& path, | 480 void ProfileInfoCache::OnGAIAPictureLoaded(const base::FilePath& path, |
| 416 gfx::Image** image) const { | 481 gfx::Image** image) const { |
| 417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 482 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 440 | 505 |
| 441 if (*success) { | 506 if (*success) { |
| 442 content::NotificationService::current()->Notify( | 507 content::NotificationService::current()->Notify( |
| 443 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, | 508 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, |
| 444 content::NotificationService::AllSources(), | 509 content::NotificationService::AllSources(), |
| 445 content::NotificationService::NoDetails()); | 510 content::NotificationService::NoDetails()); |
| 446 } | 511 } |
| 447 delete success; | 512 delete success; |
| 448 } | 513 } |
| 449 | 514 |
| 450 bool ProfileInfoCache::IsUsingGAIAPictureOfProfileAtIndex( | 515 // bool ProfileInfoCache::IsUsingGAIAPictureOfProfileAtIndex( |
| 451 size_t index) const { | 516 // size_t index) const { |
| 452 bool value = false; | 517 // bool value = false; |
| 453 GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIAPictureKey, &value); | 518 // GetInfoForProfileAtIndex(index)->GetBoolean(kUseGAIAPictureKey, &value); |
| 454 return value; | 519 // return value; |
| 455 } | 520 // } |
| 456 | 521 |
| 457 size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index) | 522 // size_t ProfileInfoCache::GetAvatarIconIndexOfProfileAtIndex(size_t index) |
| 458 const { | 523 // const { |
| 459 std::string icon_url; | 524 // std::string icon_url; |
| 460 GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); | 525 // GetInfoForProfileAtIndex(index)->GetString(kAvatarIconKey, &icon_url); |
| 461 size_t icon_index = 0; | 526 // size_t icon_index = 0; |
| 462 if (!IsDefaultAvatarIconUrl(icon_url, &icon_index)) | 527 // if (!IsDefaultAvatarIconUrl(icon_url, &icon_index)) |
| 463 DLOG(WARNING) << "Unknown avatar icon: " << icon_url; | 528 // DLOG(WARNING) << "Unknown avatar icon: " << icon_url; |
| 464 | 529 |
| 465 return icon_index; | 530 // return icon_index; |
| 466 } | 531 // } |
| 467 | 532 |
| 468 void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, | 533 // void ProfileInfoCache::SetNameOfProfileAtIndex(size_t index, |
| 469 const string16& name) { | 534 // const string16& name) { |
| 470 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 535 // scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy(
)); |
| 471 string16 current_name; | 536 // string16 current_name; |
| 472 info->GetString(kNameKey, ¤t_name); | 537 // info->GetString(kNameKey, ¤t_name); |
| 473 if (name == current_name) | 538 // if (name == current_name) |
| 474 return; | 539 // return; |
| 475 | 540 |
| 476 string16 old_display_name = GetNameOfProfileAtIndex(index); | 541 // string16 old_display_name = GetNameOfProfileAtIndex(index); |
| 477 info->SetString(kNameKey, name); | 542 // info->SetString(kNameKey, name); |
| 478 // This takes ownership of |info|. | 543 // // This takes ownership of |info|. |
| 479 SetInfoForProfileAtIndex(index, info.release()); | 544 // SetInfoForProfileAtIndex(index, info.release()); |
| 480 string16 new_display_name = GetNameOfProfileAtIndex(index); | 545 // string16 new_display_name = GetNameOfProfileAtIndex(index); |
| 481 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 546 // base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 482 UpdateSortForProfileIndex(index); | 547 // UpdateSortForProfileIndex(index); |
| 483 | 548 |
| 484 if (old_display_name != new_display_name) { | 549 // if (old_display_name != new_display_name) { |
| 485 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 550 // FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 486 observer_list_, | 551 // observer_list_, |
| 487 OnProfileNameChanged(profile_path, old_display_name)); | 552 // OnProfileNameChanged(profile_path, old_display_name)); |
| 488 } | 553 // } |
| 489 } | 554 // } |
| 490 | 555 |
| 491 void ProfileInfoCache::SetShortcutNameOfProfileAtIndex( | 556 // void ProfileInfoCache::SetShortcutNameOfProfileAtIndex( |
| 492 size_t index, | 557 // size_t index, |
| 493 const string16& shortcut_name) { | 558 // const string16& shortcut_name) { |
| 494 if (shortcut_name == GetShortcutNameOfProfileAtIndex(index)) | 559 // if (shortcut_name == GetShortcutNameOfProfileAtIndex(index)) |
| 495 return; | 560 // return; |
| 496 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 561 // scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy(
)); |
| 497 info->SetString(kShortcutNameKey, shortcut_name); | 562 // info->SetString(kShortcutNameKey, shortcut_name); |
| 498 // This takes ownership of |info|. | 563 // // This takes ownership of |info|. |
| 499 SetInfoForProfileAtIndex(index, info.release()); | 564 // SetInfoForProfileAtIndex(index, info.release()); |
| 500 } | 565 // } |
| 501 | 566 |
| 502 void ProfileInfoCache::SetUserNameOfProfileAtIndex(size_t index, | 567 // void ProfileInfoCache::SetUserNameOfProfileAtIndex(size_t index, |
| 503 const string16& user_name) { | 568 // const string16& user_name)
{ |
| 504 if (user_name == GetUserNameOfProfileAtIndex(index)) | 569 // if (user_name == GetUserNameOfProfileAtIndex(index)) |
| 505 return; | 570 // return; |
| 506 | 571 |
| 507 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 572 // scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy(
)); |
| 508 info->SetString(kUserNameKey, user_name); | 573 // info->SetString(kUserNameKey, user_name); |
| 509 // This takes ownership of |info|. | 574 // // This takes ownership of |info|. |
| 510 SetInfoForProfileAtIndex(index, info.release()); | 575 // SetInfoForProfileAtIndex(index, info.release()); |
| 511 } | 576 // } |
| 512 | 577 |
| 513 void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, | 578 // void ProfileInfoCache::SetAvatarIconOfProfileAtIndex(size_t index, |
| 514 size_t icon_index) { | 579 // size_t icon_index) { |
| 515 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 580 // scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy(
)); |
| 516 info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); | 581 // info->SetString(kAvatarIconKey, GetDefaultAvatarIconUrl(icon_index)); |
| 517 // This takes ownership of |info|. | 582 // // This takes ownership of |info|. |
| 518 SetInfoForProfileAtIndex(index, info.release()); | 583 // SetInfoForProfileAtIndex(index, info.release()); |
| 519 | 584 |
| 520 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 585 // base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 521 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 586 // FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 522 observer_list_, | 587 // observer_list_, |
| 523 OnProfileAvatarChanged(profile_path)); | 588 // OnProfileAvatarChanged(profile_path)); |
| 524 } | 589 // } |
| 525 | 590 |
| 526 void ProfileInfoCache::SetManagedUserIdOfProfileAtIndex(size_t index, | 591 // void ProfileInfoCache::SetManagedUserIdOfProfileAtIndex(size_t index, |
| 527 const std::string& id) { | 592 // const std::string& id
) { |
| 528 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 593 // scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy(
)); |
| 529 info->SetString(kManagedUserId, id); | 594 // info->SetString(kManagedUserId, id); |
| 530 // This takes ownership of |info|. | 595 // // This takes ownership of |info|. |
| 531 SetInfoForProfileAtIndex(index, info.release()); | 596 // SetInfoForProfileAtIndex(index, info.release()); |
| 532 } | 597 // } |
| 533 | 598 |
| 534 void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex( | 599 // void ProfileInfoCache::SetBackgroundStatusOfProfileAtIndex( |
| 535 size_t index, | 600 // size_t index, |
| 536 bool running_background_apps) { | 601 // bool running_background_apps) { |
| 537 if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps) | 602 // if (GetBackgroundStatusOfProfileAtIndex(index) == running_background_apps) |
| 538 return; | 603 // return; |
| 539 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 604 // scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy(
)); |
| 540 info->SetBoolean(kBackgroundAppsKey, running_background_apps); | 605 // info->SetBoolean(kBackgroundAppsKey, running_background_apps); |
| 541 // This takes ownership of |info|. | 606 // // This takes ownership of |info|. |
| 542 SetInfoForProfileAtIndex(index, info.release()); | 607 // SetInfoForProfileAtIndex(index, info.release()); |
| 543 } | 608 // } |
| 544 | 609 |
| 545 void ProfileInfoCache::SetGAIANameOfProfileAtIndex(size_t index, | 610 // void ProfileInfoCache::SetGAIANameOfProfileAtIndex(size_t index, |
| 546 const string16& name) { | 611 // const string16& name) { |
| 547 if (name == GetGAIANameOfProfileAtIndex(index)) | 612 // if (name == GetGAIANameOfProfileAtIndex(index)) |
| 548 return; | 613 // return; |
| 549 | 614 |
| 550 string16 old_display_name = GetNameOfProfileAtIndex(index); | 615 // string16 old_display_name = GetNameOfProfileAtIndex(index); |
| 551 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 616 // scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy(
)); |
| 552 info->SetString(kGAIANameKey, name); | 617 // info->SetString(kGAIANameKey, name); |
| 553 // This takes ownership of |info|. | 618 // // This takes ownership of |info|. |
| 554 SetInfoForProfileAtIndex(index, info.release()); | 619 // SetInfoForProfileAtIndex(index, info.release()); |
| 555 string16 new_display_name = GetNameOfProfileAtIndex(index); | 620 // string16 new_display_name = GetNameOfProfileAtIndex(index); |
| 556 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 621 // base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 557 UpdateSortForProfileIndex(index); | 622 // UpdateSortForProfileIndex(index); |
| 558 | 623 |
| 559 if (old_display_name != new_display_name) { | 624 // if (old_display_name != new_display_name) { |
| 560 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 625 // FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 561 observer_list_, | 626 // observer_list_, |
| 562 OnProfileNameChanged(profile_path, old_display_name)); | 627 // OnProfileNameChanged(profile_path, old_display_name)); |
| 563 } | 628 // } |
| 564 } | 629 // } |
| 565 | 630 |
| 566 void ProfileInfoCache::SetGAIAGivenNameOfProfileAtIndex( | 631 // void ProfileInfoCache::SetGAIAGivenNameOfProfileAtIndex( |
| 567 size_t index, | 632 // size_t index, |
| 568 const string16& name) { | 633 // const string16& name) { |
| 569 if (name == GetGAIAGivenNameOfProfileAtIndex(index)) | 634 // if (name == GetGAIAGivenNameOfProfileAtIndex(index)) |
| 570 return; | 635 // return; |
| 571 | 636 |
| 572 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 637 // scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy(
)); |
| 573 info->SetString(kGAIAGivenNameKey, name); | 638 // info->SetString(kGAIAGivenNameKey, name); |
| 574 // This takes ownership of |info|. | 639 // // This takes ownership of |info|. |
| 575 SetInfoForProfileAtIndex(index, info.release()); | 640 // SetInfoForProfileAtIndex(index, info.release()); |
| 576 } | 641 // } |
| 577 | 642 |
| 578 void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index, | 643 // void ProfileInfoCache::SetIsUsingGAIANameOfProfileAtIndex(size_t index, |
| 579 bool value) { | 644 // bool value) { |
| 580 if (value == IsUsingGAIANameOfProfileAtIndex(index)) | 645 // if (value == IsUsingGAIANameOfProfileAtIndex(index)) |
| 581 return; | 646 // return; |
| 582 | 647 |
| 583 string16 old_display_name = GetNameOfProfileAtIndex(index); | 648 // string16 old_display_name = GetNameOfProfileAtIndex(index); |
| 584 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 649 // scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy(
)); |
| 585 info->SetBoolean(kUseGAIANameKey, value); | 650 // info->SetBoolean(kUseGAIANameKey, value); |
| 586 // This takes ownership of |info|. | 651 // // This takes ownership of |info|. |
| 587 SetInfoForProfileAtIndex(index, info.release()); | 652 // SetInfoForProfileAtIndex(index, info.release()); |
| 588 string16 new_display_name = GetNameOfProfileAtIndex(index); | 653 // string16 new_display_name = GetNameOfProfileAtIndex(index); |
| 589 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 654 // base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 590 UpdateSortForProfileIndex(index); | 655 // UpdateSortForProfileIndex(index); |
| 591 | 656 |
| 592 if (old_display_name != new_display_name) { | 657 // if (old_display_name != new_display_name) { |
| 593 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 658 // FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 594 observer_list_, | 659 // observer_list_, |
| 595 OnProfileNameChanged(profile_path, old_display_name)); | 660 // OnProfileNameChanged(profile_path, old_display_name)); |
| 596 } | 661 // } |
| 597 } | 662 // } |
| 598 | 663 |
| 599 void ProfileInfoCache::SetGAIAPictureOfProfileAtIndex(size_t index, | 664 void ProfileInfoCache::SetGAIAPictureOfProfile(const base::FilePath& path, |
| 600 const gfx::Image* image) { | 665 const gfx::Image* image) { |
| 601 base::FilePath path = GetPathOfProfileAtIndex(index); | 666 ProfileInfoEntry entry; |
| 667 GetInfoForProfile(path, &entry); |
| 668 |
| 602 std::string key = CacheKeyFromProfilePath(path); | 669 std::string key = CacheKeyFromProfilePath(path); |
| 603 | 670 |
| 604 // Delete the old bitmap from cache. | 671 // Delete the old bitmap from cache. |
| 605 std::map<std::string, gfx::Image*>::iterator it = gaia_pictures_.find(key); | 672 std::map<std::string, gfx::Image*>::iterator it = gaia_pictures_.find(key); |
| 606 if (it != gaia_pictures_.end()) { | 673 if (it != gaia_pictures_.end()) { |
| 607 delete it->second; | 674 delete it->second; |
| 608 gaia_pictures_.erase(it); | 675 gaia_pictures_.erase(it); |
| 609 } | 676 } |
| 610 | 677 |
| 611 std::string old_file_name; | 678 std::string old_file_name = entry.GAIA_picture_file_name(); |
| 612 GetInfoForProfileAtIndex(index)->GetString( | |
| 613 kGAIAPictureFileNameKey, &old_file_name); | |
| 614 std::string new_file_name; | 679 std::string new_file_name; |
| 615 | 680 |
| 616 if (!image) { | 681 if (!image) { |
| 617 // Delete the old bitmap from disk. | 682 // Delete the old bitmap from disk. |
| 618 if (!old_file_name.empty()) { | 683 if (!old_file_name.empty()) { |
| 619 base::FilePath image_path = path.AppendASCII(old_file_name); | 684 base::FilePath image_path = path.AppendASCII(old_file_name); |
| 620 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 685 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 621 base::Bind(&DeleteBitmap, image_path)); | 686 base::Bind(&DeleteBitmap, image_path)); |
| 622 } | 687 } |
| 623 } else { | 688 } else { |
| 624 // Save the new bitmap to disk. | 689 // Save the new bitmap to disk. |
| 625 gaia_pictures_[key] = new gfx::Image(*image); | 690 gaia_pictures_[key] = new gfx::Image(*image); |
| 626 scoped_ptr<ImageData> data(new ImageData); | 691 scoped_ptr<ImageData> data(new ImageData); |
| 627 scoped_refptr<base::RefCountedMemory> png_data = image->As1xPNGBytes(); | 692 scoped_refptr<base::RefCountedMemory> png_data = image->As1xPNGBytes(); |
| 628 data->assign(png_data->front(), png_data->front() + png_data->size()); | 693 data->assign(png_data->front(), png_data->front() + png_data->size()); |
| 629 if (!data->size()) { | 694 if (!data->size()) { |
| 630 LOG(ERROR) << "Failed to PNG encode the image."; | 695 LOG(ERROR) << "Failed to PNG encode the image."; |
| 631 } else { | 696 } else { |
| 632 new_file_name = | 697 new_file_name = |
| 633 old_file_name.empty() ? kGAIAPictureFileName : old_file_name; | 698 old_file_name.empty() ? kGAIAPictureFileName : old_file_name; |
| 634 base::FilePath image_path = path.AppendASCII(new_file_name); | 699 base::FilePath image_path = path.AppendASCII(new_file_name); |
| 635 bool* success = new bool; | 700 bool* success = new bool; |
| 636 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 701 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, |
| 637 base::Bind(&SaveBitmap, data.release(), image_path, success), | 702 base::Bind(&SaveBitmap, data.release(), image_path, success), |
| 638 base::Bind(&ProfileInfoCache::OnGAIAPictureSaved, AsWeakPtr(), | 703 base::Bind(&ProfileInfoCache::OnGAIAPictureSaved, AsWeakPtr(), |
| 639 path, success)); | 704 path, success)); |
| 640 } | 705 } |
| 641 } | 706 } |
| 642 | 707 |
| 643 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 708 entry.set_GAIA_picture_file_name(new_file_name); |
| 644 info->SetString(kGAIAPictureFileNameKey, new_file_name); | 709 SetInfoForProfile(entry); |
| 645 // This takes ownership of |info|. | |
| 646 SetInfoForProfileAtIndex(index, info.release()); | |
| 647 | 710 |
| 648 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 711 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 649 observer_list_, | 712 observer_list_, |
| 650 OnProfileAvatarChanged(path)); | 713 OnProfileAvatarChanged(path)); |
| 651 } | 714 } |
| 652 | 715 |
| 653 void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, | 716 // void ProfileInfoCache::SetIsUsingGAIAPictureOfProfileAtIndex(size_t index, |
| 654 bool value) { | 717 // bool value) { |
| 655 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 718 // scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy(
)); |
| 656 info->SetBoolean(kUseGAIAPictureKey, value); | 719 // info->SetBoolean(kUseGAIAPictureKey, value); |
| 657 // This takes ownership of |info|. | 720 // // This takes ownership of |info|. |
| 658 SetInfoForProfileAtIndex(index, info.release()); | 721 // SetInfoForProfileAtIndex(index, info.release()); |
| 659 | 722 |
| 660 // Retrieve some info to update observers who care about avatar changes. | 723 // // Retrieve some info to update observers who care about avatar changes. |
| 661 base::FilePath profile_path = GetPathOfProfileAtIndex(index); | 724 // base::FilePath profile_path = GetPathOfProfileAtIndex(index); |
| 662 FOR_EACH_OBSERVER(ProfileInfoCacheObserver, | 725 // FOR_EACH_OBSERVER(ProfileInfoCacheObserver, |
| 663 observer_list_, | 726 // observer_list_, |
| 664 OnProfileAvatarChanged(profile_path)); | 727 // OnProfileAvatarChanged(profile_path)); |
| 665 } | 728 // } |
| 666 | 729 |
| 667 void ProfileInfoCache::SetProfileSigninRequiredAtIndex(size_t index, | 730 // void ProfileInfoCache::SetProfileSigninRequiredAtIndex(size_t index, |
| 668 bool value) { | 731 // bool value) { |
| 669 if (value == ProfileIsSigninRequiredAtIndex(index)) | 732 // if (value == ProfileIsSigninRequiredAtIndex(index)) |
| 670 return; | 733 // return; |
| 671 | 734 |
| 672 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 735 // scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy(
)); |
| 673 info->SetBoolean(kSigninRequiredKey, value); | 736 // info->SetBoolean(kSigninRequiredKey, value); |
| 674 // This takes ownership of |info|. | 737 // // This takes ownership of |info|. |
| 675 SetInfoForProfileAtIndex(index, info.release()); | 738 // SetInfoForProfileAtIndex(index, info.release()); |
| 676 } | 739 // } |
| 677 | 740 |
| 678 void ProfileInfoCache::SetProfileIsEphemeralAtIndex(size_t index, bool value) { | 741 void ProfileInfoCache::SetProfileIsEphemeralAtIndex(size_t index, bool value) { |
| 679 if (value == ProfileIsEphemeralAtIndex(index)) | 742 if (value == ProfileIsEphemeralAtIndex(index)) |
| 680 return; | 743 return; |
| 681 | 744 |
| 682 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 745 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); |
| 683 info->SetBoolean(kProfileIsEphemeral, value); | 746 info->SetBoolean(kProfileIsEphemeral, value); |
| 684 // This takes ownership of |info|. | 747 // This takes ownership of |info|. |
| 685 SetInfoForProfileAtIndex(index, info.release()); | 748 SetInfoForProfileAtIndex(index, info.release()); |
| 686 } | 749 } |
| 687 | 750 |
| 688 string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) const { | 751 string16 ProfileInfoCache::ChooseNameForNewProfile(size_t icon_index) const { |
| 689 string16 name; | 752 string16 name; |
| 690 for (int name_index = 1; ; ++name_index) { | 753 for (int name_index = 1; ; ++name_index) { |
| 691 if (icon_index < kGenericIconCount) { | 754 if (icon_index < kGenericIconCount) { |
| 692 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME, | 755 name = l10n_util::GetStringFUTF16Int(IDS_NUMBERED_PROFILE_NAME, |
| 693 name_index); | 756 name_index); |
| 694 } else { | 757 } else { |
| 695 name = l10n_util::GetStringUTF16( | 758 name = l10n_util::GetStringUTF16( |
| 696 kDefaultNames[icon_index - kGenericIconCount]); | 759 kDefaultNames[icon_index - kGenericIconCount]); |
| 697 if (name_index > 1) | 760 if (name_index > 1) |
| 698 name.append(UTF8ToUTF16(base::IntToString(name_index))); | 761 name.append(UTF8ToUTF16(base::IntToString(name_index))); |
| 699 } | 762 } |
| 700 | 763 |
| 701 // Loop through previously named profiles to ensure we're not duplicating. | 764 // Loop through previously named profiles to ensure we're not duplicating. |
| 702 bool name_found = false; | 765 bool name_found = false; |
| 703 for (size_t i = 0; i < GetNumberOfProfiles(); ++i) { | 766 |
| 704 if (GetNameOfProfileAtIndex(i) == name) { | 767 const std::vector<ProfileInfoEntry> entries(GetProfilesSortedByName()); |
| 768 for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin(); |
| 769 it != entries.end(); ++it) { |
| 770 if (it->GetDisplayName() == name) { |
| 705 name_found = true; | 771 name_found = true; |
| 706 break; | 772 break; |
| 707 } | 773 } |
| 708 } | 774 } |
| 709 if (!name_found) | 775 if (!name_found) |
| 710 return name; | 776 return name; |
| 711 } | 777 } |
| 712 } | 778 } |
| 713 | 779 |
| 714 bool ProfileInfoCache::GetHasMigratedToGAIAInfoOfProfileAtIndex( | 780 // bool ProfileInfoCache::GetHasMigratedToGAIAInfoOfProfileAtIndex( |
| 715 size_t index) const { | 781 // size_t index) const { |
| 716 bool value = false; | 782 // bool value = false; |
| 717 GetInfoForProfileAtIndex(index)->GetBoolean( | 783 // GetInfoForProfileAtIndex(index)->GetBoolean( |
| 718 kHasMigratedToGAIAInfoKey, &value); | 784 // kHasMigratedToGAIAInfoKey, &value); |
| 719 return value; | 785 // return value; |
| 720 } | 786 // } |
| 721 | 787 |
| 722 void ProfileInfoCache::SetHasMigratedToGAIAInfoOfProfileAtIndex( | 788 // void ProfileInfoCache::SetHasMigratedToGAIAInfoOfProfileAtIndex( |
| 723 size_t index, bool value) { | 789 // size_t index, bool value) { |
| 724 scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy()); | 790 // scoped_ptr<DictionaryValue> info(GetInfoForProfileAtIndex(index)->DeepCopy(
)); |
| 725 info->SetBoolean(kHasMigratedToGAIAInfoKey, value); | 791 // info->SetBoolean(kHasMigratedToGAIAInfoKey, value); |
| 726 // This takes ownership of |info|. | 792 // // This takes ownership of |info|. |
| 727 SetInfoForProfileAtIndex(index, info.release()); | 793 // SetInfoForProfileAtIndex(index, info.release()); |
| 728 } | 794 // } |
| 729 | 795 |
| 730 bool ProfileInfoCache::IconIndexIsUnique(size_t icon_index) const { | 796 bool ProfileInfoCache::IconIndexIsUnique(size_t icon_index) const { |
| 731 for (size_t i = 0; i < GetNumberOfProfiles(); ++i) { | 797 const std::vector<ProfileInfoEntry> entries(GetProfilesSortedByName()); |
| 732 if (GetAvatarIconIndexOfProfileAtIndex(i) == icon_index) | 798 for (std::vector<ProfileInfoEntry>::const_iterator it = entries.begin(); |
| 799 it != entries.end(); ++it) { |
| 800 if (it->icon_index() == icon_index) |
| 733 return false; | 801 return false; |
| 734 } | 802 } |
| 735 return true; | 803 return true; |
| 736 } | 804 } |
| 737 | 805 |
| 738 bool ProfileInfoCache::ChooseAvatarIconIndexForNewProfile( | 806 bool ProfileInfoCache::ChooseAvatarIconIndexForNewProfile( |
| 739 bool allow_generic_icon, | 807 bool allow_generic_icon, |
| 740 bool must_be_unique, | 808 bool must_be_unique, |
| 741 size_t* out_icon_index) const { | 809 size_t* out_icon_index) const { |
| 742 size_t start = allow_generic_icon ? 0 : kGenericIconCount; | 810 size_t start = allow_generic_icon ? 0 : kGenericIconCount; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 if (int_value < 0 || | 880 if (int_value < 0 || |
| 813 int_value >= static_cast<int>(kDefaultAvatarIconsCount)) | 881 int_value >= static_cast<int>(kDefaultAvatarIconsCount)) |
| 814 return false; | 882 return false; |
| 815 *icon_index = int_value; | 883 *icon_index = int_value; |
| 816 return true; | 884 return true; |
| 817 } | 885 } |
| 818 | 886 |
| 819 return false; | 887 return false; |
| 820 } | 888 } |
| 821 | 889 |
| 822 const DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex( | 890 // const DictionaryValue* ProfileInfoCache::GetInfoForProfileAtIndex( |
| 823 size_t index) const { | 891 // size_t index) const { |
| 824 DCHECK_LT(index, GetNumberOfProfiles()); | 892 // DCHECK_LT(index, GetNumberOfProfiles()); |
| 825 const DictionaryValue* cache = | 893 // const DictionaryValue* cache = |
| 826 prefs_->GetDictionary(prefs::kProfileInfoCache); | 894 // prefs_->GetDictionary(prefs::kProfileInfoCache); |
| 827 const DictionaryValue* info = NULL; | 895 // const DictionaryValue* info = NULL; |
| 828 cache->GetDictionaryWithoutPathExpansion(sorted_keys_[index], &info); | 896 // cache->GetDictionaryWithoutPathExpansion(sorted_keys_[index], &info); |
| 829 return info; | 897 // return info; |
| 830 } | 898 // } |
| 831 | 899 |
| 832 void ProfileInfoCache::SetInfoForProfileAtIndex(size_t index, | 900 // void ProfileInfoCache::SetInfoForProfileAtIndex(size_t index, |
| 833 DictionaryValue* info) { | 901 // DictionaryValue* info) { |
| 834 DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); | 902 // DictionaryPrefUpdate update(prefs_, prefs::kProfileInfoCache); |
| 835 DictionaryValue* cache = update.Get(); | 903 // DictionaryValue* cache = update.Get(); |
| 836 cache->SetWithoutPathExpansion(sorted_keys_[index], info); | 904 // cache->SetWithoutPathExpansion(sorted_keys_[index], info); |
| 837 | 905 |
| 838 content::NotificationService::current()->Notify( | 906 // content::NotificationService::current()->Notify( |
| 839 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 907 // chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 840 content::NotificationService::AllSources(), | 908 // content::NotificationService::AllSources(), |
| 841 content::NotificationService::NoDetails()); | 909 // content::NotificationService::NoDetails()); |
| 842 } | 910 // } |
| 843 | 911 |
| 844 std::string ProfileInfoCache::CacheKeyFromProfilePath( | 912 std::string ProfileInfoCache::CacheKeyFromProfilePath( |
| 845 const base::FilePath& profile_path) const { | 913 const base::FilePath& profile_path) const { |
| 846 DCHECK(user_data_dir_ == profile_path.DirName()); | 914 //DCHECK(user_data_dir_ == profile_path.DirName()); |
| 915 LOG(ERROR) << "user data is " << user_data_dir_.MaybeAsASCII(); |
| 916 LOG(ERROR) << "profile path is " << profile_path.DirName().MaybeAsASCII(); |
| 847 base::FilePath base_name = profile_path.BaseName(); | 917 base::FilePath base_name = profile_path.BaseName(); |
| 848 return base_name.MaybeAsASCII(); | 918 return base_name.MaybeAsASCII(); |
| 849 } | 919 } |
| 850 | 920 |
| 851 std::vector<std::string>::iterator ProfileInfoCache::FindPositionForProfile( | 921 // std::vector<std::string>::iterator ProfileInfoCache::FindPositionForProfile( |
| 852 const std::string& search_key, | 922 // const std::string& search_key, |
| 853 const string16& search_name) { | 923 // const string16& search_name) { |
| 854 string16 search_name_l = base::i18n::ToLower(search_name); | 924 // string16 search_name_l = base::i18n::ToLower(search_name); |
| 855 for (size_t i = 0; i < GetNumberOfProfiles(); ++i) { | 925 // for (size_t i = 0; i < GetNumberOfProfiles(); ++i) { |
| 856 string16 name_l = base::i18n::ToLower(GetNameOfProfileAtIndex(i)); | 926 // string16 name_l = base::i18n::ToLower(GetNameOfProfileAtIndex(i)); |
| 857 int name_compare = search_name_l.compare(name_l); | 927 // int name_compare = search_name_l.compare(name_l); |
| 858 if (name_compare < 0) | 928 // if (name_compare < 0) |
| 859 return sorted_keys_.begin() + i; | 929 // return sorted_keys_.begin() + i; |
| 860 if (name_compare == 0) { | 930 // if (name_compare == 0) { |
| 861 int key_compare = search_key.compare(sorted_keys_[i]); | 931 // int key_compare = search_key.compare(sorted_keys_[i]); |
| 862 if (key_compare < 0) | 932 // if (key_compare < 0) |
| 863 return sorted_keys_.begin() + i; | 933 // return sorted_keys_.begin() + i; |
| 864 } | 934 // } |
| 865 } | 935 // } |
| 866 return sorted_keys_.end(); | 936 // return sorted_keys_.end(); |
| 867 } | 937 // } |
| 868 | 938 |
| 869 void ProfileInfoCache::UpdateSortForProfileIndex(size_t index) { | 939 // void ProfileInfoCache::UpdateSortForProfileIndex(size_t index) { |
| 870 string16 name = GetNameOfProfileAtIndex(index); | 940 // string16 name = GetNameOfProfileAtIndex(index); |
| 871 | 941 |
| 872 // Remove and reinsert key in |sorted_keys_| to alphasort. | 942 // // Remove and reinsert key in |sorted_keys_| to alphasort. |
| 873 std::string key = CacheKeyFromProfilePath(GetPathOfProfileAtIndex(index)); | 943 // std::string key = CacheKeyFromProfilePath(GetPathOfProfileAtIndex(index)); |
| 874 std::vector<std::string>::iterator key_it = | 944 // std::vector<std::string>::iterator key_it = |
| 875 std::find(sorted_keys_.begin(), sorted_keys_.end(), key); | 945 // std::find(sorted_keys_.begin(), sorted_keys_.end(), key); |
| 876 DCHECK(key_it != sorted_keys_.end()); | 946 // DCHECK(key_it != sorted_keys_.end()); |
| 877 sorted_keys_.erase(key_it); | 947 // sorted_keys_.erase(key_it); |
| 878 sorted_keys_.insert(FindPositionForProfile(key, name), key); | 948 // sorted_keys_.insert(FindPositionForProfile(key, name), key); |
| 879 | 949 |
| 880 content::NotificationService::current()->Notify( | 950 // content::NotificationService::current()->Notify( |
| 881 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 951 // chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 882 content::NotificationService::AllSources(), | 952 // content::NotificationService::AllSources(), |
| 883 content::NotificationService::NoDetails()); | 953 // content::NotificationService::NoDetails()); |
| 884 } | 954 // } |
| 885 | 955 |
| 886 // static | 956 // static |
| 887 std::vector<string16> ProfileInfoCache::GetProfileNames() { | 957 std::vector<string16> ProfileInfoCache::GetProfileNames() { |
| 888 std::vector<string16> names; | 958 std::vector<string16> names; |
| 889 PrefService* local_state = g_browser_process->local_state(); | 959 PrefService* local_state = g_browser_process->local_state(); |
| 890 const DictionaryValue* cache = local_state->GetDictionary( | 960 const DictionaryValue* cache = local_state->GetDictionary( |
| 891 prefs::kProfileInfoCache); | 961 prefs::kProfileInfoCache); |
| 892 string16 name; | 962 string16 name; |
| 893 for (base::DictionaryValue::Iterator it(*cache); !it.IsAtEnd(); | 963 for (base::DictionaryValue::Iterator it(*cache); !it.IsAtEnd(); |
| 894 it.Advance()) { | 964 it.Advance()) { |
| 895 const base::DictionaryValue* info = NULL; | 965 const base::DictionaryValue* info = NULL; |
| 896 it.value().GetAsDictionary(&info); | 966 it.value().GetAsDictionary(&info); |
| 897 info->GetString(kNameKey, &name); | 967 info->GetString(kNameKey, &name); |
| 898 names.push_back(name); | 968 names.push_back(name); |
| 899 } | 969 } |
| 900 return names; | 970 return names; |
| 901 } | 971 } |
| 902 | 972 |
| 903 // static | 973 // static |
| 904 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { | 974 void ProfileInfoCache::RegisterPrefs(PrefRegistrySimple* registry) { |
| 905 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); | 975 registry->RegisterDictionaryPref(prefs::kProfileInfoCache); |
| 906 } | 976 } |
| OLD | NEW |