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

Delta Between Two Patch Sets: compiled/subscription/Subscription.cpp

Issue 29426559: Issue 5137 - [emscripten] Added basic filter storage implementation (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Left Patch Set: Fixed some inconsistencies Created May 3, 2017, 8:25 a.m.
Right Patch Set: Fixed bogus assert Created Aug. 31, 2017, 12:44 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « compiled/subscription/Subscription.h ('k') | compiled/subscription/UserDefinedSubscription.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #include <cstdio> 18 #include <cstdio>
19 #include <cstdlib> 19 #include <cstdlib>
20 20
21 #include "Subscription.h" 21 #include "Subscription.h"
22 #include "DownloadableSubscription.h" 22 #include "DownloadableSubscription.h"
23 #include "UserDefinedSubscription.h" 23 #include "UserDefinedSubscription.h"
24 #include "../StringMap.h" 24 #include "../StringMap.h"
25 25
26 namespace 26 namespace
27 { 27 {
28 StringMap<Subscription*> knownSubscriptions(16); 28 StringMap<Subscription*> knownSubscriptions(16);
29 } 29 }
30 30
31 class DownloadableSubscription;
32 class UserDefinedSubscription;
33
34 Subscription::Subscription(Type type, const String& id) 31 Subscription::Subscription(Type type, const String& id)
35 : mID(id), mType(type), mDisabled(false) 32 : mID(id), mType(type), mDisabled(false)
36 { 33 {
37 annotate_address(this, "Subscription"); 34 annotate_address(this, "Subscription");
38 } 35 }
39 36
40 Subscription::~Subscription() 37 Subscription::~Subscription()
41 { 38 {
42 knownSubscriptions.erase(mID); 39 knownSubscriptions.erase(mID);
43 } 40 }
44 41
45 Filter* Subscription::FilterAt(unsigned index) 42 Filter* Subscription::FilterAt(Subscription::Filters::size_type index)
46 { 43 {
47 if (index >= mFilters.size()) 44 if (index >= mFilters.size())
48 return nullptr; 45 return nullptr;
49 46
50 FilterPtr result(mFilters[index]); 47 FilterPtr result(mFilters[index]);
51 return result.release(); 48 return result.release();
52 } 49 }
53 50
54 int Subscription::IndexOfFilter(Filter* filter) 51 int Subscription::IndexOfFilter(Filter* filter)
55 { 52 {
56 for (unsigned i = 0; i < mFilters.size(); i++) 53 for (Filters::size_type i = 0; i < mFilters.size(); i++)
57 if (mFilters[i] == filter) 54 if (mFilters[i] == filter)
58 return i; 55 return i;
59 return -1; 56 return -1;
60 } 57 }
61 58
62 OwnedString Subscription::Serialize() const 59 OwnedString Subscription::Serialize() const
63 { 60 {
64 OwnedString result(u"[Subscription]\nurl="_str); 61 OwnedString result(u"[Subscription]\nurl="_str);
65 result.append(mID); 62 result.append(mID);
66 result.append(u'\n'); 63 result.append(u'\n');
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 122
126 // This is a hack: we looked up the entry using id but create it using 123 // This is a hack: we looked up the entry using id but create it using
127 // subscription->mID. This works because both are equal at this point. 124 // subscription->mID. This works because both are equal at this point.
128 // However, id refers to a temporary buffer which will go away. 125 // However, id refers to a temporary buffer which will go away.
129 enter_context("Adding to known subscriptions"); 126 enter_context("Adding to known subscriptions");
130 knownSubscription.assign(subscription->mID, subscription.get()); 127 knownSubscription.assign(subscription->mID, subscription.get());
131 exit_context(); 128 exit_context();
132 129
133 return subscription.release(); 130 return subscription.release();
134 } 131 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld