Clear protocol handlers on exit

This commit is contained in:
Cheng Zhao 2016-07-09 17:02:55 +09:00
parent 3481acd570
commit 627028e3a0
5 changed files with 27 additions and 2 deletions

View file

@ -26,6 +26,18 @@ namespace atom {
namespace api { namespace api {
namespace {
// Clear protocol handlers in IO thread.
void ClearJobFactoryInIO(
scoped_refptr<brightray::URLRequestContextGetter> request_context_getter) {
auto job_factory = static_cast<AtomURLRequestJobFactory*>(
request_context_getter->job_factory());
job_factory->Clear();
}
} // namespace
Protocol::Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context) Protocol::Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context)
: request_context_getter_(static_cast<brightray::URLRequestContextGetter*>( : request_context_getter_(static_cast<brightray::URLRequestContextGetter*>(
browser_context->GetRequestContext())), browser_context->GetRequestContext())),
@ -33,6 +45,12 @@ Protocol::Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context)
Init(isolate); Init(isolate);
} }
Protocol::~Protocol() {
content::BrowserThread::PostTask(
content::BrowserThread::IO, FROM_HERE,
base::Bind(ClearJobFactoryInIO, request_context_getter_));
}
void Protocol::RegisterServiceWorkerSchemes( void Protocol::RegisterServiceWorkerSchemes(
const std::vector<std::string>& schemes) { const std::vector<std::string>& schemes) {
atom::AtomBrowserClient::SetCustomServiceWorkerSchemes(schemes); atom::AtomBrowserClient::SetCustomServiceWorkerSchemes(schemes);

View file

@ -43,6 +43,7 @@ class Protocol : public mate::TrackableObject<Protocol> {
protected: protected:
Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context); Protocol(v8::Isolate* isolate, AtomBrowserContext* browser_context);
~Protocol();
private: private:
// Possible errors. // Possible errors.

View file

@ -25,7 +25,6 @@ const char* kGeolocationProviderURL =
} // namespace } // namespace
AtomAccessTokenStore::AtomAccessTokenStore() { AtomAccessTokenStore::AtomAccessTokenStore() {
LOG(ERROR) << "AtomAccessTokenStore";
content::GeolocationProvider::GetInstance()->UserDidOptIntoLocationServices(); content::GeolocationProvider::GetInstance()->UserDidOptIntoLocationServices();
} }

View file

@ -20,7 +20,7 @@ typedef net::URLRequestJobFactory::ProtocolHandler ProtocolHandler;
AtomURLRequestJobFactory::AtomURLRequestJobFactory() {} AtomURLRequestJobFactory::AtomURLRequestJobFactory() {}
AtomURLRequestJobFactory::~AtomURLRequestJobFactory() { AtomURLRequestJobFactory::~AtomURLRequestJobFactory() {
STLDeleteValues(&protocol_handler_map_); Clear();
} }
bool AtomURLRequestJobFactory::SetProtocolHandler( bool AtomURLRequestJobFactory::SetProtocolHandler(
@ -77,6 +77,10 @@ bool AtomURLRequestJobFactory::HasProtocolHandler(
return ContainsKey(protocol_handler_map_, scheme); return ContainsKey(protocol_handler_map_, scheme);
} }
void AtomURLRequestJobFactory::Clear() {
STLDeleteValues(&protocol_handler_map_);
}
net::URLRequestJob* AtomURLRequestJobFactory::MaybeCreateJobWithProtocolHandler( net::URLRequestJob* AtomURLRequestJobFactory::MaybeCreateJobWithProtocolHandler(
const std::string& scheme, const std::string& scheme,
net::URLRequest* request, net::URLRequest* request,

View file

@ -39,6 +39,9 @@ class AtomURLRequestJobFactory : public net::URLRequestJobFactory {
// Whether the protocol handler is registered by the job factory. // Whether the protocol handler is registered by the job factory.
bool HasProtocolHandler(const std::string& scheme) const; bool HasProtocolHandler(const std::string& scheme) const;
// Clear all protocol handlers.
void Clear();
// URLRequestJobFactory implementation // URLRequestJobFactory implementation
net::URLRequestJob* MaybeCreateJobWithProtocolHandler( net::URLRequestJob* MaybeCreateJobWithProtocolHandler(
const std::string& scheme, const std::string& scheme,