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

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

Issue 220493003: Safebrowsing: change gethash caching to match api 2.3 rules, fix some corner cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: changes to fullhash / prefix handling Created 6 years, 8 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
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 <deque> 11 #include <deque>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/basictypes.h" 16 #include "base/basictypes.h"
17 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
18 #include "base/time/time.h"
18 #include "chrome/browser/safe_browsing/chunk_range.h" 19 #include "chrome/browser/safe_browsing/chunk_range.h"
19 20
20 class GURL; 21 class GURL;
21 22
22 class SBEntry; 23 class SBEntry;
23 24
24 // A truncated hash's type. 25 // A truncated hash's type.
25 typedef uint32 SBPrefix; 26 typedef uint32 SBPrefix;
26 27
27 // Container for holding a chunk URL and the list it belongs to. 28 // Container for holding a chunk URL and the list it belongs to.
28 struct ChunkUrl { 29 struct ChunkUrl {
29 std::string url; 30 std::string url;
30 std::string list_name; 31 std::string list_name;
31 }; 32 };
32 33
33 // A full hash. 34 // A full hash.
34 union SBFullHash { 35 union SBFullHash {
35 char full_hash[32]; 36 char full_hash[32];
36 SBPrefix prefix; 37 SBPrefix prefix;
37 }; 38 };
38 39
39 inline bool SBFullHashEqual(const SBFullHash& a, const SBFullHash& b) { 40 inline bool SBFullHashEqual(const SBFullHash& a, const SBFullHash& b) {
40 return !memcmp(a.full_hash, b.full_hash, sizeof(a.full_hash)); 41 return !memcmp(a.full_hash, b.full_hash, sizeof(a.full_hash));
41 } 42 }
42 43
44 inline bool SBFullHashLess(const SBFullHash& a, const SBFullHash& b) {
45 return memcmp(a.full_hash, b.full_hash, sizeof(a.full_hash)) < 0;
46 }
47
43 // Generate full hash for the given string. 48 // Generate full hash for the given string.
44 SBFullHash SBFullHashForString(const base::StringPiece& str); 49 SBFullHash SBFullHashForString(const base::StringPiece& str);
45 50
46 // Container for information about a specific host in an add/sub chunk. 51 // Container for information about a specific host in an add/sub chunk.
47 struct SBChunkHost { 52 struct SBChunkHost {
48 SBPrefix host; 53 SBPrefix host;
49 SBEntry* entry; 54 SBEntry* entry;
50 }; 55 };
51 56
52 // Container for an add/sub chunk. 57 // Container for an add/sub chunk.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 private: 104 private:
100 std::vector<SBChunk> chunks_; 105 std::vector<SBChunk> chunks_;
101 106
102 DISALLOW_COPY_AND_ASSIGN(SBChunkList); 107 DISALLOW_COPY_AND_ASSIGN(SBChunkList);
103 }; 108 };
104 109
105 // Used when we get a gethash response. 110 // Used when we get a gethash response.
106 struct SBFullHashResult { 111 struct SBFullHashResult {
107 SBFullHash hash; 112 SBFullHash hash;
108 std::string list_name; 113 std::string list_name;
109 int add_chunk_id; 114 };
115
116 struct SBCachedFullHashResult {
117 SBCachedFullHashResult();
118 explicit SBCachedFullHashResult(const base::Time& in_expire_after);
119 ~SBCachedFullHashResult();
120
121 base::Time expire_after;
122 std::vector<SBFullHashResult> full_hashes;
110 }; 123 };
111 124
112 // Contains information about a list in the database. 125 // Contains information about a list in the database.
113 struct SBListChunkRanges { 126 struct SBListChunkRanges {
114 explicit SBListChunkRanges(const std::string& n); 127 explicit SBListChunkRanges(const std::string& n);
115 128
116 std::string name; // The list name. 129 std::string name; // The list name.
117 std::string adds; // The ranges for add chunks. 130 std::string adds; // The ranges for add chunks.
118 std::string subs; // The ranges for sub chunks. 131 std::string subs; // The ranges for sub chunks.
119 }; 132 };
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 GURL GeneratePhishingReportUrl(const std::string& report_page, 374 GURL GeneratePhishingReportUrl(const std::string& report_page,
362 const std::string& url_to_report, 375 const std::string& url_to_report,
363 bool is_client_side_detection); 376 bool is_client_side_detection);
364 377
365 SBFullHash StringToSBFullHash(const std::string& hash_in); 378 SBFullHash StringToSBFullHash(const std::string& hash_in);
366 std::string SBFullHashToString(const SBFullHash& hash_out); 379 std::string SBFullHashToString(const SBFullHash& hash_out);
367 380
368 } // namespace safe_browsing_util 381 } // namespace safe_browsing_util
369 382
370 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_ 383 #endif // CHROME_BROWSER_SAFE_BROWSING_SAFE_BROWSING_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698