2018-06-19 01:45:58 +00:00
|
|
|
// Copyright (c) 2018 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NET_LOG_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NET_LOG_H_
|
2018-06-19 01:45:58 +00:00
|
|
|
|
2024-01-10 22:23:35 +00:00
|
|
|
#include <optional>
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2021-06-21 01:52:28 +00:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "base/values.h"
|
2020-03-18 23:46:05 +00:00
|
|
|
#include "gin/wrappable.h"
|
2021-06-21 01:52:28 +00:00
|
|
|
#include "mojo/public/cpp/bindings/remote.h"
|
|
|
|
#include "net/log/net_log_capture_mode.h"
|
2019-05-23 22:31:38 +00:00
|
|
|
#include "services/network/public/mojom/net_log.mojom.h"
|
2019-11-01 06:10:32 +00:00
|
|
|
#include "shell/common/gin_helper/promise.h"
|
2020-03-18 23:46:05 +00:00
|
|
|
|
2024-07-29 17:42:57 +00:00
|
|
|
namespace base {
|
|
|
|
class FilePath;
|
|
|
|
class TaskRunner;
|
|
|
|
} // namespace base
|
|
|
|
|
2020-03-18 23:46:05 +00:00
|
|
|
namespace gin {
|
|
|
|
class Arguments;
|
2024-07-29 17:42:57 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class Handle;
|
|
|
|
} // namespace gin
|
2018-06-19 01:45:58 +00:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
2018-10-04 18:08:56 +00:00
|
|
|
class ElectronBrowserContext;
|
|
|
|
|
2018-06-19 01:45:58 +00:00
|
|
|
namespace api {
|
|
|
|
|
2021-06-21 01:52:28 +00:00
|
|
|
// The code is referenced from the net_log::NetExportFileWriter class.
|
2020-03-18 23:46:05 +00:00
|
|
|
class NetLog : public gin::Wrappable<NetLog> {
|
2018-06-19 01:45:58 +00:00
|
|
|
public:
|
2019-10-25 13:03:28 +00:00
|
|
|
static gin::Handle<NetLog> Create(v8::Isolate* isolate,
|
|
|
|
ElectronBrowserContext* browser_context);
|
2018-06-19 01:45:58 +00:00
|
|
|
|
2019-07-25 23:06:39 +00:00
|
|
|
v8::Local<v8::Promise> StartLogging(base::FilePath log_path,
|
2020-03-18 23:46:05 +00:00
|
|
|
gin::Arguments* args);
|
|
|
|
v8::Local<v8::Promise> StopLogging(gin::Arguments* args);
|
2019-05-23 22:31:38 +00:00
|
|
|
bool IsCurrentlyLogging() const;
|
2018-06-19 01:45:58 +00:00
|
|
|
|
2020-03-18 23:46:05 +00:00
|
|
|
// gin::Wrappable
|
|
|
|
static gin::WrapperInfo kWrapperInfo;
|
|
|
|
gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
|
|
|
v8::Isolate* isolate) override;
|
|
|
|
const char* GetTypeName() override;
|
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
NetLog(const NetLog&) = delete;
|
|
|
|
NetLog& operator=(const NetLog&) = delete;
|
|
|
|
|
2018-06-19 01:45:58 +00:00
|
|
|
protected:
|
2018-10-04 18:08:56 +00:00
|
|
|
explicit NetLog(v8::Isolate* isolate,
|
|
|
|
ElectronBrowserContext* browser_context);
|
2018-06-19 01:45:58 +00:00
|
|
|
~NetLog() override;
|
|
|
|
|
2019-05-23 22:31:38 +00:00
|
|
|
void OnConnectionError();
|
|
|
|
|
2019-05-24 17:54:32 +00:00
|
|
|
void StartNetLogAfterCreateFile(net::NetLogCaptureMode capture_mode,
|
|
|
|
uint64_t max_file_size,
|
2022-06-27 20:50:08 +00:00
|
|
|
base::Value::Dict custom_constants,
|
2019-05-24 17:54:32 +00:00
|
|
|
base::File output_file);
|
2019-05-23 22:31:38 +00:00
|
|
|
void NetLogStarted(int32_t error);
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2018-06-19 01:45:58 +00:00
|
|
|
private:
|
2023-05-11 20:07:39 +00:00
|
|
|
raw_ptr<ElectronBrowserContext> browser_context_;
|
2019-05-23 22:31:38 +00:00
|
|
|
|
2021-06-21 01:52:28 +00:00
|
|
|
mojo::Remote<network::mojom::NetLogExporter> net_log_exporter_;
|
2019-05-23 22:31:38 +00:00
|
|
|
|
2024-01-10 22:23:35 +00:00
|
|
|
std::optional<gin_helper::Promise<void>> pending_start_promise_;
|
2019-05-23 22:31:38 +00:00
|
|
|
|
|
|
|
scoped_refptr<base::TaskRunner> file_task_runner_;
|
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<NetLog> weak_ptr_factory_{this};
|
2018-06-19 01:45:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_NET_LOG_H_
|