fix crash on quit
This commit is contained in:
parent
1022357700
commit
33f65ba981
4 changed files with 32 additions and 7 deletions
|
@ -13,6 +13,25 @@
|
|||
#include "net/log/net_log_util.h"
|
||||
#include "net/url_request/url_request_context.h"
|
||||
|
||||
namespace {
|
||||
|
||||
base::Value* GetConstants() {
|
||||
scoped_ptr<base::DictionaryValue> constants = net::GetNetConstants();
|
||||
|
||||
// Adding client information to constants dictionary.
|
||||
base::DictionaryValue* client_info = new base::DictionaryValue();
|
||||
|
||||
client_info->SetString("name", "Electron");
|
||||
client_info->SetString("command_line",
|
||||
base::CommandLine::ForCurrentProcess()->GetCommandLineString());
|
||||
|
||||
constants->Set("clientInfo", client_info);
|
||||
|
||||
return constants.release();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace brightray {
|
||||
|
||||
NetLog::NetLog(net::URLRequestContext* context)
|
||||
|
@ -35,16 +54,15 @@ NetLog::NetLog(net::URLRequestContext* context)
|
|||
<< "for net logging";
|
||||
|
||||
std::string json;
|
||||
scoped_ptr<base::Value> constants = net::GetNetConstants();
|
||||
base::JSONWriter::Write(constants.release(), &json);
|
||||
base::JSONWriter::Write(GetConstants(), &json);
|
||||
fprintf(log_file_.get(), "{\"constants\": %s, \n", json.c_str());
|
||||
fprintf(log_file_.get(), "\"events\": [\n");
|
||||
|
||||
if (context_.get()) {
|
||||
if (context_) {
|
||||
DCHECK(context_->CalledOnValidThread());
|
||||
|
||||
std::set<net::URLRequestContext*> contexts;
|
||||
contexts.insert(context_.get());
|
||||
contexts.insert(context_);
|
||||
|
||||
net::CreateNetLogEntriesForActiveObjects(contexts, this);
|
||||
}
|
||||
|
@ -55,6 +73,8 @@ NetLog::NetLog(net::URLRequestContext* context)
|
|||
|
||||
NetLog::~NetLog() {
|
||||
DeprecatedRemoveObserver(this);
|
||||
|
||||
// Ending events array.
|
||||
fprintf(log_file_.get(), "]}");
|
||||
log_file_.reset();
|
||||
}
|
||||
|
|
|
@ -19,13 +19,14 @@ class NetLog : public net::NetLog,
|
|||
public net::NetLog::ThreadSafeObserver {
|
||||
public:
|
||||
explicit NetLog(net::URLRequestContext* context);
|
||||
virtual ~NetLog();
|
||||
~NetLog() override;
|
||||
|
||||
void OnAddEntry(const net::NetLog::Entry& entry) override;
|
||||
|
||||
private:
|
||||
bool added_events_;
|
||||
scoped_ptr<net::URLRequestContext> context_;
|
||||
// We use raw pointer to prevent reference cycle.
|
||||
net::URLRequestContext* const context_;
|
||||
base::ScopedFILE log_file_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NetLog);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "net/dns/mapped_host_resolver.h"
|
||||
#include "net/http/http_auth_handler_factory.h"
|
||||
#include "net/http/http_server_properties_impl.h"
|
||||
#include "net/log/net_log.h"
|
||||
#include "net/proxy/dhcp_proxy_script_fetcher_factory.h"
|
||||
#include "net/proxy/proxy_config_service.h"
|
||||
#include "net/proxy/proxy_script_fetcher_impl.h"
|
||||
|
@ -147,7 +148,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
|||
auto& command_line = *base::CommandLine::ForCurrentProcess();
|
||||
if (!url_request_context_.get()) {
|
||||
url_request_context_.reset(new net::URLRequestContext);
|
||||
url_request_context_->set_net_log(new NetLog(url_request_context_.get()));
|
||||
net_log_.reset(new NetLog(url_request_context_.get()));
|
||||
url_request_context_->set_net_log(net_log_.get());
|
||||
network_delegate_.reset(delegate_->CreateNetworkDelegate());
|
||||
url_request_context_->set_network_delegate(network_delegate_.get());
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ class MessageLoop;
|
|||
}
|
||||
|
||||
namespace net {
|
||||
class NetLog;
|
||||
class HostMappingRules;
|
||||
class HostResolver;
|
||||
class NetworkDelegate;
|
||||
|
@ -65,6 +66,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
|
|||
base::MessageLoop* file_loop_;
|
||||
|
||||
scoped_ptr<net::ProxyConfigService> proxy_config_service_;
|
||||
scoped_ptr<net::NetLog> net_log_;
|
||||
scoped_ptr<net::NetworkDelegate> network_delegate_;
|
||||
scoped_ptr<net::URLRequestContextStorage> storage_;
|
||||
scoped_ptr<net::URLRequestContext> url_request_context_;
|
||||
|
|
Loading…
Reference in a new issue