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/gtest_prod_util.h" | |
13 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/scoped_ptr.h" | |
15 | |
16 namespace base { | |
17 class DictionaryValue; | |
18 } | |
19 | |
20 class NetLogLogger; | |
21 class ChromeNetLog; | |
22 | |
23 // 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.
| |
24 // "chrome-net-export" folder in file_util::GetTempDir() directory. | |
25 // | |
26 // NetLogTempFile maintains the current state (state_) of the logging into a | |
27 // chrome-net-export/log.json file. | |
28 // | |
29 // The following are the possible states | |
30 // a) Only Start is allowed (state_ == UNINITIALIZED). | |
31 // b) Only Stop is allowed (state_ == ALLOW_STOP). | |
32 // 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.
| |
33 // | |
34 // This is created/destroyed on the UI thread, but all other function calls | |
35 // occur on the FILE_USER_BLOCKING thread. | |
36 // | |
37 // This relies on the UI thread outlasting all other named threads for thread | |
38 // safety. | |
39 class NetLogTempFile { | |
40 public: | |
41 // This enum lists the UI button commands it could receive. | |
42 enum Command { | |
43 DO_START, // Call StartLog. | |
44 DO_STOP, // Call StopLog. | |
45 }; | |
46 | |
47 ~NetLogTempFile(); // Destructs a NetLogTempFile. | |
48 | |
49 // Accepts the button command and executes them. | |
50 void ProcessCommand(Command command); | |
51 | |
52 // Returns true and the path to the temporary file that needs to be sent via | |
53 // 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.
| |
54 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.
| |
55 | |
56 // Creates a Value summary of the state of the NetLogTempFile. The caller is | |
57 // responsible for deleting the returned value. | |
58 base::DictionaryValue* GetState(); | |
59 | |
60 private: | |
61 friend class ChromeNetLog; | |
62 friend class NetLogTempFileTest; | |
63 | |
64 // Allow tests to access our innards for testing purposes. | |
65 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, Init); | |
66 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, InitAllowStart); | |
67 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, InitAllowStartOrSend); | |
68 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, ProcessCommandDoStart); | |
69 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, ProcessCommandDoStop); | |
70 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, GetNetLogToSend); | |
71 | |
72 // This enum lists the possible state NetLogTempFile could be in. It is used | |
73 // to enable/disable "Start", "Stop" and "Send" (email) UI actions. | |
74 enum State { | |
75 STATE_UNINITIALIZED, | |
76 STATE_ALLOW_START, // Only DO_START Command is allowed. | |
77 STATE_ALLOW_STOP, // Only DO_STOP Command is allowed. | |
78 STATE_ALLOW_START_SEND, // Either DO_START or DO_SEND is allowed. | |
79 }; | |
80 | |
81 // Constructs a NetLogTempFile. Only one instance is created in | |
82 // browser process. | |
83 explicit NetLogTempFile(ChromeNetLog* chrome_net_log); | |
84 | |
85 // Initializes the |state_| to either ALLOW_START (if there is no temporary | |
86 // file from earlier run) or ALLOW_START_SEND (if there is a temporary file | |
87 // from earlier run). | |
88 void Init(); | |
89 | |
90 // Start collecting NetLog data into chrome-net-export/log.json file in | |
91 // file_util::GetTempDir() directory. It deletes all the temporary files that | |
92 // are in that directory before creating a new temporary file. It is a no-op | |
93 // if we are already collecting data into a file. | |
94 void StartNetLog(); | |
95 | |
96 // Stop collecting NetLog data into the temporary file. It is a no-op if we | |
97 // are not collecting data into a file. | |
98 void StopNetLog(); | |
99 | |
100 // Helper function for unit tests. | |
101 State state() const { return state_; } | |
102 void set_state(State state) { state_ = state; } | |
103 | |
104 FilePath log_path() const { return log_path_; } | |
105 | |
106 State state_; // Current state of NetLogTempFile. | |
107 | |
108 // Name of the file. It defaults to log.json, but can be overwritten by | |
109 // unittests. | |
110 FilePath::StringType log_filename_; | |
111 | |
112 FilePath log_path_; // FilePath to the temporary file. | |
113 | |
114 // |net_log_logger_| watches the NetLog event stream, and sends all entries to | |
115 // the file created in StartNetLog(). | |
116 scoped_ptr<NetLogLogger> net_log_logger_; | |
117 | |
118 // 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.
| |
119 // using global (g_browser_process). | |
120 ChromeNetLog* chrome_net_log_; | |
121 | |
122 DISALLOW_COPY_AND_ASSIGN(NetLogTempFile); | |
123 }; | |
124 | |
125 #endif // CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_ | |
OLD | NEW |