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

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,125 @@
+// 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/gtest_prod_util.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace base {
+class DictionaryValue;
+}
+
+class NetLogLogger;
+class ChromeNetLog;
+
+// NetLogTempFile logs all the net_log entries into a temporary file created in
mmenke 2013/01/17 17:49:43 nit: NetLog entries (There is variable called net
ramant (doing other things) 2013/01/18 04:59:52 Done.
+// "chrome-net-export" folder in file_util::GetTempDir() directory.
+//
+// NetLogTempFile maintains the current state (state_) of the logging into a
+// chrome-net-export/log.json 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/17 17:49:43 nit: States have been renamed.
ramant (doing other things) 2013/01/18 04:59:52 Done.
+//
+// This is created/destroyed on the UI thread, but all other function calls
+// occur on the FILE_USER_BLOCKING thread.
+//
+// This relies on the UI thread outlasting all other named threads for thread
+// safety.
+class NetLogTempFile {
+ public:
+ // This enum lists the UI button commands it could receive.
+ enum Command {
+ DO_START, // Call StartLog.
+ DO_STOP, // Call StopLog.
+ };
+
+ ~NetLogTempFile(); // Destructs a NetLogTempFile.
+
+ // Accepts the button command and executes them.
+ void ProcessCommand(Command command);
+
+ // Returns true and the path to the temporary file that needs to be sent via
+ // email. If there is no file to send, then it returns false.
mmenke 2013/01/17 17:49:43 Don't think there's any need to mention email in t
ramant (doing other things) 2013/01/18 04:59:52 Done.
+ bool GetNetLogToSend(FilePath* path);
mmenke 2013/01/17 17:49:43 May want to call this "GetFilePath". I don't thin
ramant (doing other things) 2013/01/18 04:59:52 Done.
+
+ // Creates a Value summary of the state of the NetLogTempFile. The caller is
+ // responsible for deleting the returned value.
+ base::DictionaryValue* GetState();
+
+ private:
+ friend class ChromeNetLog;
+ friend class NetLogTempFileTest;
+
+ // Allow tests to access our innards for testing purposes.
+ FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, Init);
+ FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, InitAllowStart);
+ FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, InitAllowStartOrSend);
+ FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, ProcessCommandDoStart);
+ FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, ProcessCommandDoStop);
+ FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, GetNetLogToSend);
+
+ // This enum lists the possible state NetLogTempFile could be in. It is used
+ // to enable/disable "Start", "Stop" and "Send" (email) UI actions.
+ enum State {
+ STATE_UNINITIALIZED,
+ STATE_ALLOW_START, // Only DO_START Command is allowed.
+ STATE_ALLOW_STOP, // Only DO_STOP Command is allowed.
+ STATE_ALLOW_START_SEND, // Either DO_START or DO_SEND is allowed.
+ };
+
+ // Constructs a NetLogTempFile. Only one instance is created in
+ // browser process.
+ explicit NetLogTempFile(ChromeNetLog* chrome_net_log);
+
+ // 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 chrome-net-export/log.json file 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();
+
+ // Helper function for unit tests.
+ State state() const { return state_; }
+ void set_state(State state) { state_ = state; }
+
+ FilePath log_path() const { return log_path_; }
+
+ State state_; // Current state of NetLogTempFile.
+
+ // Name of the file. It defaults to log.json, but can be overwritten by
+ // unittests.
+ FilePath::StringType log_filename_;
+
+ FilePath log_path_; // FilePath to the temporary file.
+
+ // |net_log_logger_| watches the NetLog event stream, and sends all entries to
+ // the file created in StartNetLog().
+ scoped_ptr<NetLogLogger> net_log_logger_;
+
+ // The chrome_net_log_ is owned by the browser process, cached here to avoid
mmenke 2013/01/17 17:49:43 nit: Above, you surround state_ in ||'s. Google
ramant (doing other things) 2013/01/18 04:59:52 Done.
+ // using global (g_browser_process).
+ ChromeNetLog* chrome_net_log_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetLogTempFile);
+};
+
+#endif // CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_

Powered by Google App Engine
This is Rietveld 408576698