* chore: fix cpplint 'include_what_you_use' warnings Typically by including <memory>, <utility> etc. * chore: fix 'static/global string constant' warning Use C style strings instead of std::string. Style guide forbids non-trivial static / global variables. https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables /home/charles/electron/electron-gn/src/electron/script/cpplint.js * refactor: remove global string variables. Fix 'global string variables are not permitted' linter warnings by using the base::NoDestructor<> wrapper to make it explicit that these variables are never destroyed. The style guide's take on globals with nontrivial destructors: https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables * fix: initializer error introduced in last commit * fix: remove WIP file that was included by accident * fix: include order * fix: include order * fix: include order * fix: include order, again
		
			
				
	
	
		
			93 lines
		
	
	
	
		
			2.5 KiB
			
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			93 lines
		
	
	
	
		
			2.5 KiB
			
		
	
	
	
		
			C++
		
	
	
	
	
	
// Copyright (c) 2018 GitHub, Inc.
 | 
						|
// Use of this source code is governed by the MIT license that can be
 | 
						|
// found in the LICENSE file.
 | 
						|
 | 
						|
#include "atom/browser/api/atom_api_net_log.h"
 | 
						|
 | 
						|
#include <utility>
 | 
						|
 | 
						|
#include "atom/browser/atom_browser_client.h"
 | 
						|
#include "atom/common/native_mate_converters/callback.h"
 | 
						|
#include "atom/common/native_mate_converters/file_path_converter.h"
 | 
						|
#include "base/callback.h"
 | 
						|
#include "content/public/common/content_switches.h"
 | 
						|
#include "native_mate/dictionary.h"
 | 
						|
#include "native_mate/handle.h"
 | 
						|
 | 
						|
#include "atom/common/node_includes.h"
 | 
						|
 | 
						|
namespace atom {
 | 
						|
 | 
						|
namespace api {
 | 
						|
 | 
						|
NetLog::NetLog(v8::Isolate* isolate) {
 | 
						|
  Init(isolate);
 | 
						|
 | 
						|
  net_log_ = atom::AtomBrowserClient::Get()->GetNetLog();
 | 
						|
}
 | 
						|
 | 
						|
NetLog::~NetLog() {}
 | 
						|
 | 
						|
// static
 | 
						|
v8::Local<v8::Value> NetLog::Create(v8::Isolate* isolate) {
 | 
						|
  return mate::CreateHandle(isolate, new NetLog(isolate)).ToV8();
 | 
						|
}
 | 
						|
 | 
						|
void NetLog::StartLogging(mate::Arguments* args) {
 | 
						|
  base::FilePath log_path;
 | 
						|
  if (!args->GetNext(&log_path) || log_path.empty()) {
 | 
						|
    args->ThrowError("The first parameter must be a valid string");
 | 
						|
    return;
 | 
						|
  }
 | 
						|
 | 
						|
  net_log_->StartDynamicLogging(log_path);
 | 
						|
}
 | 
						|
 | 
						|
bool NetLog::IsCurrentlyLogging() {
 | 
						|
  return net_log_->IsDynamicLogging();
 | 
						|
}
 | 
						|
 | 
						|
base::FilePath::StringType NetLog::GetCurrentlyLoggingPath() {
 | 
						|
  return net_log_->GetDynamicLoggingPath().value();
 | 
						|
}
 | 
						|
 | 
						|
void NetLog::StopLogging(mate::Arguments* args) {
 | 
						|
  base::OnceClosure callback;
 | 
						|
  args->GetNext(&callback);
 | 
						|
 | 
						|
  net_log_->StopDynamicLogging(std::move(callback));
 | 
						|
}
 | 
						|
 | 
						|
// static
 | 
						|
void NetLog::BuildPrototype(v8::Isolate* isolate,
 | 
						|
                            v8::Local<v8::FunctionTemplate> prototype) {
 | 
						|
  prototype->SetClassName(mate::StringToV8(isolate, "NetLog"));
 | 
						|
  mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
 | 
						|
      .SetProperty("currentlyLogging", &NetLog::IsCurrentlyLogging)
 | 
						|
      .SetProperty("currentlyLoggingPath", &NetLog::GetCurrentlyLoggingPath)
 | 
						|
      .SetMethod("startLogging", &NetLog::StartLogging)
 | 
						|
      .SetMethod("_stopLogging", &NetLog::StopLogging);
 | 
						|
}
 | 
						|
 | 
						|
}  // namespace api
 | 
						|
 | 
						|
}  // namespace atom
 | 
						|
 | 
						|
namespace {
 | 
						|
 | 
						|
using atom::api::NetLog;
 | 
						|
 | 
						|
void Initialize(v8::Local<v8::Object> exports,
 | 
						|
                v8::Local<v8::Value> unused,
 | 
						|
                v8::Local<v8::Context> context,
 | 
						|
                void* priv) {
 | 
						|
  v8::Isolate* isolate = context->GetIsolate();
 | 
						|
 | 
						|
  mate::Dictionary dict(isolate, exports);
 | 
						|
  dict.Set("netLog", NetLog::Create(isolate));
 | 
						|
  dict.Set("NetLog", NetLog::GetConstructor(isolate)->GetFunction());
 | 
						|
}
 | 
						|
 | 
						|
}  // namespace
 | 
						|
 | 
						|
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_browser_net_log, Initialize)
 |