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

Unified Diff: chrome/browser/net/net_log_temp_file.h

Issue 11828036: First cut at UI for saving net_logs data into a temporary file on (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 11 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
Index: chrome/browser/net/net_log_temp_file.h
===================================================================
--- chrome/browser/net/net_log_temp_file.h (revision 0)
+++ chrome/browser/net/net_log_temp_file.h (revision 0)
@@ -0,0 +1,92 @@
+// Copyright (c) 2013 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.
+
+#ifndef CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_
+#define CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/file_path.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace base {
+class Value;
+}
+
+class NetLogLogger;
+
+// NetLogTempFile logs all the net_log entries into a temporary file created in
+// "NetLogs" folder in file_util::GetTempDir() directory.
+//
+// NetLogTempFile maintains the current state (state_) of the logging into a
+// temporary file.
+//
+// The following are the possible states
+// a) Only Start is allowed (state_ == UNINITIALIZED).
+// b) Only Stop is allowed (state_ == ALLOW_STOP).
+// c) Either Send or Start is allowed (state_ == ALLOW_START_SEND).
mmenke 2013/01/11 18:31:12 Think it's worth mentioning this is created/destro
ramant (doing other things) 2013/01/12 04:34:04 Done.
+class NetLogTempFile {
+ public:
+ // This enum lists the UI button commands it could receive.
+ enum Command {
+ DO_START, // Call StartLog.
+ DO_STOP, // Call StopLog.
+ DO_SEND, // Call SendLog.
+ };
+
+ // This enum lists the possible state NetLogTempFile could be in.
+ enum State {
mmenke 2013/01/11 18:31:12 Since these aren't used externally, this should be
ramant (doing other things) 2013/01/12 04:34:04 Done.
+ UNINITIALIZED,
+ ALLOW_START, // Only StartLog is allowed.
+ ALLOW_STOP, // Only StopLog is allowed.
+ ALLOW_START_SEND, // Either OnSendLog or OnStartLog calls are allowed.
mmenke 2013/01/11 18:31:12 Suggest naming the state after what |this| is curr
ramant (doing other things) 2013/01/12 04:34:04 Added STATE_ to the names. Updated the comments to
+ };
+
+ // Constructs a NetLogTempFile. Only one instance is created in
+ // browser process.
+ NetLogTempFile();
+ ~NetLogTempFile();
mmenke 2013/01/11 18:31:12 Given how weirdly this class will behave if we hav
ramant (doing other things) 2013/01/12 04:34:04 left ~NetLogTempFile() as public because of scoped
mmenke 2013/01/17 17:49:43 You could friend the relevant class if you really
+
+ // Accepts the button command and executes them.
+ void ProcessCommand(Command command);
+
+ // Creates a Value summary of the state of the NetLogTempFile. The caller is
+ // responsible for deleting the returned value.
+ base::Value* NetLogTempFileToValue();
mmenke 2013/01/11 18:31:12 Suggest renaming this "GetStateAsValue()" or even
ramant (doing other things) 2013/01/12 04:34:04 Done.
+
+ private:
+ // Initializes the |state_| to either ALLOW_START (if there is no temporary
+ // file from earlier run) or ALLOW_START_SEND (if there is a temporary file
+ // from earlier run).
+ void Init();
+
+ // Start collecting NetLog data into a temporary file in "NetLogs" folder in
+ // file_util::GetTempDir() directory. It deletes all the temporary files that
+ // are in that directory before creating a new temporary file. It is a no-op
+ // if we are already collecting data into a file.
+ void StartNetLog();
+
+ // Stop collecting NetLog data into the temporary file. It is a no-op if we
+ // are not collecting data into a file.
+ void StopNetLog();
+
+ // Emails the temporary file if one exists.
+ void SendNetLog();
+
+ // Helper function that runs on UI thread to send NetLog data via email.
+ static void SendEmail(const FilePath& file_to_send);
+
+ State state_; // Current state of NetLogTempFile.
+
+ FilePath log_path_; // FilePath to the temporary file.
+
+ // |net_log_logger_| watches the NetLog event stream, and sends all entries to
+ // the temporary file created in StartNetLog().
+ scoped_ptr<NetLogLogger> net_log_logger_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetLogTempFile);
+};
+
+#endif // CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_

Powered by Google App Engine
This is Rietveld 408576698