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

Side by Side Diff: src/Platform.cpp

Issue 29500602: Issue 5450 - introduce the Platform class (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: rebase Created July 31, 2017, 12:53 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
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 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 #include <AdblockPlus/Platform.h>
18 #include <AdblockPlus/JsEngine.h>
19 #include <AdblockPlus/FilterEngine.h>
20 #include <AdblockPlus/DefaultLogSystem.h>
21 #include "DefaultTimer.h"
22 #include "DefaultWebRequest.h"
23 #include "DefaultFileSystem.h"
24
25 using namespace AdblockPlus;
26
27 namespace
28 {
29 void DummyScheduler(const AdblockPlus::SchedulerTask& task)
30 {
31 std::thread(task).detach();
32 }
33 }
34
35 TimerPtr AdblockPlus::CreateDefaultTimer()
36 {
37 return TimerPtr(new DefaultTimer());
38 }
39
40 FileSystemPtr AdblockPlus::CreateDefaultFileSystem(const Scheduler& scheduler)
41 {
42 return FileSystemPtr(new DefaultFileSystem(scheduler, std::unique_ptr<DefaultF ileSystemSync>(new DefaultFileSystemSync())));
43 }
44
45 WebRequestPtr AdblockPlus::CreateDefaultWebRequest(const Scheduler& scheduler)
46 {
47 return WebRequestPtr(new DefaultWebRequest(scheduler, std::unique_ptr<DefaultW ebRequestSync>(new DefaultWebRequestSync())));
48 }
49
50 LogSystemPtr AdblockPlus::CreateDefaultLogSystem()
51 {
52 return LogSystemPtr(new DefaultLogSystem());
53 }
54
55 Platform::Platform(CreationParameters&& creationParameters)
56 {
57 logSystem = creationParameters.logSystem ? std::move(creationParameters.logSys tem) : CreateDefaultLogSystem();
58 timer = creationParameters.timer ? std::move(creationParameters.timer) : Creat eDefaultTimer();
59 fileSystem = creationParameters.fileSystem ? std::move(creationParameters.file System) : CreateDefaultFileSystem(::DummyScheduler);
60 webRequest = creationParameters.webRequest ? std::move(creationParameters.webR equest) : CreateDefaultWebRequest(::DummyScheduler);
61 }
62
63 Platform::~Platform()
64 {
65 }
66
67 void Platform::SetUpJsEngine(const AppInfo& appInfo)
68 {
69 std::lock_guard<std::mutex> lock(modulesMutex);
70 if (jsEngine)
71 return;
72 jsEngine = JsEngine::New(appInfo, *this);
73 }
74
75 std::shared_ptr<JsEngine> Platform::GetJsEngine()
76 {
77 SetUpJsEngine();
78 return jsEngine;
79 }
80
81 ITimer& Platform::GetTimer()
82 {
83 return *timer;
84 }
85
86 IFileSystem& Platform::GetFileSystem()
87 {
88 return *fileSystem;
89 }
90
91 IWebRequest& Platform::GetWebRequest()
92 {
93 return *webRequest;
94 }
95
96 LogSystem& Platform::GetLogSystem()
97 {
98 return *logSystem;
99 }
OLDNEW

Powered by Google App Engine
This is Rietveld