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

Unified Diff: src/engine/main.cpp

Issue 10800092: Use libadblockplus update checker (Closed)
Patch Set: Addressed review comments Created June 7, 2013, 5:27 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/engine/main.cpp
===================================================================
--- a/src/engine/main.cpp
+++ b/src/engine/main.cpp
@@ -1,37 +1,24 @@
#include <AdblockPlus.h>
+#include <functional>
#include <vector>
#include <Windows.h>
#include "../shared/AutoHandle.h"
#include "../shared/Communication.h"
#include "../shared/Utils.h"
#include "../shared/Version.h"
#include "Debug.h"
+#include "Updater.h"
namespace
{
std::auto_ptr<AdblockPlus::FilterEngine> filterEngine;
- std::string ToUtf8String(std::wstring str)
- {
- size_t length = str.size();
- if (length == 0)
- return std::string();
-
- DWORD utf8StringLength = WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, 0, 0, 0, 0);
- if (utf8StringLength == 0)
- throw std::runtime_error("Failed to determine the required buffer size");
-
- std::string utf8String(utf8StringLength, '\0');
- WideCharToMultiByte(CP_UTF8, 0, str.c_str(), length, &utf8String[0], utf8StringLength, 0, 0);
- return utf8String;
- }
-
void WriteStrings(Communication::OutputBuffer& response,
const std::vector<std::string>& strings)
{
int32_t count = strings.size();
response << count;
for (int32_t i = 0; i < count; i++)
response << strings[i];
}
@@ -158,32 +145,47 @@ namespace
{
DebugException(e);
}
// TODO: Keep the pipe open until the client disconnects
return 0;
}
+
+ void OnUpdateAvailable(AdblockPlus::JsEnginePtr jsEngine, AdblockPlus::JsValueList& params)
+ {
+ if (params.size() < 1)
+ {
+ Debug("updateAvailable event missing URL");
+ return;
+ }
+
+ Updater updater(jsEngine, params[0]->AsString());
+ updater.Update();
+ }
}
std::auto_ptr<AdblockPlus::FilterEngine> CreateFilterEngine(const std::wstring& locale)
{
AdblockPlus::AppInfo appInfo;
appInfo.version = ToUtf8String(IEPLUGIN_VERSION);
appInfo.name = "adblockplusie";
appInfo.platform = "msie";
appInfo.locale = ToUtf8String(locale);
#ifdef ADBLOCK_PLUS_TEST_MODE
appInfo.developmentBuild = true;
#else
appInfo.developmentBuild = false;
#endif
AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo);
+ jsEngine->SetEventCallback("updateAvailable",
+ std::bind(&OnUpdateAvailable, jsEngine, std::placeholders::_1));
+
std::string dataPath = ToUtf8String(GetAppDataPath());
dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get())->SetBasePath(dataPath);
std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterEngine(jsEngine));
return filterEngine;
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{

Powered by Google App Engine
This is Rietveld