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,97 @@ |
+// Copyright (c) 2012 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" |
+#include "base/memory/singleton.h" |
+#include "base/memory/weak_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 is a singleton that 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_ == STOP). |
+// c) Either Send or Start is allowed (state_ == START_SEND). |
+class NetLogTempFile { |
+ public: |
+ // This enum lists the possible state NetLogTempFile could be in. |
+ 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 { |
+ UNINITIALIZED, |
+ START, // Only StartLog is allowed. |
+ STOP, // Only StopLog is allowed. |
+ START_SEND, // Either OnSendLog or OnStartLog calls are allowed. |
+ }; |
+ |
+ static NetLogTempFile* GetInstance(); |
mmenke
2012/12/27 20:43:05
What's the motivation for making this a Singleton?
ramant (doing other things)
2013/01/04 01:47:28
Made it a single to work with chrome://net-interna
mmenke
2013/01/04 16:22:09
How much do we care about that use case? I've bee
|
+ |
+ // Constructs a NetLogTempFile. Only one instance is created in |
+ // browser process. |
+ NetLogTempFile(); |
+ ~NetLogTempFile(); |
mmenke
2012/12/27 20:43:05
If we're going to make this a Singleton, these sho
ramant (doing other things)
2013/01/04 01:47:28
Done.
|
+ |
+ 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() const; |
+ |
+ private: |
+ friend struct DefaultSingletonTraits<NetLogTempFile>; |
+ |
+ // Initializes the |state_| to either START (if there is no |
+ // temporary file from earlier run) or START_SEND (if there is a |
+ // temporary file from earlier run). |
+ void DetermineInitialState(); |
+ |
+ // 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(); |
+ |
+ // Send NetLog 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_ |