Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: content/browser/media_gallery/media_gallery_database.h

Issue 9567035: Added MediaGalleryDatabase (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Minor cleanups Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/common/content_export.h"
12 #include "sql/connection.h"
13 #include "sql/init_status.h"
14 #include "sql/meta_table.h"
15
16 namespace media_gallery {
17
18 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.
19
20 class CONTENT_EXPORT MediaGalleryDatabase {
21 public:
22 MediaGalleryDatabase();
23 virtual ~MediaGalleryDatabase();
24
25 // Must call this function to complete initialization. Will return true on
26 // success. On false, no other function should be called.
27 sql::InitStatus Init(const FilePath& database_path);
28
29 // Returns the current version that we will generate history databases with.
30 static int GetCurrentVersion();
31
32 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
33 public:
34 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.
35 CollectionRow(FilePath path,
36 base::Time last_modified_time,
37 int entry_count,
38 bool all_parsed)
39 : path_(path),
40 last_modified_time_(last_modified_time),
41 entry_count_(entry_count),
42 all_parsed_(all_parsed) { }
43 virtual ~CollectionRow() { }
vandebo (ex-Chrome) 2012/03/05 23:16:03 And the destructor.
tpayne 2012/03/06 01:52:37 Done.
44 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
45 const FilePath& GetPath() const { return path_; }
46 const base::Time& GetLastModifiedTime() const {
47 return last_modified_time_;
48 }
49 int GetEntryCount() const { return entry_count_; }
50 bool IsAllParsed() const { return all_parsed_; }
51 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.
52 return id_ == row2.id_
53 && path_ == row2.path_
54 && last_modified_time_ == row2.last_modified_time_
55 && entry_count_ == row2.entry_count_
56 && all_parsed_ == row2.all_parsed_;
57 }
58
59 private:
60 friend class MediaGalleryDatabase;
61 COLLECTIONID id_;
62 FilePath path_;
63 base::Time last_modified_time_;
64 int entry_count_;
65 bool all_parsed_;
66 };
Lei Zhang 2012/03/05 23:38:36 missed a DISALLOW_COPY_AND_ASSIGN here.
tpayne 2012/03/06 01:52:37 Done.
67
68 // Sets the id_ field of the input collection_row to the generated unique
69 // key value and returns the same. On failure, returns zero.
70 int CreateCollectionRow(CollectionRow* collection_row);
71
72 // Finds the row with the specified id and fills its data into the collection
73 // pointer passed by the caller. Returns true on success.
74 bool GetCollectionRow(COLLECTIONID id, CollectionRow* collection);
75
76 protected:
77 virtual sql::Connection& GetDB() {
78 return db_;
79 }
80
81 // Initializes an already open database.
82 sql::InitStatus InitInternal(sql::Connection* db);
83
84 private:
85 sql::Connection db_;
86 sql::MetaTable meta_table_;
87 bool CreateCollectionsTable(sql::Connection* db);
88 sql::InitStatus EnsureCurrentVersion();
89 void FillCollectionRow(const sql::Statement& s, CollectionRow* i);
90
91 DISALLOW_COPY_AND_ASSIGN(MediaGalleryDatabase);
92 };
93
94 } // namespace media_gallery
95
96 std::ostream& operator<<(std::ostream& out,
97 const media_gallery::MediaGalleryDatabase::CollectionRow& row);
98
99 #endif // CONTENT_BROWSER_MEDIA_GALLERY_MEDIA_GALLERY_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698