Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(539)

Side by Side Diff: chrome/browser/profiles/profile_info_cache.cc

Issue 1214483002: Improve the ProfileInfoCache API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 std::vector<base::FilePath>::const_iterator it; 1231 std::vector<base::FilePath>::const_iterator it;
1232 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) { 1232 for (it = profiles_to_rename.begin(); it != profiles_to_rename.end(); ++it) {
1233 size_t profile_index = GetIndexOfProfileWithPath(*it); 1233 size_t profile_index = GetIndexOfProfileWithPath(*it);
1234 SetProfileIsUsingDefaultNameAtIndex(profile_index, true); 1234 SetProfileIsUsingDefaultNameAtIndex(profile_index, true);
1235 // This will assign a new "Person %d" type name and re-sort the cache. 1235 // This will assign a new "Person %d" type name and re-sort the cache.
1236 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile( 1236 SetNameOfProfileAtIndex(profile_index, ChooseNameForNewProfile(
1237 GetAvatarIconIndexOfProfileAtIndex(profile_index))); 1237 GetAvatarIconIndexOfProfileAtIndex(profile_index)));
1238 } 1238 }
1239 #endif 1239 #endif
1240 } 1240 }
1241
1242 // ProfileMetadataStorage implementation
noms (inactive) 2015/06/29 17:10:39 nit: . at the end?
Mike Lerman 2015/06/29 19:14:37 I didn't think we generally had leading comments l
1243 void ProfileInfoCache::AddProfile(
1244 const base::FilePath& profile_path,
1245 const base::string16& name,
1246 const std::string& gaia_id,
1247 const base::string16& user_name,
1248 size_t icon_index,
1249 const std::string& supervised_user_id) {
1250 AddProfileToCache(
1251 profile_path, name, gaia_id, user_name, icon_index, supervised_user_id);
1252 }
1253 void ProfileInfoCache::DeleteProfile(const base::FilePath& profile_path) {
Mike Lerman 2015/06/29 19:14:37 nit: newline
1254 DeleteProfileFromCache(profile_path);
1255 }
1256
1257 std::vector<ProfileMetadataStorage::ProfileMetadataEntry>
1258 ProfileInfoCache::GetAllProfilesMetadata() {
noms (inactive) 2015/06/29 17:10:40 Yeah, here metadata is even worse (see the other c
anthonyvd 2015/06/30 21:24:52 You're absolutely right. I changed "Metadata" to "
Mike Lerman 2015/07/02 18:01:30 Ok, it makes sense to leave sorting to the callers
1259 std::vector<ProfileMetadataStorage::ProfileMetadataEntry> ret;
1260 for (size_t i = 0; i < GetNumberOfProfiles(); ++i) {
1261 ProfileMetadataStorage::ProfileMetadataEntry entry;
1262 entry.profile_index_ = i;
1263 entry.profile_info_cache_ = this;
1264 ret.push_back(entry);
1265 }
1266 return ret;
1267 }
1268
1269 bool ProfileInfoCache::GetProfileMetadataWithPath(
1270 const base::FilePath& path, ProfileMetadataEntry* entry) {
noms (inactive) 2015/06/29 17:10:39 Idea: Why not return the `entry` (or null if it do
Mike Lerman 2015/06/29 19:14:37 I think the advantage of Anthony's implementation
anthonyvd 2015/06/30 21:24:52 Exactly. The main reason for crashes right now is
1271 if (GetNumberOfProfiles() == 0) {
1272 return false;
1273 }
1274
1275 size_t index = GetIndexOfProfileWithPath(path);
1276 if (index == std::string::npos) {
1277 return false;
1278 }
1279
1280 entry->profile_index_ = index;
noms (inactive) 2015/06/29 17:10:40 Weeeeeeeell if it's a private member, you probably
anthonyvd 2015/06/30 21:24:52 I wanted those to be private with the ProfileInfoC
1281 entry->profile_info_cache_ = this;
1282 return true;
1283 }
1284
1285 // ProfileMetadataEntry implementation
1286 base::string16 ProfileMetadataStorage::ProfileMetadataEntry::GetName() const {
noms (inactive) 2015/06/29 17:10:39 I think this should be in a different file, maybe.
Mike Lerman 2015/06/29 19:14:37 I agree - this seems like the wrong place for this
anthonyvd 2015/06/30 21:24:52 Good point, which kind of ties in to the other com
1287 return profile_info_cache_->GetNameOfProfileAtIndex(profile_index_);
1288 }
1289
1290 base::string16 ProfileMetadataStorage::ProfileMetadataEntry::GetShortcutName()
1291 const {
1292 return profile_info_cache_->GetShortcutNameOfProfileAtIndex(profile_index_);
1293 }
1294
1295 base::FilePath ProfileMetadataStorage::ProfileMetadataEntry::GetPath() const {
1296 return profile_info_cache_->GetPathOfProfileAtIndex(profile_index_);
1297 }
1298
1299 base::Time ProfileMetadataStorage::ProfileMetadataEntry::GetActiveTime() const {
1300 return profile_info_cache_->GetProfileActiveTimeAtIndex(profile_index_);
1301 }
1302
1303 base::string16 ProfileMetadataStorage::ProfileMetadataEntry::GetUserName()
1304 const {
1305 return profile_info_cache_->GetUserNameOfProfileAtIndex(profile_index_);
1306 }
1307
1308 const gfx::Image&
1309 ProfileMetadataStorage::ProfileMetadataEntry::GetAvatarIcon() {
1310 return profile_info_cache_->GetAvatarIconOfProfileAtIndex(profile_index_);
1311 }
1312
1313 std::string
1314 ProfileMetadataStorage::ProfileMetadataEntry::GetLocalAuthCredentials() const {
1315 return profile_info_cache_->GetLocalAuthCredentialsOfProfileAtIndex(
1316 profile_index_);
1317 }
1318
1319 std::string
1320 ProfileMetadataStorage::ProfileMetadataEntry::GetPasswordChangeDetectionToken()
1321 const {
1322 return profile_info_cache_->GetPasswordChangeDetectionTokenAtIndex(
1323 profile_index_);
1324 }
1325
1326 bool ProfileMetadataStorage::ProfileMetadataEntry::GetBackgroundStatus() const {
1327 return profile_info_cache_->GetBackgroundStatusOfProfileAtIndex(
1328 profile_index_);
1329 }
1330
1331 base::string16 ProfileMetadataStorage::ProfileMetadataEntry::GetGAIAName()
1332 const {
1333 return profile_info_cache_->GetGAIANameOfProfileAtIndex(profile_index_);
1334 }
1335
1336 base::string16 ProfileMetadataStorage::ProfileMetadataEntry::GetGAIAGivenName()
1337 const {
1338 return profile_info_cache_->GetGAIAGivenNameOfProfileAtIndex(profile_index_);
1339 }
1340
1341 std::string ProfileMetadataStorage::ProfileMetadataEntry::GetGAIAId() const {
1342 return profile_info_cache_->GetGAIAIdOfProfileAtIndex(profile_index_);
1343 }
1344
1345 const gfx::Image* ProfileMetadataStorage::ProfileMetadataEntry::GetGAIAPicture()
1346 const {
1347 return profile_info_cache_->GetGAIAPictureOfProfileAtIndex(profile_index_);
1348 }
1349
1350 bool ProfileMetadataStorage::ProfileMetadataEntry::IsUsingGAIAPicture()
1351 const {
1352 return profile_info_cache_->IsUsingGAIAPictureOfProfileAtIndex(
1353 profile_index_);
1354 }
1355
1356 bool ProfileMetadataStorage::ProfileMetadataEntry::IsSupervised() const {
1357 return profile_info_cache_->ProfileIsSupervisedAtIndex(profile_index_);
1358 }
1359
1360 bool ProfileMetadataStorage::ProfileMetadataEntry::IsChild() const {
1361 return profile_info_cache_->ProfileIsChildAtIndex(profile_index_);
1362 }
1363
1364 bool ProfileMetadataStorage::ProfileMetadataEntry::IsLegacySupervised()
1365 const {
1366 return profile_info_cache_->ProfileIsLegacySupervisedAtIndex(profile_index_);
1367 }
1368
1369 bool ProfileMetadataStorage::ProfileMetadataEntry::IsOmitted() const {
1370 return profile_info_cache_->IsOmittedProfileAtIndex(profile_index_);
1371 }
1372
1373 bool ProfileMetadataStorage::ProfileMetadataEntry::IsSigninRequired() const {
1374 return profile_info_cache_->ProfileIsSigninRequiredAtIndex(profile_index_);
1375 }
1376
1377 std::string ProfileMetadataStorage::ProfileMetadataEntry::GetSupervisedUserId()
1378 const {
1379 return profile_info_cache_->GetSupervisedUserIdOfProfileAtIndex(
1380 profile_index_);
1381 }
1382
1383 bool ProfileMetadataStorage::ProfileMetadataEntry::IsEphemeral() const {
1384 return profile_info_cache_->ProfileIsEphemeralAtIndex(profile_index_);
1385 }
1386
1387 bool ProfileMetadataStorage::ProfileMetadataEntry::IsUsingDefaultName()
1388 const {
1389 return profile_info_cache_->ProfileIsUsingDefaultNameAtIndex(profile_index_);
1390 }
1391
1392 bool ProfileMetadataStorage::ProfileMetadataEntry::IsAuthenticated() const {
1393 return profile_info_cache_->ProfileIsAuthenticatedAtIndex(profile_index_);
1394 }
1395
1396 bool ProfileMetadataStorage::ProfileMetadataEntry::IsUsingDefaultAvatar()
1397 const {
1398 return profile_info_cache_->ProfileIsUsingDefaultAvatarAtIndex(
1399 profile_index_);
1400 }
1401
1402 bool ProfileMetadataStorage::ProfileMetadataEntry::IsAuthError() const {
1403 return profile_info_cache_->ProfileIsAuthErrorAtIndex(profile_index_);
1404 }
1405
1406 size_t ProfileMetadataStorage::ProfileMetadataEntry::GetAvatarIconIndex()
1407 const {
1408 return profile_info_cache_->GetAvatarIconIndexOfProfileAtIndex(
1409 profile_index_);
1410 }
1411
1412 void ProfileMetadataStorage::ProfileMetadataEntry::SetName(
1413 const base::string16& name) {
1414 profile_info_cache_->SetNameOfProfileAtIndex(profile_index_, name);
1415 }
1416
1417 void ProfileMetadataStorage::ProfileMetadataEntry::SetShortcutName(
1418 const base::string16& name) {
1419 profile_info_cache_->SetShortcutNameOfProfileAtIndex(profile_index_, name);
1420 }
1421
1422 void ProfileMetadataStorage::ProfileMetadataEntry::SetIsOmitted(
1423 bool is_omitted) {
1424 profile_info_cache_->SetIsOmittedProfileAtIndex(profile_index_, is_omitted);
1425 }
1426
1427 void ProfileMetadataStorage::ProfileMetadataEntry::SetSupervisedUserId(
1428 const std::string& id) {
1429 profile_info_cache_->SetSupervisedUserIdOfProfileAtIndex(profile_index_, id);
1430 }
1431
1432 void ProfileMetadataStorage::ProfileMetadataEntry::SetLocalAuthCredentials(
1433 const std::string& auth) {
1434 profile_info_cache_->SetLocalAuthCredentialsOfProfileAtIndex(
1435 profile_index_, auth);
1436 }
1437
1438 void
1439 ProfileMetadataStorage::ProfileMetadataEntry::SetPasswordChangeDetectionToken(
1440 const std::string& token) {
1441 profile_info_cache_->SetPasswordChangeDetectionTokenAtIndex(
1442 profile_index_, token);
1443 }
1444
1445 void ProfileMetadataStorage::ProfileMetadataEntry::SetBackgroundStatus(
1446 bool running_background_apps) {
1447 profile_info_cache_->SetBackgroundStatusOfProfileAtIndex(
1448 profile_index_, running_background_apps);
1449 }
1450
1451 void ProfileMetadataStorage::ProfileMetadataEntry::SetGAIAName(
1452 const base::string16& name) {
1453 profile_info_cache_->SetGAIANameOfProfileAtIndex(profile_index_, name);
1454 }
1455
1456 void ProfileMetadataStorage::ProfileMetadataEntry::SetGAIAGivenName(
1457 const base::string16& name) {
1458 profile_info_cache_->SetGAIAGivenNameOfProfileAtIndex(profile_index_, name);
1459 }
1460
1461 void ProfileMetadataStorage::ProfileMetadataEntry::SetGAIAPicture(
1462 const gfx::Image* image) {
1463 profile_info_cache_->SetGAIAPictureOfProfileAtIndex(profile_index_, image);
1464 }
1465
1466 void ProfileMetadataStorage::ProfileMetadataEntry::SetIsUsingGAIAPicture(
1467 bool value) {
1468 profile_info_cache_->SetIsUsingGAIAPictureOfProfileAtIndex(
1469 profile_index_, value);
1470 }
1471
1472 void ProfileMetadataStorage::ProfileMetadataEntry::SetIsSigninRequired(
1473 bool value) {
1474 profile_info_cache_->SetProfileSigninRequiredAtIndex(profile_index_, value);
1475 }
1476
1477 void ProfileMetadataStorage::ProfileMetadataEntry::SetIsEphemeral(bool value) {
1478 profile_info_cache_->SetProfileIsEphemeralAtIndex(profile_index_, value);
1479 }
1480
1481 void ProfileMetadataStorage::ProfileMetadataEntry::SetIsUsingDefaultName(
1482 bool value) {
1483 profile_info_cache_->SetProfileIsUsingDefaultNameAtIndex(
1484 profile_index_, value);
1485 }
1486
1487 void ProfileMetadataStorage::ProfileMetadataEntry::SetIsUsingDefaultAvatar(
1488 bool value) {
1489 profile_info_cache_->SetProfileIsUsingDefaultAvatarAtIndex(
1490 profile_index_, value);
1491 }
1492
1493 void ProfileMetadataStorage::ProfileMetadataEntry::SetIsAuthError(bool value) {
1494 profile_info_cache_->SetProfileIsAuthErrorAtIndex(profile_index_, value);
1495 }
1496
1497 void ProfileMetadataStorage::ProfileMetadataEntry::SetAvatarIconIndex(
1498 size_t icon_index) {
1499 profile_info_cache_->SetAvatarIconOfProfileAtIndex(
1500 profile_index_, icon_index);
1501 }
1502
1503 void ProfileMetadataStorage::ProfileMetadataEntry::SetAuthInfo(
1504 const std::string& gaia_id, const base::string16& user_name) {
1505 profile_info_cache_->SetAuthInfoOfProfileAtIndex(
1506 profile_index_, gaia_id, user_name);
1507 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698