Skip to content

Commit 4d7e328

Browse files
committed
port nw.App proxy API implementation to NS
1 parent 261ee02 commit 4d7e328

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

src/api/nw_app_api.cc

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "chrome/browser/devtools/devtools_window.h"
1414
#include "chrome/browser/extensions/devtools_util.h"
1515
#include "chrome/browser/extensions/extension_service.h"
16+
#include "chrome/browser/net/profile_network_context_service.h"
17+
#include "chrome/browser/net/profile_network_context_service_factory.h"
1618
#include "content/nw/src/api/nw_app.h"
1719
#include "content/nw/src/nw_base.h"
1820
#include "content/public/browser/render_frame_host.h"
@@ -34,18 +36,6 @@
3436

3537
using namespace extensions::nwapi::nw__app;
3638

37-
namespace {
38-
void SetProxyConfigCallback(
39-
base::WaitableEvent* done,
40-
const scoped_refptr<net::URLRequestContextGetter>& url_request_context_getter,
41-
const net::ProxyConfigWithAnnotation& proxy_config) {
42-
net::ProxyResolutionService* proxy_service =
43-
url_request_context_getter->GetURLRequestContext()->proxy_resolution_service();
44-
proxy_service->ResetConfigService(base::WrapUnique(new net::ProxyConfigServiceFixed(proxy_config)));
45-
done->Signal();
46-
}
47-
} // namespace
48-
4939
namespace extensions {
5040
NwAppQuitFunction::NwAppQuitFunction() {
5141

@@ -204,19 +194,10 @@ bool NwAppSetProxyConfigFunction::RunNWSync(base::ListValue* response, std::stri
204194
config = net::ProxyConfigWithAnnotation(pc, TRAFFIC_ANNOTATION_FOR_TESTS);
205195
}
206196

207-
base::ScopedAllowBaseSyncPrimitivesOutsideBlockingScope allow_wait;
208-
209-
content::RenderProcessHost* render_process_host = GetSenderWebContents()->GetMainFrame()->GetProcess();
210-
net::URLRequestContextGetter* context_getter =
211-
render_process_host->GetStoragePartition()->GetURLRequestContext();
212-
213-
base::WaitableEvent done(base::WaitableEvent::ResetPolicy::AUTOMATIC,
214-
base::WaitableEvent::InitialState::NOT_SIGNALED);
215-
base::PostTaskWithTraits(
216-
FROM_HERE, {content::BrowserThread::IO},
217-
base::BindOnce(&SetProxyConfigCallback, &done,
218-
base::WrapRefCounted(context_getter), config));
219-
done.Wait();
197+
Profile* profile = Profile::FromBrowserContext(context_);
198+
auto* profile_network_context =
199+
ProfileNetworkContextServiceFactory::GetForContext(profile);
200+
profile_network_context->UpdateProxyConfig(config);
220201
return true;
221202
}
222203

0 commit comments

Comments
 (0)