OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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_ == ALLOW_STOP). | |
31 // c) Either Send or Start is allowed (state_ == ALLOW_START_SEND). | |
32 class NetLogTempFile { | |
33 public: | |
34 // This enum lists the UI button commands it could receive. | |
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 ALLOW_START, // Only StartLog is allowed. | |
45 ALLOW_STOP, // Only StopLog is allowed. | |
46 ALLOW_START_SEND, // Either OnSendLog or OnStartLog calls are allowed. | |
47 }; | |
48 | |
49 static NetLogTempFile* GetInstance(); | |
50 | |
51 // Constructs a NetLogTempFile. Only one instance is created in | |
52 // browser process. | |
53 NetLogTempFile(); | |
mmenke
2013/01/04 16:22:09
This shouldn't be public for a singleton.
| |
54 | |
55 // Accepts the button command and executes them. | |
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 ~NetLogTempFile(); | |
66 | |
67 // Initializes the |state_| to either ALLOW_START (if there is no temporary | |
68 // file from earlier run) or ALLOW_START_SEND (if there is a temporary file | |
69 // from earlier run). | |
70 void Init(); | |
71 | |
72 // Start collecting NetLog data into a temporary file in "NetLogs" folder in | |
73 // file_util::GetTempDir() directory. It deletes all the temporary files that | |
74 // are in that directory before creating a new temporary file. It is a no-op | |
75 // if we are already collecting data into a file. | |
76 void StartNetLog(); | |
77 | |
78 // Stop collecting NetLog data into the temporary file. It is a no-op if we | |
79 // are not collecting data into a file. | |
80 void StopNetLog(); | |
81 | |
82 // Emails the temporary file if one exists. | |
83 void SendNetLog(); | |
84 | |
85 // Helper function that runs on UI thread to send NetLog data via email. | |
86 static void SendEmail(const FilePath& file_to_send); | |
87 | |
88 State state_; // Current state of NetLogTempFile. | |
89 | |
90 FilePath log_path_; // FilePath to the temporary file. | |
91 | |
92 // |net_log_logger_| watches the NetLog event stream, and sends all entries to | |
93 // the temporary file created in StartNetLog(). | |
94 scoped_ptr<NetLogLogger> net_log_logger_; | |
95 | |
96 DISALLOW_COPY_AND_ASSIGN(NetLogTempFile); | |
97 }; | |
98 | |
99 #endif // CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_ | |
OLD | NEW |