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