refactor: netLog directly uses network service (#18289)

This commit is contained in:
Jeremy Apthorp 2019-05-23 15:31:38 -07:00 committed by GitHub
parent d57df5a4a1
commit 646f572b77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 220 additions and 141 deletions

View file

@ -12,9 +12,10 @@
#include "atom/browser/api/trackable_object.h"
#include "atom/common/promise_util.h"
#include "base/callback.h"
#include "base/optional.h"
#include "base/values.h"
#include "components/net_log/net_export_file_writer.h"
#include "native_mate/handle.h"
#include "services/network/public/mojom/net_log.mojom.h"
namespace atom {
@ -22,8 +23,7 @@ class AtomBrowserContext;
namespace api {
class NetLog : public mate::TrackableObject<NetLog>,
public net_log::NetExportFileWriter::StateObserver {
class NetLog : public mate::TrackableObject<NetLog> {
public:
static mate::Handle<NetLog> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
@ -31,24 +31,33 @@ class NetLog : public mate::TrackableObject<NetLog>,
static void BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype);
void StartLogging(mate::Arguments* args);
std::string GetLoggingState() const;
bool IsCurrentlyLogging() const;
std::string GetCurrentlyLoggingPath() const;
v8::Local<v8::Promise> StartLogging(mate::Arguments* args);
v8::Local<v8::Promise> StopLogging(mate::Arguments* args);
bool IsCurrentlyLogging() const;
protected:
explicit NetLog(v8::Isolate* isolate, AtomBrowserContext* browser_context);
~NetLog() override;
// net_log::NetExportFileWriter::StateObserver implementation
void OnNewState(const base::DictionaryValue& state) override;
void OnConnectionError();
void StartNetLogAfterCreateFile(
network::mojom::NetLogCaptureMode capture_mode,
uint64_t max_file_size,
base::Value custom_constants,
base::File output_file);
void NetLogStarted(int32_t error);
private:
AtomBrowserContext* browser_context_;
net_log::NetExportFileWriter* net_log_writer_;
std::list<atom::util::Promise> stop_callback_queue_;
std::unique_ptr<base::DictionaryValue> net_log_state_;
network::mojom::NetLogExporterPtr net_log_exporter_;
base::Optional<util::Promise> pending_start_promise_;
scoped_refptr<base::TaskRunner> file_task_runner_;
base::WeakPtrFactory<NetLog> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(NetLog);
};