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 CONTENT_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_ |
| 6 #define CONTENT_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/basictypes.h" |
| 10 #include "base/file_path.h" |
| 11 #include "content/browser/media_gallery/media_gallery_types.h" |
| 12 #include "content/common/content_export.h" |
| 13 #include "sql/connection.h" |
| 14 #include "sql/init_status.h" |
| 15 #include "sql/meta_table.h" |
| 16 |
| 17 namespace media_gallery { |
| 18 |
| 19 class CONTENT_EXPORT 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 FilePath& database_path); |
| 27 |
| 28 // Returns the current version that we will generate history databases with. |
| 29 static int GetCurrentVersion(); |
| 30 |
| 31 // Sets the id_ field of the input collection_row to the generated unique |
| 32 // key value and returns the same. On failure, returns zero. |
| 33 int CreateCollectionRow(CollectionRow* collection_row); |
| 34 |
| 35 // Finds the row with the specified id and fills its data into the collection |
| 36 // pointer passed by the caller. Returns true on success. |
| 37 bool GetCollectionRow(CollectionId id, CollectionRow* collection); |
| 38 |
| 39 protected: |
| 40 virtual sql::Connection& GetDB(); |
| 41 |
| 42 // Initializes an already open database. |
| 43 sql::InitStatus InitInternal(sql::Connection* db); |
| 44 static bool DoesCollectionsTableExist(sql::Connection* db); |
| 45 |
| 46 private: |
| 47 sql::Connection db_; |
| 48 sql::MetaTable meta_table_; |
| 49 static bool CreateCollectionsTable(sql::Connection* db); |
| 50 sql::InitStatus EnsureCurrentVersion(); |
| 51 void FillCollectionRow(const sql::Statement& s, CollectionRow* i); |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(MediaGalleryDatabase); |
| 54 }; |
| 55 |
| 56 } // namespace media_gallery |
| 57 |
| 58 std::ostream& operator<<(std::ostream& out, |
| 59 const media_gallery::CollectionRow& row); |
| 60 |
| 61 #endif // CONTENT_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_ |
OLD | NEW |