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

Side by Side Diff: src/Platform.cpp

Issue 29508569: Issue 5450 - don't expose std::shared_ptr<JsEngine> (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created Aug. 7, 2017, 8:39 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 | « src/FilterEngine.cpp ('k') | test/AppInfoJsObject.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2017 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
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 } 65 }
66 66
67 void Platform::SetUpJsEngine(const AppInfo& appInfo) 67 void Platform::SetUpJsEngine(const AppInfo& appInfo)
68 { 68 {
69 std::lock_guard<std::mutex> lock(modulesMutex); 69 std::lock_guard<std::mutex> lock(modulesMutex);
70 if (jsEngine) 70 if (jsEngine)
71 return; 71 return;
72 jsEngine = JsEngine::New(appInfo, *this); 72 jsEngine = JsEngine::New(appInfo, *this);
73 } 73 }
74 74
75 std::shared_ptr<JsEngine> Platform::GetJsEngine() 75 JsEngine& Platform::GetJsEngine()
76 { 76 {
77 SetUpJsEngine(); 77 SetUpJsEngine();
78 return jsEngine; 78 return *jsEngine;
79 } 79 }
80 80
81 void Platform::CreateFilterEngineAsync(const FilterEngine::CreationParameters& p arameters, 81 void Platform::CreateFilterEngineAsync(const FilterEngine::CreationParameters& p arameters,
82 const OnFilterEngineCreatedCallback& onCreated) 82 const OnFilterEngineCreatedCallback& onCreated)
83 { 83 {
84 std::shared_ptr<std::promise<FilterEnginePtr>> filterEnginePromise; 84 std::shared_ptr<std::promise<FilterEnginePtr>> filterEnginePromise;
85 { 85 {
86 std::lock_guard<std::mutex> lock(modulesMutex); 86 std::lock_guard<std::mutex> lock(modulesMutex);
87 if (filterEngine.valid()) 87 if (filterEngine.valid())
88 return; 88 return;
89 filterEnginePromise = std::make_shared<std::promise<FilterEnginePtr>>(); 89 filterEnginePromise = std::make_shared<std::promise<FilterEnginePtr>>();
90 filterEngine = filterEnginePromise->get_future(); 90 filterEngine = filterEnginePromise->get_future();
91 } 91 }
92 92
93 FilterEngine::CreateAsync(GetJsEngine(), [this, onCreated, filterEnginePromise ](const FilterEnginePtr& filterEngine) 93 GetJsEngine(); // ensures that JsEngine is instantiated
94 FilterEngine::CreateAsync(jsEngine, [this, onCreated, filterEnginePromise](con st FilterEnginePtr& filterEngine)
94 { 95 {
95 filterEnginePromise->set_value(filterEngine); 96 filterEnginePromise->set_value(filterEngine);
96 if (onCreated) 97 if (onCreated)
97 onCreated(filterEngine); 98 onCreated(filterEngine);
98 }, parameters); 99 }, parameters);
99 } 100 }
100 101
101 FilterEnginePtr Platform::GetFilterEngine() 102 FilterEnginePtr Platform::GetFilterEngine()
102 { 103 {
103 CreateFilterEngineAsync(); 104 CreateFilterEngineAsync();
(...skipping 12 matching lines...) Expand all
116 117
117 IWebRequest& Platform::GetWebRequest() 118 IWebRequest& Platform::GetWebRequest()
118 { 119 {
119 return *webRequest; 120 return *webRequest;
120 } 121 }
121 122
122 LogSystem& Platform::GetLogSystem() 123 LogSystem& Platform::GetLogSystem()
123 { 124 {
124 return *logSystem; 125 return *logSystem;
125 } 126 }
OLDNEW
« no previous file with comments | « src/FilterEngine.cpp ('k') | test/AppInfoJsObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld