Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Unified Diff: ios/crnet/crnet_net_log.cc

Issue 1125293004: ios: add CrNet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix last nits Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/crnet/crnet_net_log.h ('k') | ios/crnet/crnet_pack.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/crnet/crnet_net_log.cc
diff --git a/ios/crnet/crnet_net_log.cc b/ios/crnet/crnet_net_log.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4ad3d3057d7317d68f2f90f3f7bbb6c2b7dc090f
--- /dev/null
+++ b/ios/crnet/crnet_net_log.cc
@@ -0,0 +1,46 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ios/crnet/crnet_net_log.h"
+
+#include "base/files/file_path.h"
+#include "base/files/file_util.h"
+#include "base/files/scoped_file.h"
+#include "base/values.h"
+#include "net/log/net_log.h"
+#include "net/log/net_log_util.h"
+#include "net/log/write_to_file_net_log_observer.h"
+
+CrNetNetLog::CrNetNetLog() { }
+CrNetNetLog::~CrNetNetLog() { }
+
+bool CrNetNetLog::Start(const base::FilePath& log_file,
+ CrNetNetLog::Mode mode) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ base::FilePath temp_dir;
+ if (!base::GetTempDir(&temp_dir))
+ return false;
+
+ base::FilePath full_path = temp_dir.Append(log_file);
+ base::ScopedFILE file(base::OpenFile(full_path, "w"));
+ if (!file)
+ return false;
+
+ scoped_ptr<base::Value> constants(net::GetNetConstants().Pass());
+
+ net::NetLogCaptureMode capture_mode = mode == LOG_ALL_BYTES ?
+ net::NetLogCaptureMode::IncludeSocketBytes() :
+ net::NetLogCaptureMode::Default();
+ write_to_file_observer_.reset(new net::WriteToFileNetLogObserver());
+ write_to_file_observer_->set_capture_mode(capture_mode);
+ write_to_file_observer_->StartObserving(this, file.Pass(), constants.get(),
+ nullptr);
+ return true;
+}
+
+void CrNetNetLog::Stop() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ write_to_file_observer_->StopObserving(nullptr);
+ write_to_file_observer_.reset();
+}
« no previous file with comments | « ios/crnet/crnet_net_log.h ('k') | ios/crnet/crnet_pack.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698