Index: content/browser/media_gallery/media_gallery_database.h |
diff --git a/content/browser/media_gallery/media_gallery_database.h b/content/browser/media_gallery/media_gallery_database.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..42032caa3daa85eaa4193991b0e467b7e233e253 |
--- /dev/null |
+++ b/content/browser/media_gallery/media_gallery_database.h |
@@ -0,0 +1,99 @@ |
+// Copyright (c) 2012 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 CONTENT_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_ |
+#define CONTENT_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_ |
+#pragma once |
+ |
+#include "base/basictypes.h" |
+#include "base/file_path.h" |
+#include "content/common/content_export.h" |
+#include "sql/connection.h" |
+#include "sql/init_status.h" |
+#include "sql/meta_table.h" |
+ |
+namespace media_gallery { |
+ |
+typedef int COLLECTIONID; |
vandebo (ex-Chrome)
2012/03/05 23:16:03
Types should be initial cap, camel case.
tpayne
2012/03/06 01:52:37
Done.
|
+ |
+class CONTENT_EXPORT MediaGalleryDatabase { |
+ public: |
+ MediaGalleryDatabase(); |
+ virtual ~MediaGalleryDatabase(); |
+ |
+ // Must call this function to complete initialization. Will return true on |
+ // success. On false, no other function should be called. |
+ sql::InitStatus Init(const FilePath& database_path); |
+ |
+ // Returns the current version that we will generate history databases with. |
+ static int GetCurrentVersion(); |
+ |
+ class CollectionRow { |
tpayne
2012/03/02 01:05:00
I don't know if this class is simple enough to mak
vandebo (ex-Chrome)
2012/03/05 23:16:03
Hard to say at this point, at some level it's a ma
vandebo (ex-Chrome)
2012/03/05 23:16:03
You may want to make this a struct though, dependi
tpayne
2012/03/06 01:52:37
Done.
tpayne
2012/03/06 01:52:37
Since I need to pull out part of the implementatio
|
+ public: |
+ CollectionRow() { } |
vandebo (ex-Chrome)
2012/03/05 23:16:03
Classes with non-trivial fields should not have in
tpayne
2012/03/06 01:52:37
Done.
|
+ CollectionRow(FilePath path, |
+ base::Time last_modified_time, |
+ int entry_count, |
+ bool all_parsed) |
+ : path_(path), |
+ last_modified_time_(last_modified_time), |
+ entry_count_(entry_count), |
+ all_parsed_(all_parsed) { } |
+ virtual ~CollectionRow() { } |
vandebo (ex-Chrome)
2012/03/05 23:16:03
And the destructor.
tpayne
2012/03/06 01:52:37
Done.
|
+ int GetId() const { return id_; } |
vandebo (ex-Chrome)
2012/03/05 23:16:03
Getter/Setters should use unix_hacker_style naming
tpayne
2012/03/06 01:52:37
N/A
|
+ const FilePath& GetPath() const { return path_; } |
+ const base::Time& GetLastModifiedTime() const { |
+ return last_modified_time_; |
+ } |
+ int GetEntryCount() const { return entry_count_; } |
+ bool IsAllParsed() const { return all_parsed_; } |
+ bool operator==(const CollectionRow& row2) const { |
Lei Zhang
2012/03/05 23:38:36
Please try to keep implementation out of headers.
tpayne
2012/03/06 01:52:37
Done.
|
+ return id_ == row2.id_ |
+ && path_ == row2.path_ |
+ && last_modified_time_ == row2.last_modified_time_ |
+ && entry_count_ == row2.entry_count_ |
+ && all_parsed_ == row2.all_parsed_; |
+ } |
+ |
+ private: |
+ friend class MediaGalleryDatabase; |
+ COLLECTIONID id_; |
+ FilePath path_; |
+ base::Time last_modified_time_; |
+ int entry_count_; |
+ bool all_parsed_; |
+ }; |
Lei Zhang
2012/03/05 23:38:36
missed a DISALLOW_COPY_AND_ASSIGN here.
tpayne
2012/03/06 01:52:37
Done.
|
+ |
+ // Sets the id_ field of the input collection_row to the generated unique |
+ // key value and returns the same. On failure, returns zero. |
+ int CreateCollectionRow(CollectionRow* collection_row); |
+ |
+ // Finds the row with the specified id and fills its data into the collection |
+ // pointer passed by the caller. Returns true on success. |
+ bool GetCollectionRow(COLLECTIONID id, CollectionRow* collection); |
+ |
+ protected: |
+ virtual sql::Connection& GetDB() { |
+ return db_; |
+ } |
+ |
+ // Initializes an already open database. |
+ sql::InitStatus InitInternal(sql::Connection* db); |
+ |
+ private: |
+ sql::Connection db_; |
+ sql::MetaTable meta_table_; |
+ bool CreateCollectionsTable(sql::Connection* db); |
+ sql::InitStatus EnsureCurrentVersion(); |
+ void FillCollectionRow(const sql::Statement& s, CollectionRow* i); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(MediaGalleryDatabase); |
+}; |
+ |
+} // namespace media_gallery |
+ |
+std::ostream& operator<<(std::ostream& out, |
+ const media_gallery::MediaGalleryDatabase::CollectionRow& row); |
+ |
+#endif // CONTENT_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_ |