fix crash on quit

This commit is contained in:
deepak1556 2015-06-06 14:33:07 +05:30
parent 1022357700
commit 33f65ba981
4 changed files with 32 additions and 7 deletions

View file

@ -13,6 +13,25 @@
#include "net/log/net_log_util.h" #include "net/log/net_log_util.h"
#include "net/url_request/url_request_context.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 { namespace brightray {
NetLog::NetLog(net::URLRequestContext* context) NetLog::NetLog(net::URLRequestContext* context)
@ -35,16 +54,15 @@ NetLog::NetLog(net::URLRequestContext* context)
<< "for net logging"; << "for net logging";
std::string json; std::string json;
scoped_ptr<base::Value> constants = net::GetNetConstants(); base::JSONWriter::Write(GetConstants(), &json);
base::JSONWriter::Write(constants.release(), &json);
fprintf(log_file_.get(), "{\"constants\": %s, \n", json.c_str()); fprintf(log_file_.get(), "{\"constants\": %s, \n", json.c_str());
fprintf(log_file_.get(), "\"events\": [\n"); fprintf(log_file_.get(), "\"events\": [\n");
if (context_.get()) { if (context_) {
DCHECK(context_->CalledOnValidThread()); DCHECK(context_->CalledOnValidThread());
std::set<net::URLRequestContext*> contexts; std::set<net::URLRequestContext*> contexts;
contexts.insert(context_.get()); contexts.insert(context_);
net::CreateNetLogEntriesForActiveObjects(contexts, this); net::CreateNetLogEntriesForActiveObjects(contexts, this);
} }
@ -55,6 +73,8 @@ NetLog::NetLog(net::URLRequestContext* context)
NetLog::~NetLog() { NetLog::~NetLog() {
DeprecatedRemoveObserver(this); DeprecatedRemoveObserver(this);
// Ending events array.
fprintf(log_file_.get(), "]}"); fprintf(log_file_.get(), "]}");
log_file_.reset(); log_file_.reset();
} }

View file

@ -19,13 +19,14 @@ class NetLog : public net::NetLog,
public net::NetLog::ThreadSafeObserver { public net::NetLog::ThreadSafeObserver {
public: public:
explicit NetLog(net::URLRequestContext* context); explicit NetLog(net::URLRequestContext* context);
virtual ~NetLog(); ~NetLog() override;
void OnAddEntry(const net::NetLog::Entry& entry) override; void OnAddEntry(const net::NetLog::Entry& entry) override;
private: private:
bool added_events_; bool added_events_;
scoped_ptr<net::URLRequestContext> context_; // We use raw pointer to prevent reference cycle.
net::URLRequestContext* const context_;
base::ScopedFILE log_file_; base::ScopedFILE log_file_;
DISALLOW_COPY_AND_ASSIGN(NetLog); DISALLOW_COPY_AND_ASSIGN(NetLog);

View file

@ -22,6 +22,7 @@
#include "net/dns/mapped_host_resolver.h" #include "net/dns/mapped_host_resolver.h"
#include "net/http/http_auth_handler_factory.h" #include "net/http/http_auth_handler_factory.h"
#include "net/http/http_server_properties_impl.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/dhcp_proxy_script_fetcher_factory.h"
#include "net/proxy/proxy_config_service.h" #include "net/proxy/proxy_config_service.h"
#include "net/proxy/proxy_script_fetcher_impl.h" #include "net/proxy/proxy_script_fetcher_impl.h"
@ -147,7 +148,8 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
auto& command_line = *base::CommandLine::ForCurrentProcess(); auto& command_line = *base::CommandLine::ForCurrentProcess();
if (!url_request_context_.get()) { if (!url_request_context_.get()) {
url_request_context_.reset(new net::URLRequestContext); 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()); network_delegate_.reset(delegate_->CreateNetworkDelegate());
url_request_context_->set_network_delegate(network_delegate_.get()); url_request_context_->set_network_delegate(network_delegate_.get());

View file

@ -17,6 +17,7 @@ class MessageLoop;
} }
namespace net { namespace net {
class NetLog;
class HostMappingRules; class HostMappingRules;
class HostResolver; class HostResolver;
class NetworkDelegate; class NetworkDelegate;
@ -65,6 +66,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter {
base::MessageLoop* file_loop_; base::MessageLoop* file_loop_;
scoped_ptr<net::ProxyConfigService> proxy_config_service_; scoped_ptr<net::ProxyConfigService> proxy_config_service_;
scoped_ptr<net::NetLog> net_log_;
scoped_ptr<net::NetworkDelegate> network_delegate_; scoped_ptr<net::NetworkDelegate> network_delegate_;
scoped_ptr<net::URLRequestContextStorage> storage_; scoped_ptr<net::URLRequestContextStorage> storage_;
scoped_ptr<net::URLRequestContext> url_request_context_; scoped_ptr<net::URLRequestContext> url_request_context_;