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

Side by Side Diff: Shared/PluginSettings.cpp

Issue 10580043: Run a single FilterEngine instance in a separate process (Closed)
Patch Set: Addressed review issues Created May 23, 2013, 7:10 p.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 | « Shared/PluginFilter.cpp ('k') | Shared/PluginStdAfx.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include <Wbemidl.h> 3 #include <Wbemidl.h>
4 #include <time.h> 4 #include <time.h>
5 #include "PluginIniFileW.h" 5 #include "PluginIniFileW.h"
6 #include "PluginIniFile.h" 6 #include "PluginIniFile.h"
7 #include "PluginSettings.h" 7 #include "PluginSettings.h"
8 #include "PluginDictionary.h" 8 #include "PluginDictionary.h"
9 #include "PluginClient.h" 9 #include "PluginClient.h"
10 #include "PluginChecksum.h" 10 #include "PluginChecksum.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 s_criticalSectionLocal.Lock(); 201 s_criticalSectionLocal.Lock();
202 { 202 {
203 if ((!s_instance) || (s_isLightOnly)) 203 if ((!s_instance) || (s_isLightOnly))
204 { 204 {
205 s_instance = new CPluginSettings(); 205 s_instance = new CPluginSettings();
206 #ifdef USE_CONSOLE 206 #ifdef USE_CONSOLE
207 CONSOLE("Fetching Available Subscription\n"); 207 CONSOLE("Fetching Available Subscription\n");
208 #endif 208 #endif
209 try 209 try
210 { 210 {
211 CPluginSettings::GetInstance()->m_subscriptions = CPluginClient::GetInst ance()->GetFilterEngine()->FetchAvailableSubscriptions(); 211 CPluginSettings::GetInstance()->m_subscriptions = CPluginClient::GetInst ance()->FetchAvailableSubscriptions();
212 } 212 }
213 catch(std::exception ex) 213 catch(std::exception ex)
214 { 214 {
215 DEBUG_GENERAL(ex.what()); 215 DEBUG_GENERAL(ex.what());
216 throw ex; 216 throw ex;
217 } 217 }
218 s_isLightOnly = false; 218 s_isLightOnly = false;
219 } 219 }
220 220
221 instance = s_instance; 221 instance = s_instance;
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1490 } 1490 }
1491 1491
1492 CPluginSettingsWhitelistLock lock; 1492 CPluginSettingsWhitelistLock lock;
1493 if (lock.IsLocked()) 1493 if (lock.IsLocked())
1494 { 1494 {
1495 ClearWhitelist(); 1495 ClearWhitelist();
1496 1496
1497 s_criticalSectionLocal.Lock(); 1497 s_criticalSectionLocal.Lock();
1498 try 1498 try
1499 { 1499 {
1500 std::vector<AdblockPlus::FilterPtr> filters = CPluginClient::GetInstance() ->GetFilterEngine()->GetListedFilters(); 1500 std::vector<AdblockPlus::FilterPtr> filters = CPluginClient::GetInstance() ->GetListedFilters();
1501 for (int i = 0; i < filters.size(); i ++) 1501 for (int i = 0; i < filters.size(); i ++)
1502 { 1502 {
1503 if (filters[i]->GetType() == AdblockPlus::Filter::Type::TYPE_EXCEPTION) 1503 if (filters[i]->GetType() == AdblockPlus::Filter::Type::TYPE_EXCEPTION)
1504 { 1504 {
1505 std::string text = filters[i]->GetProperty("text")->AsString(); 1505 std::string text = filters[i]->GetProperty("text")->AsString();
1506 //@@||example.com^$document 1506 //@@||example.com^$document
1507 size_t endPos = text.rfind("^$document"); 1507 size_t endPos = text.rfind("^$document");
1508 if (endPos != std::string::npos) 1508 if (endPos != std::string::npos)
1509 { 1509 {
1510 size_t startPos = text.find("@@||") + 4; 1510 size_t startPos = text.find("@@||") + 4;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 1549
1550 std::string newDomain = CW2A(domain, CP_UTF8); 1550 std::string newDomain = CW2A(domain, CP_UTF8);
1551 1551
1552 //Domain already present? 1552 //Domain already present?
1553 if (std::find(m_whitelistedDomains.begin(), m_whitelistedDomains.end(), newD omain) != m_whitelistedDomains.end()) 1553 if (std::find(m_whitelistedDomains.begin(), m_whitelistedDomains.end(), newD omain) != m_whitelistedDomains.end())
1554 { 1554 {
1555 return; 1555 return;
1556 } 1556 }
1557 s_criticalSectionLocal.Lock(); 1557 s_criticalSectionLocal.Lock();
1558 { 1558 {
1559 AdblockPlus::FilterPtr whitelistFilter = CPluginClient::GetInstance()->Get FilterEngine()->GetFilter(std::string("@@||").append(CW2A(domain)).append("^$doc ument")); 1559 AdblockPlus::FilterPtr whitelistFilter = CPluginClient::GetInstance()->Get Filter(std::string("@@||").append(CW2A(domain)).append("^$document"));
1560 whitelistFilter->AddToList(); 1560 whitelistFilter->AddToList();
1561 } 1561 }
1562 s_criticalSectionLocal.Unlock(); 1562 s_criticalSectionLocal.Unlock();
1563 1563
1564 } 1564 }
1565 1565
1566 if (isForcingUpdateOnStart) 1566 if (isForcingUpdateOnStart)
1567 { 1567 {
1568 ForceConfigurationUpdateOnStart(); 1568 ForceConfigurationUpdateOnStart();
1569 } 1569 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 void CPluginSettings::SetSubscription(BSTR url) 1638 void CPluginSettings::SetSubscription(BSTR url)
1639 { 1639 {
1640 std::string urlConverted = CT2A(url, CP_UTF8); 1640 std::string urlConverted = CT2A(url, CP_UTF8);
1641 SetSubscription(urlConverted); 1641 SetSubscription(urlConverted);
1642 } 1642 }
1643 1643
1644 void CPluginSettings::SetSubscription(std::string url) 1644 void CPluginSettings::SetSubscription(std::string url)
1645 { 1645 {
1646 try 1646 try
1647 { 1647 {
1648 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine(); 1648 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = CPluginClient::Get Instance()->GetListedSubscriptions();
1649 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetL istedSubscriptions();
1650 if (subscriptions.size() > 0) 1649 if (subscriptions.size() > 0)
1651 { 1650 {
1652 for (int i = 0; i < subscriptions.size(); i ++) 1651 for (int i = 0; i < subscriptions.size(); i ++)
1653 { 1652 {
1654 subscriptions[i]->RemoveFromList(); 1653 subscriptions[i]->RemoveFromList();
1655 } 1654 }
1656 } 1655 }
1657 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription(ur l); 1656 AdblockPlus::SubscriptionPtr subscription = CPluginClient::GetInstance()->Ge tSubscription(url);
1658 subscription->AddToList(); 1657 subscription->AddToList();
1659 RefreshFilterlist(); 1658 RefreshFilterlist();
1660 RefreshWhitelist(); 1659 RefreshWhitelist();
1661 } 1660 }
1662 catch(std::exception ex) 1661 catch(std::exception ex)
1663 { 1662 {
1664 DEBUG_GENERAL(ex.what()); 1663 DEBUG_GENERAL(ex.what());
1665 } 1664 }
1666 catch(std::runtime_error ex) 1665 catch(std::runtime_error ex)
1667 { 1666 {
(...skipping 10 matching lines...) Expand all
1678 } 1677 }
1679 return retTokens; 1678 return retTokens;
1680 } 1679 }
1681 1680
1682 1681
1683 void CPluginSettings::SetDefaultSubscription() 1682 void CPluginSettings::SetDefaultSubscription()
1684 { 1683 {
1685 CPluginSystem* system = CPluginSystem::GetInstance(); 1684 CPluginSystem* system = CPluginSystem::GetInstance();
1686 CString lng = system->GetBrowserLanguage().Left(2); 1685 CString lng = system->GetBrowserLanguage().Left(2);
1687 std::string browserLanguage = CW2A(lng, CP_UTF8); 1686 std::string browserLanguage = CW2A(lng, CP_UTF8);
1688 FilterEngine* filterEngine = CPluginClient::GetInstance()->GetFilterEngine(); 1687 std::vector<SubscriptionPtr> subscriptions = CPluginClient::GetInstance()->Fet chAvailableSubscriptions();
1689 std::vector<SubscriptionPtr> subscriptions = filterEngine->FetchAvailableSubsc riptions();
1690 bool subscriptionSet = false; 1688 bool subscriptionSet = false;
1691 while (!subscriptionSet) 1689 while (!subscriptionSet)
1692 { 1690 {
1693 for (int i = 0; i < subscriptions.size(); i++) 1691 for (int i = 0; i < subscriptions.size(); i++)
1694 { 1692 {
1695 std::string prefixes = subscriptions[i]->GetProperty("prefixes")->AsString (); 1693 std::string prefixes = subscriptions[i]->GetProperty("prefixes")->AsString ();
1696 std::vector<std::string> tokens = split(prefixes, ','); 1694 std::vector<std::string> tokens = split(prefixes, ',');
1697 for (int j = 0; j < tokens.size(); j ++) 1695 for (int j = 0; j < tokens.size(); j ++)
1698 { 1696 {
1699 if (tokens[j] == browserLanguage) 1697 if (tokens[j] == browserLanguage)
1700 { 1698 {
1701 SetSubscription(subscriptions[i]->GetProperty("url")->AsString()); 1699 SetSubscription(subscriptions[i]->GetProperty("url")->AsString());
1702 subscriptionSet = true; 1700 subscriptionSet = true;
1703 } 1701 }
1704 } 1702 }
1705 } 1703 }
1706 1704
1707 if (browserLanguage == "en") 1705 if (browserLanguage == "en")
1708 break; 1706 break;
1709 // failed to set the subscription for browser language. Try "en" 1707 // failed to set the subscription for browser language. Try "en"
1710 browserLanguage = "en"; 1708 browserLanguage = "en";
1711 1709
1712 } 1710 }
1713 } 1711 }
1714 1712
1715 CString CPluginSettings::GetSubscription() 1713 CString CPluginSettings::GetSubscription()
1716 { 1714 {
1717 try 1715 try
1718 { 1716 {
1719 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine(); 1717 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = CPluginClient::GetI nstance()->GetListedSubscriptions();
1720 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetL istedSubscriptions();
1721 1718
1722 if (subscriptions.size() == 0) 1719 if (subscriptions.size() == 0)
1723 { 1720 {
1724 SetDefaultSubscription(); 1721 SetDefaultSubscription();
1725 subscriptions = filterEngine->GetListedSubscriptions(); 1722 subscriptions = CPluginClient::GetInstance()->GetListedSubscriptions();
1726 } 1723 }
1727 for (int i = 0; i < subscriptions.size(); i ++) 1724 for (int i = 0; i < subscriptions.size(); i ++)
1728 { 1725 {
1729 return CString(CA2T(subscriptions[i]->GetProperty("url")->AsString().c_str (), CP_UTF8)); 1726 return CString(CA2T(subscriptions[i]->GetProperty("url")->AsString().c_str (), CP_UTF8));
1730 } 1727 }
1731 } 1728 }
1732 catch(std::exception ex) 1729 catch(std::exception ex)
1733 { 1730 {
1734 DEBUG_GENERAL(ex.what()); 1731 DEBUG_GENERAL(ex.what());
1735 } 1732 }
1736 catch(std::runtime_error ex) 1733 catch(std::runtime_error ex)
1737 { 1734 {
1738 DEBUG_GENERAL(ex.what()); 1735 DEBUG_GENERAL(ex.what());
1739 } 1736 }
1740 return CString(L""); 1737 return CString(L"");
1741 } 1738 }
1742 1739
1743 1740
1744 void CPluginSettings::RefreshFilterlist() 1741 void CPluginSettings::RefreshFilterlist()
1745 { 1742 {
1746 try 1743 try
1747 { 1744 {
1748 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine();
1749
1750 // Make sure at least the default subscription is set 1745 // Make sure at least the default subscription is set
1751 CPluginSettings* settings = CPluginSettings::GetInstance(); 1746 CPluginSettings* settings = CPluginSettings::GetInstance();
1752 settings->GetSubscription(); 1747 settings->GetSubscription();
1753 1748
1754 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetL istedSubscriptions(); 1749 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = CPluginClient::Get Instance()->GetListedSubscriptions();
1755 for (int i = 0; i < subscriptions.size(); i ++) 1750 for (int i = 0; i < subscriptions.size(); i ++)
1756 { 1751 {
1757 subscriptions[i]->UpdateFilters(); 1752 subscriptions[i]->UpdateFilters();
1758 } 1753 }
1759 } 1754 }
1760 catch(std::exception ex) 1755 catch(std::exception ex)
1761 { 1756 {
1762 DEBUG_GENERAL(ex.what()); 1757 DEBUG_GENERAL(ex.what());
1763 } 1758 }
1764 catch(std::runtime_error ex) 1759 catch(std::runtime_error ex)
1765 { 1760 {
1766 DEBUG_GENERAL(ex.what()); 1761 DEBUG_GENERAL(ex.what());
1767 } 1762 }
1768 } 1763 }
1769 1764
1770 #endif // SUPPORT_WHITELIST 1765 #endif // SUPPORT_WHITELIST
OLDNEW
« no previous file with comments | « Shared/PluginFilter.cpp ('k') | Shared/PluginStdAfx.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld