OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_DB_H_ | 5 #ifndef CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_DB_H_ |
6 #define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_DB_H_ | 6 #define CHROME_BROWSER_PRIVACY_BLACKLIST_BLACKLIST_DB_H_ |
7 | 7 |
8 #include <cstdio> | 8 #include <cstdio> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 | 13 |
14 class FilePath; | 14 class FilePath; |
15 | 15 |
16 // TODO(idanan): Error handling needed. I/O errors can always happen! | |
17 | |
18 //////////////////////////////////////////////////////////////////////////////// | 16 //////////////////////////////////////////////////////////////////////////////// |
19 // | 17 // |
20 // Blacklist Binary Storage Output Class | 18 // Blacklist Binary Storage Output Class |
21 // | 19 // |
22 // Stores aggregate Privacy Blacklists efficiently on disk. The public | 20 // Stores aggregate Privacy Blacklists efficiently on disk. The public |
23 // functions below must be called in the order they are declared, as | 21 // functions below must be called in the order they are declared, as |
24 // the input class is expected to read them in that order. The provider | 22 // the input class is expected to read them in that order. The provider |
25 // and entry output functions must be called the number of times set. | 23 // and entry output functions must be called the number of times set. |
26 // | 24 // |
27 //////////////////////////////////////////////////////////////////////////////// | 25 //////////////////////////////////////////////////////////////////////////////// |
28 class BlacklistStoreOutput { | 26 class BlacklistStoreOutput { |
29 public: | 27 public: |
30 explicit BlacklistStoreOutput(FILE* file); | 28 explicit BlacklistStoreOutput(FILE* file); |
31 ~BlacklistStoreOutput(); | 29 ~BlacklistStoreOutput(); |
32 | 30 |
33 // Sets the number of providers stored. | 31 // Returns true if the object initialized without error. |
34 void ReserveProviders(uint32); | 32 bool is_good() const { return is_good_; } |
35 | 33 |
36 // Stores a provider. | 34 // Sets the number of providers stored. Returns true if successful. |
37 void StoreProvider(const std::string& name, const std::string& url); | 35 bool ReserveProviders(uint32); |
38 | 36 |
39 // Sets the number of entries stored. | 37 // Stores a provider. Returns true if successful. |
40 void ReserveEntries(uint32); | 38 bool StoreProvider(const std::string& name, const std::string& url); |
41 | 39 |
42 // Stores an entry. | 40 // Sets the number of entries stored. Returns true if successful. |
43 void StoreEntry(const std::string& pattern, | 41 bool ReserveEntries(uint32); |
| 42 |
| 43 // Stores an entry. Returns true if successful. |
| 44 bool StoreEntry(const std::string& pattern, |
44 uint32 attributes, | 45 uint32 attributes, |
45 const std::vector<std::string>& types, | 46 const std::vector<std::string>& types, |
46 uint32 provider); | 47 uint32 provider); |
47 | 48 |
48 private: | 49 private: |
49 // Writes basic types to the stream. | 50 // Writes basic types to the stream. Returns true if successful. |
50 void WriteUInt(uint32); | 51 bool WriteUInt(uint32); |
51 void WriteString(const std::string&); | 52 bool WriteString(const std::string&); |
52 | 53 |
53 FILE* file_; | 54 FILE* file_; |
| 55 bool is_good_; |
54 DISALLOW_COPY_AND_ASSIGN(BlacklistStoreOutput); | 56 DISALLOW_COPY_AND_ASSIGN(BlacklistStoreOutput); |
55 }; | 57 }; |
56 | 58 |
57 //////////////////////////////////////////////////////////////////////////////// | 59 //////////////////////////////////////////////////////////////////////////////// |
58 // | 60 // |
59 // Blacklist Binary Storage Input Class | 61 // Blacklist Binary Storage Input Class |
60 // | 62 // |
61 // Stores aggregate Privacy Blacklists efficiently on disk. The public | 63 // Stores aggregate Privacy Blacklists efficiently on disk. The public |
62 // functions below must be called in the order they are declared, as | 64 // functions below must be called in the order they are declared, as |
63 // the output class is expected to write them in that order. The provider | 65 // the output class is expected to write them in that order. The provider |
64 // entries read functions must be called the correct number of times. | 66 // entries read functions must be called the correct number of times. |
65 // | 67 // |
66 //////////////////////////////////////////////////////////////////////////////// | 68 //////////////////////////////////////////////////////////////////////////////// |
67 class BlacklistStoreInput { | 69 class BlacklistStoreInput { |
68 public: | 70 public: |
69 explicit BlacklistStoreInput(FILE* file); | 71 explicit BlacklistStoreInput(FILE* file); |
70 ~BlacklistStoreInput(); | 72 ~BlacklistStoreInput(); |
71 | 73 |
| 74 // Returns true if this object initialized without error. |
| 75 bool is_good() const { return is_good_; } |
| 76 |
72 // Reads the number of providers. | 77 // Reads the number of providers. |
73 uint32 ReadNumProviders(); | 78 uint32 ReadNumProviders(); |
74 | 79 |
75 // Reads a provider. | 80 // Reads a provider. Returns true on success. |
76 void ReadProvider(std::string* name, std::string* url); | 81 bool ReadProvider(std::string* name, std::string* url); |
77 | 82 |
78 // Reads the number of entries. | 83 // Reads the number of entries. Returns true on success. |
79 uint32 ReadNumEntries(); | 84 uint32 ReadNumEntries(); |
80 | 85 |
81 // Reads an entry. | 86 // Reads an entry. |
82 void ReadEntry(std::string* pattern, | 87 bool ReadEntry(std::string* pattern, |
83 uint32* attributes, | 88 uint32* attributes, |
84 std::vector<std::string>* types, | 89 std::vector<std::string>* types, |
85 uint32* provider); | 90 uint32* provider); |
86 | 91 |
87 private: | 92 private: |
88 uint32 ReadUInt(); | 93 uint32 ReadUInt(); |
89 std::string ReadString(); | 94 std::string ReadString(); |
90 | 95 |
91 FILE* file_; | 96 FILE* file_; |
| 97 bool is_good_; |
92 DISALLOW_COPY_AND_ASSIGN(BlacklistStoreInput); | 98 DISALLOW_COPY_AND_ASSIGN(BlacklistStoreInput); |
93 }; | 99 }; |
94 | 100 |
95 #endif | 101 #endif |
OLD | NEW |