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