Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_ | |
| 6 #define CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/file_path.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/singleton.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 | |
| 16 namespace base { | |
| 17 class Value; | |
| 18 } | |
| 19 | |
| 20 class NetLogLogger; | |
| 21 | |
| 22 // NetLogTempFile logs all the net_log entries into a temporary file created in | |
| 23 // "NetLogs" folder in file_util::GetTempDir() directory. | |
| 24 // | |
| 25 // NetLogTempFile is a singleton that maintains the current state (state_) of | |
| 26 // the logging into a temporary file. | |
| 27 // | |
| 28 // The following are the possible states | |
| 29 // a) Only Start is allowed (state_ == UNINITIALIZED). | |
| 30 // b) Only Stop is allowed (state_ == STOP). | |
| 31 // c) Either Send or Start is allowed (state_ == START_SEND). | |
| 32 class NetLogTempFile { | |
| 33 public: | |
| 34 // This enum lists the possible state NetLogTempFile could be in. | |
| 35 enum Command { | |
| 36 DO_START, // Call StartLog. | |
| 37 DO_STOP, // Call StopLog. | |
| 38 DO_SEND, // Call SendLog. | |
| 39 }; | |
| 40 | |
| 41 // This enum lists the possible state NetLogTempFile could be in. | |
| 42 enum State { | |
| 43 UNINITIALIZED, | |
| 44 START, // Only StartLog is allowed. | |
| 45 STOP, // Only StopLog is allowed. | |
| 46 START_SEND, // Either OnSendLog or OnStartLog calls are allowed. | |
| 47 }; | |
| 48 | |
| 49 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
| |
| 50 | |
| 51 // Constructs a NetLogTempFile. Only one instance is created in | |
| 52 // browser process. | |
| 53 NetLogTempFile(); | |
| 54 ~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.
| |
| 55 | |
| 56 void ProcessCommand(Command command); | |
| 57 | |
| 58 // Creates a Value summary of the state of the NetLogTempFile. The caller is | |
| 59 // responsible for deleting the returned value. | |
| 60 base::Value* NetLogTempFileToValue() const; | |
| 61 | |
| 62 private: | |
| 63 friend struct DefaultSingletonTraits<NetLogTempFile>; | |
| 64 | |
| 65 // Initializes the |state_| to either START (if there is no | |
| 66 // temporary file from earlier run) or START_SEND (if there is a | |
| 67 // temporary file from earlier run). | |
| 68 void DetermineInitialState(); | |
| 69 | |
| 70 // Start collecting NetLog data into a temporary file in "NetLogs" folder in | |
| 71 // file_util::GetTempDir() directory. It deletes all the temporary files that | |
| 72 // are in that directory before creating a new temporary file. It is a no-op | |
| 73 // if we are already collecting data into a file. | |
| 74 void StartNetLog(); | |
| 75 | |
| 76 // Stop collecting NetLog data into the temporary file. It is a no-op if we | |
| 77 // are not collecting data into a file. | |
| 78 void StopNetLog(); | |
| 79 | |
| 80 // Emails the temporary file if one exists. | |
| 81 void SendNetLog(); | |
| 82 | |
| 83 // Send NetLog via email. | |
| 84 static void SendEmail(const FilePath& file_to_send); | |
| 85 | |
| 86 State state_; // Current state of NetLogTempFile. | |
| 87 | |
| 88 FilePath log_path_; // FilePath to the temporary file. | |
| 89 | |
| 90 // |net_log_logger_| watches the NetLog event stream, and sends all entries to | |
| 91 // the temporary file created in StartNetLog(). | |
| 92 scoped_ptr<NetLogLogger> net_log_logger_; | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(NetLogTempFile); | |
| 95 }; | |
| 96 | |
| 97 #endif // CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_ | |
| OLD | NEW |