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

Side by Side Diff: chrome/browser/safe_browsing/safe_browsing_util.h

Issue 1410343012: Revert of Move more declarations from c/b/sb/sb_util.h to components. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@01_components
Patch Set: Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 // Utilities for the SafeBrowsing code. 5 // Utilities for the SafeBrowsing code.
6 6
7 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_ 7 #ifndef CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
8 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_ 8 #define CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
9 9
10 #include <cstring> 10 #include <cstring>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/strings/string_piece.h" 16 #include "base/strings/string_piece.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "chrome/browser/safe_browsing/chunk_range.h" 18 #include "chrome/browser/safe_browsing/chunk_range.h"
19 #include "components/safe_browsing_db/util.h" 19 #include "components/safe_browsing_db/safe_browsing_db_util.h"
20 20
21 namespace safe_browsing { 21 namespace safe_browsing {
22 class ChunkData; 22 class ChunkData;
23 }; 23 };
24 24
25 class GURL;
26
25 // Container for holding a chunk URL and the list it belongs to. 27 // Container for holding a chunk URL and the list it belongs to.
26 struct ChunkUrl { 28 struct ChunkUrl {
27 std::string url; 29 std::string url;
28 std::string list_name; 30 std::string list_name;
29 }; 31 };
30 32
31 // Data for an individual chunk sent from the server. 33 // Data for an individual chunk sent from the server.
32 class SBChunkData { 34 class SBChunkData {
33 public: 35 public:
34 SBChunkData(); 36 SBChunkData();
(...skipping 21 matching lines...) Expand all
56 size_t FullHashCount() const; 58 size_t FullHashCount() const;
57 SBFullHash FullHashAt(size_t i) const; 59 SBFullHash FullHashAt(size_t i) const;
58 60
59 private: 61 private:
60 // Protocol buffer sent from server. 62 // Protocol buffer sent from server.
61 scoped_ptr<safe_browsing::ChunkData> chunk_data_; 63 scoped_ptr<safe_browsing::ChunkData> chunk_data_;
62 64
63 DISALLOW_COPY_AND_ASSIGN(SBChunkData); 65 DISALLOW_COPY_AND_ASSIGN(SBChunkData);
64 }; 66 };
65 67
68 // Used when we get a gethash response.
69 struct SBFullHashResult {
70 SBFullHash hash;
71 // TODO(shess): Refactor to allow ListType here.
72 int list_id;
73 std::string metadata;
74 };
75
76 // Caches individual response from GETHASH request.
77 struct SBCachedFullHashResult {
78 SBCachedFullHashResult();
79 explicit SBCachedFullHashResult(const base::Time& in_expire_after);
80 ~SBCachedFullHashResult();
81
82 base::Time expire_after;
83 std::vector<SBFullHashResult> full_hashes;
84 };
85
66 // Contains information about a list in the database. 86 // Contains information about a list in the database.
67 struct SBListChunkRanges { 87 struct SBListChunkRanges {
68 explicit SBListChunkRanges(const std::string& n); 88 explicit SBListChunkRanges(const std::string& n);
69 89
70 std::string name; // The list name. 90 std::string name; // The list name.
71 std::string adds; // The ranges for add chunks. 91 std::string adds; // The ranges for add chunks.
72 std::string subs; // The ranges for sub chunks. 92 std::string subs; // The ranges for sub chunks.
73 }; 93 };
74 94
75 // Container for deleting chunks from the database. 95 // Container for deleting chunks from the database.
76 struct SBChunkDelete { 96 struct SBChunkDelete {
77 SBChunkDelete(); 97 SBChunkDelete();
78 ~SBChunkDelete(); 98 ~SBChunkDelete();
79 99
80 std::string list_name; 100 std::string list_name;
81 bool is_sub_del; 101 bool is_sub_del;
82 std::vector<ChunkRange> chunk_del; 102 std::vector<ChunkRange> chunk_del;
83 }; 103 };
84 104
105 // Utility functions -----------------------------------------------------------
106
107 namespace safe_browsing_util {
108
109 // SafeBrowsing list names.
110 extern const char kMalwareList[];
111 extern const char kPhishingList[];
112 // Binary Download list name.
113 extern const char kBinUrlList[];
114 // SafeBrowsing client-side detection whitelist list name.
115 extern const char kCsdWhiteList[];
116 // SafeBrowsing download whitelist list name.
117 extern const char kDownloadWhiteList[];
118 // SafeBrowsing extension list name.
119 extern const char kExtensionBlacklist[];
120 // SafeBrowsing csd malware IP blacklist name.
121 extern const char kIPBlacklist[];
122 // SafeBrowsing unwanted URL list.
123 extern const char kUnwantedUrlList[];
124 // SafeBrowsing off-domain inclusion whitelist list name.
125 extern const char kInclusionWhitelist[];
126
127 // This array must contain all Safe Browsing lists.
128 extern const char* kAllLists[9];
129
130 enum ListType {
131 INVALID = -1,
132 MALWARE = 0,
133 PHISH = 1,
134 BINURL = 2,
135 // Obsolete BINHASH = 3,
136 CSDWHITELIST = 4,
137 // SafeBrowsing lists are stored in pairs. Keep ListType 5
138 // available for a potential second list that we would store in the
139 // csd-whitelist store file.
140 DOWNLOADWHITELIST = 6,
141 // See above comment. Leave 7 available.
142 EXTENSIONBLACKLIST = 8,
143 // See above comment. Leave 9 available.
144 // Obsolete SIDEEFFECTFREEWHITELIST = 10,
145 // See above comment. Leave 11 available.
146 IPBLACKLIST = 12,
147 // See above comment. Leave 13 available.
148 UNWANTEDURL = 14,
149 // See above comment. Leave 15 available.
150 INCLUSIONWHITELIST = 16,
151 // See above comment. Leave 17 available.
152 };
153
154 // Maps a list name to ListType.
155 ListType GetListId(const base::StringPiece& name);
156
157 // Maps a ListId to list name. Return false if fails.
158 bool GetListName(ListType list_id, std::string* list);
159
160 // Canonicalizes url as per Google Safe Browsing Specification.
161 // See section 6.1 in
162 // http://code.google.com/p/google-safe-browsing/wiki/Protocolv2Spec.
163 void CanonicalizeUrl(const GURL& url, std::string* canonicalized_hostname,
164 std::string* canonicalized_path,
165 std::string* canonicalized_query);
166
167 // Given a URL, returns all the hosts we need to check. They are returned
168 // in order of size (i.e. b.c is first, then a.b.c).
169 void GenerateHostsToCheck(const GURL& url, std::vector<std::string>* hosts);
170
171 // Given a URL, returns all the paths we need to check.
172 void GeneratePathsToCheck(const GURL& url, std::vector<std::string>* paths);
173
174 // Given a URL, returns all the patterns we need to check.
175 void GeneratePatternsToCheck(const GURL& url, std::vector<std::string>* urls);
176
177 SBFullHash StringToSBFullHash(const std::string& hash_in);
178 std::string SBFullHashToString(const SBFullHash& hash_out);
179
180 } // namespace safe_browsing_util
181
85 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_ 182 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/safe_browsing_store_unittest.cc ('k') | chrome/browser/safe_browsing/safe_browsing_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698