atom_api_net_log.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (c) 2018 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ATOM_BROWSER_API_ATOM_API_NET_LOG_H_
  5. #define ATOM_BROWSER_API_ATOM_API_NET_LOG_H_
  6. #include <list>
  7. #include <memory>
  8. #include <string>
  9. #include "atom/browser/api/trackable_object.h"
  10. #include "atom/common/promise_util.h"
  11. #include "base/callback.h"
  12. #include "base/values.h"
  13. #include "components/net_log/net_export_file_writer.h"
  14. #include "native_mate/handle.h"
  15. namespace atom {
  16. class AtomBrowserContext;
  17. namespace api {
  18. class NetLog : public mate::TrackableObject<NetLog>,
  19. public net_log::NetExportFileWriter::StateObserver {
  20. public:
  21. static mate::Handle<NetLog> Create(v8::Isolate* isolate,
  22. AtomBrowserContext* browser_context);
  23. static void BuildPrototype(v8::Isolate* isolate,
  24. v8::Local<v8::FunctionTemplate> prototype);
  25. void StartLogging(mate::Arguments* args);
  26. std::string GetLoggingState() const;
  27. bool IsCurrentlyLogging() const;
  28. std::string GetCurrentlyLoggingPath() const;
  29. v8::Local<v8::Promise> StopLogging(mate::Arguments* args);
  30. protected:
  31. explicit NetLog(v8::Isolate* isolate, AtomBrowserContext* browser_context);
  32. ~NetLog() override;
  33. // net_log::NetExportFileWriter::StateObserver implementation
  34. void OnNewState(const base::DictionaryValue& state) override;
  35. private:
  36. AtomBrowserContext* browser_context_;
  37. net_log::NetExportFileWriter* net_log_writer_;
  38. std::list<atom::util::Promise> stop_callback_queue_;
  39. std::unique_ptr<base::DictionaryValue> net_log_state_;
  40. DISALLOW_COPY_AND_ASSIGN(NetLog);
  41. };
  42. } // namespace api
  43. } // namespace atom
  44. #endif // ATOM_BROWSER_API_ATOM_API_NET_LOG_H_