OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_ | |
6 #define CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/file_path.h" | |
10 #include "chrome/browser/media_gallery/media_gallery_database_types.h" | |
11 #include "sql/connection.h" | |
12 #include "sql/init_status.h" | |
13 #include "sql/meta_table.h" | |
14 | |
15 namespace chrome { | |
16 | |
17 // Encapsulates the SQL database that stores pre-parsed media gallery metadata | |
18 // for search and retrieval. | |
19 class MediaGalleryDatabase { | |
20 public: | |
21 MediaGalleryDatabase(); | |
22 virtual ~MediaGalleryDatabase(); | |
23 | |
24 // Must call this function to complete initialization. Will return true on | |
25 // success. On false, no other function should be called. | |
26 sql::InitStatus Init(const base::FilePath& database_path); | |
27 | |
28 // Returns the current version that we will generate media gallery databases | |
29 // with. | |
30 static int GetCurrentVersion(); | |
31 | |
32 // Sets the id field of the input collection_row to the generated unique | |
33 // key value and returns the same. On failure, returns zero. | |
34 int CreateCollectionRow(CollectionRow* collection_row); | |
35 | |
36 // Finds the row with the specified id and fills its data into the collection | |
37 // pointer passed by the caller. Returns true on success. | |
38 bool GetCollectionRow(CollectionId id, CollectionRow* collection); | |
39 | |
40 protected: | |
41 virtual sql::Connection& GetDB(); | |
42 | |
43 // Initializes an already open database. | |
44 sql::InitStatus InitInternal(sql::Connection* db); | |
45 static bool DoesCollectionsTableExist(sql::Connection* db); | |
46 | |
47 private: | |
48 static bool CreateCollectionsTable(sql::Connection* db); | |
49 sql::InitStatus EnsureCurrentVersion(); | |
50 void FillCollectionRow(const sql::Statement& statement, CollectionRow* row); | |
51 | |
52 sql::Connection db_; | |
53 sql::MetaTable meta_table_; | |
54 | |
55 DISALLOW_COPY_AND_ASSIGN(MediaGalleryDatabase); | |
56 }; | |
57 | |
58 } // namespace chrome | |
59 | |
60 std::ostream& operator<<(std::ostream& out, const chrome::CollectionRow& row); | |
61 | |
62 #endif // CHROME_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_ | |
OLD | NEW |