Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/ReferrerMapping.cpp

Issue 6307944991817728: Issue 984 - port referrer mapping from Android (Closed)
Patch Set: Created July 16, 2014, 10:14 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « libadblockplus.gyp ('k') | test/ReferrerMapping.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <AdblockPlus/ReferrerMapping.h>
19
20 using namespace AdblockPlus;
21
22 ReferrerMapping::ReferrerMapping(const int maxCachedUrls)
23 : maxCachedUrls(maxCachedUrls)
24 {
25 }
26
27 void ReferrerMapping::Add(const std::string& url, const std::string& referrer)
28 {
29 mapping[url] = referrer;
30 if (std::find(cachedUrls.begin(), cachedUrls.end(), url) != cachedUrls.end())
31 cachedUrls.remove(url);
32 cachedUrls.push_back(url);
33 const int urlsToPop = cachedUrls.size() - maxCachedUrls;
Wladimir Palant 2014/07/16 10:23:24 Nit: add an empty line before this one to indicate
Felix Dahlke 2014/07/16 10:34:24 Done.
34 for (int i = 0; i < urlsToPop; i++)
35 {
36 const std::string poppedUrl = cachedUrls.front();
37 cachedUrls.pop_front();
38 mapping.erase(poppedUrl);
39 }
40 }
41
42 std::vector<std::string> ReferrerMapping::BuildReferrerChain(
43 const std::string& url) const
44 {
45 std::vector<std::string> referrerChain;
46 referrerChain.push_back(url);
47 // We need to limit the chain length to ensure we don't block indefinitely
48 // if there's a referrer loop.
49 const int maxChainLength = 10;
50 std::map<std::string, std::string>::const_iterator currentEntry =
51 mapping.find(url);
52 for (int i = 0; i < maxChainLength && currentEntry != mapping.end(); i++)
53 {
54 const std::string& currentUrl = currentEntry->second;
55 referrerChain.insert(referrerChain.begin(), currentUrl);
56 currentEntry = mapping.find(currentUrl);
57 }
58 return referrerChain;
59 }
OLDNEW
« no previous file with comments | « libadblockplus.gyp ('k') | test/ReferrerMapping.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld