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_CHROMEOS_GDATA_GDATA_DB_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DB_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/memory/scoped_ptr.h" | |
11 | |
12 class FilePath; | |
13 | |
14 namespace gdata { | |
15 | |
16 class GDataEntry; | |
17 class GDataDBIter; | |
18 | |
19 // GData Database interface class. | |
20 class GDataDB { | |
21 public: | |
22 enum Status { | |
23 DB_OK = 0, | |
24 DB_KEY_NOT_FOUND, // Key not found. | |
25 DB_CORRUPTION, // Database file corrupt. | |
26 DB_IO_ERROR, // File I/O error. | |
27 DB_INTERNAL_ERROR, | |
28 }; | |
29 | |
30 virtual ~GDataDB() {} | |
31 | |
32 // Puts |entry| to the database. | |
33 virtual Status Put(const GDataEntry& entry) = 0; | |
34 | |
35 // Deletes a database entry with key |resource_id| or |path| respectively. | |
36 virtual Status DeleteByResourceId(const std::string& resource_id) = 0; | |
37 virtual Status DeleteByPath(const FilePath& path) = 0; | |
38 | |
39 // Fetches a GDataEntry* by key |resource_id| or |path| respectively. | |
40 virtual Status GetByResourceId(const std::string& resource_id, | |
41 scoped_ptr<GDataEntry>* entry) = 0; | |
42 virtual Status GetByPath(const FilePath& path, | |
43 scoped_ptr<GDataEntry>* entry) = 0; | |
44 | |
45 // Creates an iterator to fetch all GDataEntry's under |path|. | |
46 // Will not return NULL. | |
47 virtual scoped_ptr<GDataDBIter> CreateIterator(const FilePath& path) = 0; | |
48 | |
49 // Puts |raw_value| keyed with |resource_id| to the database. | |
50 // Used for testing (ex. injecting incompatible proto). | |
51 virtual Status PutRawForTesting(const std::string& resource_id, | |
52 const std::string& raw_value) = 0; | |
53 | |
54 protected: | |
55 GDataDB() {} | |
56 }; | |
57 | |
58 // GData Database Iterator interface class. | |
59 class GDataDBIter { | |
60 public: | |
61 virtual ~GDataDBIter() {} | |
62 | |
63 // Fetches the next |entry| in the iteration sequence. Returns false when | |
64 // there are no more entries. | |
65 virtual bool GetNext(std::string* path, scoped_ptr<GDataEntry>* entry) = 0; | |
66 | |
67 protected: | |
68 GDataDBIter() {} | |
69 }; | |
70 | |
71 } // namespace gdata | |
72 | |
73 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DB_H_ | |
OLD | NEW |