blob: f4ed02b8c651820a92a02235a8ac0ab0e4c66d04 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_
#define CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_
#pragma once
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/string16.h"
namespace gfx {
class Image;
}
class DictionaryValue;
class PrefService;
// This class saves various information about profiles to local preferences.
// This cache can be used to display a list of profiles without having to
// actually load the profiles from disk.
class ProfileInfoCache {
public:
ProfileInfoCache(PrefService* prefs, const FilePath& user_data_dir);
~ProfileInfoCache();
void AddProfileToCache(const FilePath& profile_path,
const string16& name,
size_t icon_index);
void DeleteProfileFromCache(const FilePath& profile_path);
size_t GetNumberOfProfiles() const;
size_t GetIndexOfProfileWithPath(const FilePath& profile_path) const;
string16 GetNameOfProfileAtIndex(size_t index) const;
FilePath GetPathOfProfileAtIndex(size_t index) const;
const gfx::Image& GetAvatarIconOfProfileAtIndex(size_t index) const;
size_t GetAvatarIconIndexOfProfileAtIndex(size_t index) const;
void SetNameOfProfileAtIndex(size_t index, const string16& name);
void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index);
// Returns unique name that can be assigned to a newly created profile.
string16 ChooseNameForNewProfile();
// Returns an avatar icon index that can be assigned to a newly created
// profile. Note that the icon may not be unique since there are a limited
// set of default icons.
int ChooseAvatarIconIndexForNewProfile();
const FilePath& GetUserDataDir() const;
// Gets the number of default avatar icons that exist.
static size_t GetDefaultAvatarIconCount();
// Gets the resource ID of the default avatar icon at |index|.
static int GetDefaultAvatarIconResourceIDAtIndex(size_t index);
// Returns a URL for the default avatar icon with specified index.
static std::string GetDefaultAvatarIconUrl(size_t index);
// Register cache related preferences in Local State.
static void RegisterPrefs(PrefService* prefs);
private:
const DictionaryValue* GetInfoForProfileAtIndex(size_t index) const;
// Saves the profile info to a cache and takes ownership of |info|.
// Currently the only information that is cached is the profiles name and
// avatar icon.
void SetInfoForProfileAtIndex(size_t index, DictionaryValue* info);
std::string CacheKeyFromProfilePath(const FilePath& profile_path) const;
std::vector<std::string>::iterator FindPositionForProfile(
std::string search_key,
const string16& search_name);
PrefService* prefs_;
std::vector<std::string> sorted_keys_;
FilePath user_data_dir_;
DISALLOW_COPY_AND_ASSIGN(ProfileInfoCache);
};
#endif // CHROME_BROWSER_PROFILES_PROFILE_INFO_CACHE_H_
|