OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef IOS_CHROME_BROWSER_BROWSER_STATE_BROWSER_STATE_INFO_CACHE_H_ | 5 #ifndef IOS_CHROME_BROWSER_BROWSER_STATE_BROWSER_STATE_INFO_CACHE_H_ |
6 #define IOS_CHROME_BROWSER_BROWSER_STATE_BROWSER_STATE_INFO_CACHE_H_ | 6 #define IOS_CHROME_BROWSER_BROWSER_STATE_BROWSER_STATE_INFO_CACHE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 // This class saves various information about browser states to local | 24 // This class saves various information about browser states to local |
25 // preferences. | 25 // preferences. |
26 class BrowserStateInfoCache { | 26 class BrowserStateInfoCache { |
27 public: | 27 public: |
28 BrowserStateInfoCache(PrefService* prefs, | 28 BrowserStateInfoCache(PrefService* prefs, |
29 const base::FilePath& user_data_dir); | 29 const base::FilePath& user_data_dir); |
30 virtual ~BrowserStateInfoCache(); | 30 virtual ~BrowserStateInfoCache(); |
31 | 31 |
32 void AddBrowserState(const base::FilePath& browser_state_path, | 32 void AddBrowserState(const base::FilePath& browser_state_path, |
33 const base::string16& name, | |
34 const std::string& gaia_id, | 33 const std::string& gaia_id, |
35 const base::string16& user_name); | 34 const base::string16& user_name); |
36 void RemoveBrowserState(const base::FilePath& browser_state_path); | 35 void RemoveBrowserState(const base::FilePath& browser_state_path); |
37 | 36 |
38 // Returns the count of known browser states. | 37 // Returns the count of known browser states. |
39 size_t GetNumberOfBrowserStates() const; | 38 size_t GetNumberOfBrowserStates() const; |
40 | 39 |
41 // Adds and removes an observer. | 40 // Adds and removes an observer. |
42 void AddObserver(BrowserStateInfoCacheObserver* observer); | 41 void AddObserver(BrowserStateInfoCacheObserver* observer); |
43 void RemoveObserver(BrowserStateInfoCacheObserver* observer); | 42 void RemoveObserver(BrowserStateInfoCacheObserver* observer); |
44 | 43 |
45 // Gets and sets information related to browser states. | 44 // Gets and sets information related to browser states. |
46 size_t GetIndexOfBrowserStateWithPath( | 45 size_t GetIndexOfBrowserStateWithPath( |
47 const base::FilePath& browser_state_path) const; | 46 const base::FilePath& browser_state_path) const; |
48 base::string16 GetNameOfBrowserStateAtIndex(size_t index) const; | |
49 base::string16 GetUserNameOfBrowserStateAtIndex(size_t index) const; | 47 base::string16 GetUserNameOfBrowserStateAtIndex(size_t index) const; |
50 base::FilePath GetPathOfBrowserStateAtIndex(size_t index) const; | 48 base::FilePath GetPathOfBrowserStateAtIndex(size_t index) const; |
51 std::string GetGAIAIdOfBrowserStateAtIndex(size_t index) const; | 49 std::string GetGAIAIdOfBrowserStateAtIndex(size_t index) const; |
52 bool BrowserStateIsAuthenticatedAtIndex(size_t index) const; | 50 bool BrowserStateIsAuthenticatedAtIndex(size_t index) const; |
53 void SetAuthInfoOfBrowserStateAtIndex(size_t index, | 51 void SetAuthInfoOfBrowserStateAtIndex(size_t index, |
54 const std::string& gaia_id, | 52 const std::string& gaia_id, |
55 const base::string16& user_name); | 53 const base::string16& user_name); |
56 void SetBrowserStateIsAuthErrorAtIndex(size_t index, bool value); | 54 void SetBrowserStateIsAuthErrorAtIndex(size_t index, bool value); |
57 bool BrowserStateIsAuthErrorAtIndex(size_t index) const; | 55 bool BrowserStateIsAuthErrorAtIndex(size_t index) const; |
58 | 56 |
59 const base::FilePath& GetUserDataDir() const; | 57 const base::FilePath& GetUserDataDir() const; |
60 | 58 |
61 // Register cache related preferences in Local State. | 59 // Register cache related preferences in Local State. |
62 static void RegisterPrefs(PrefRegistrySimple* registry); | 60 static void RegisterPrefs(PrefRegistrySimple* registry); |
63 | 61 |
64 private: | 62 private: |
65 const base::DictionaryValue* GetInfoForBrowserStateAtIndex( | 63 const base::DictionaryValue* GetInfoForBrowserStateAtIndex( |
66 size_t index) const; | 64 size_t index) const; |
67 // Saves the browser state info to a cache and takes ownership of |info|. | 65 // Saves the browser state info to a cache and takes ownership of |info|. |
68 void SetInfoForBrowserStateAtIndex(size_t index, base::DictionaryValue* info); | 66 void SetInfoForBrowserStateAtIndex(size_t index, base::DictionaryValue* info); |
69 | 67 |
70 std::string CacheKeyFromBrowserStatePath( | 68 std::string CacheKeyFromBrowserStatePath( |
71 const base::FilePath& browser_state_path) const; | 69 const base::FilePath& browser_state_path) const; |
72 std::vector<std::string>::iterator FindPositionForBrowserState( | 70 void AddBrowserStateCacheKey(const std::string& key); |
73 const std::string& search_key, | |
74 const base::string16& search_name); | |
75 | 71 |
76 PrefService* prefs_; | 72 PrefService* prefs_; |
77 std::vector<std::string> sorted_keys_; | 73 std::vector<std::string> sorted_keys_; |
78 base::FilePath user_data_dir_; | 74 base::FilePath user_data_dir_; |
79 base::ObserverList<BrowserStateInfoCacheObserver, true> observer_list_; | 75 base::ObserverList<BrowserStateInfoCacheObserver, true> observer_list_; |
80 | 76 |
81 DISALLOW_COPY_AND_ASSIGN(BrowserStateInfoCache); | 77 DISALLOW_COPY_AND_ASSIGN(BrowserStateInfoCache); |
82 }; | 78 }; |
83 | 79 |
84 #endif // IOS_CHROME_BROWSER_BROWSER_STATE_BROWSER_STATE_INFO_CACHE_H_ | 80 #endif // IOS_CHROME_BROWSER_BROWSER_STATE_BROWSER_STATE_INFO_CACHE_H_ |
OLD | NEW |