sbLocalDatabaseLibraryLoader.h
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25 */
26 
27 #ifndef __SB_LOCALDATABASELIBRARYLOADER_H__
28 #define __SB_LOCALDATABASELIBRARYLOADER_H__
29 
30 #include <sbILibraryLoader.h>
31 
32 #include <nsClassHashtable.h>
33 #include <nsHashKeys.h>
34 #include <nsIObserver.h>
35 #include <nsIPrefBranch.h>
36 #include <nsStringGlue.h>
37 
38 class nsIComponentManager;
39 class nsIFile;
40 class nsILocalFile;
41 class nsIPrefService;
42 class sbILibraryManager;
45 
46 struct nsModuleComponentInfo;
47 
49  public nsIObserver
50 {
51  struct sbLoaderInfo
52  {
53  sbLoaderInfo(sbILibraryManager* aLibraryManager,
54  sbLocalDatabaseLibraryFactory* aLibraryFactory)
55  : libraryManager(aLibraryManager),
56  libraryFactory(aLibraryFactory)
57  { }
58 
60  sbLocalDatabaseLibraryFactory* libraryFactory;
61  };
62 
63  struct sbLibraryExistsInfo
64  {
65  sbLibraryExistsInfo(const nsAString& aResourceGUID)
66  : resourceGUID(aResourceGUID),
67  index(-1)
68  { }
69 
70  nsString resourceGUID;
71  PRInt32 index;
72  };
73 
74 public:
76  NS_DECL_SBILIBRARYLOADER
77  NS_DECL_NSIOBSERVER
78 
80 
81  nsresult Init();
82 
83 private:
84  ~sbLocalDatabaseLibraryLoader();
85 
86  nsresult LoadLibraries();
87 
88  nsresult EnsureDefaultLibraries();
89 
90  nsresult EnsureDefaultLibrary(const nsACString& aLibraryGUIDPref,
91  const nsAString& aDefaultDatabaseGUID,
92  const nsAString& aLibraryNameKey,
93  const nsAString& aCustomType,
94  const nsAString& aDefaultColumnSpec);
95 
97  CreateDefaultLibraryInfo(const nsACString& aPrefKey,
98  const nsAString& aDatabaseGUID = EmptyString(),
99  nsILocalFile* aDatabaseFile = nsnull,
100  const nsAString& aLibraryNameKey = EmptyString());
101 
102  NS_METHOD PromptToDeleteLibraries();
103  NS_METHOD PromptInaccessibleLibraries();
104 
105  PRUint32 GetNextLibraryIndex();
106 
107  static void RemovePrefBranch(const nsACString& aPrefBranch);
108 
109  static PLDHashOperator PR_CALLBACK
110  LoadLibrariesCallback(nsUint32HashKey::KeyType aKey,
111  sbLibraryLoaderInfo* aEntry,
112  void* aUserData);
113 
114  static PLDHashOperator PR_CALLBACK
115  LibraryExistsCallback(nsUint32HashKey::KeyType aKey,
116  sbLibraryLoaderInfo* aEntry,
117  void* aUserData);
118 
119  static PLDHashOperator PR_CALLBACK
120  VerifyEntriesCallback(nsUint32HashKey::KeyType aKey,
121  nsAutoPtr<sbLibraryLoaderInfo>& aEntry,
122  void* aUserData);
123 
124  PRBool m_DetectedCorruptLibrary;
125  PRBool m_DeleteLibrariesAtShutdown;
126 
127 private:
128  nsClassHashtable<nsUint32HashKey, sbLibraryLoaderInfo> mLibraryInfoTable;
129  nsCOMPtr<nsIPrefBranch> mRootBranch;
130 };
131 
132 
133 
135 {
136 public:
138 
139  nsresult Init(const nsACString& aPrefKey);
140 
141  nsresult SetDatabaseGUID(const nsAString& aGUID);
142  void GetDatabaseGUID(nsAString& _retval);
143 
144  nsresult SetDatabaseLocation(nsILocalFile* aLocation);
145  already_AddRefed<nsILocalFile> GetDatabaseLocation();
146 
147  nsresult SetLoadAtStartup(PRBool aLoadAtStartup);
148  PRBool GetLoadAtStartup();
149 
150  nsresult SetResourceGUID(const nsAString& aGUID);
151  void GetResourceGUID(nsAString& _retval);
152 
153  void GetPrefBranch(nsACString& _retval);
154 
155 private:
156  nsCOMPtr<nsIPrefBranch> mPrefBranch;
157 
158  // XXXben If you add additional values to this class please remember to
159  // update LOADERINFO_VALUE_COUNT in sbLocalDatabaseLibraryLoader.cpp
160  nsCString mDatabaseGUIDKey;
161  nsCString mLocationKey;
162  nsCString mStartupKey;
163  nsCString mResourceGUIDKey;
164 };
165 
166 #endif /* __SB_LOCALDATABASELIBRARYLOADER_H__ */
nsresult Init(const nsACString &aPrefKey)
already_AddRefed< nsILocalFile > GetDatabaseLocation()
nsresult SetLoadAtStartup(PRBool aLoadAtStartup)
Manages the lifecycle of libraries in the system.
var libraryManager
nsresult SetDatabaseLocation(nsILocalFile *aLocation)
void GetPrefBranch(nsACString &_retval)
void GetResourceGUID(nsAString &_retval)
[USER CODE SHOULD NOT REFERENCE THIS CLASS]
void GetDatabaseGUID(nsAString &_retval)
nsresult SetDatabaseGUID(const nsAString &aGUID)
nsresult SetResourceGUID(const nsAString &aGUID)
NS_DECL_ISUPPORTS NS_DECL_SBILIBRARYLOADER NS_DECL_NSIOBSERVER sbLocalDatabaseLibraryLoader()