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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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"
mmenke 2013/01/25 17:39:12 Don't think we need this.
ramant (doing other things) 2013/01/25 20:05:24 Done.
14 #include "base/memory/scoped_ptr.h"
15
16 namespace base {
17 class DictionaryValue;
18 }
19
20 class NetLogLogger;
21 class ChromeNetLog;
mmenke 2013/01/25 17:39:12 nit: Alphabetize.
ramant (doing other things) 2013/01/25 20:05:24 Done.
22
23 // NetLogTempFile logs all the NetLog entries into a temporary file
24 // "chrome-net-export-log.json" created 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_ == STATE_UNINITIALIZED).
31 // b) Only Stop is allowed (state_ == STATE_ALLOW_STOP).
32 // c) Either Send or Start is allowed (state_ == STATE_ALLOW_START_SEND).
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 virtual ~NetLogTempFile(); // Destructs a NetLogTempFile.
48
49 // Accepts the button command and executes it.
50 void ProcessCommand(Command command);
51
52 // Returns true and the path to the temporary file. If there is no file to
53 // send, then it returns false. It also returns false when actively logging to
54 // the file.
55 bool GetFilePath(FilePath* path);
56
57 // Creates a Value summary of the state of the NetLogTempFile. The caller is
58 // responsible for deleting the returned value.
59 base::DictionaryValue* GetState();
60
61 protected:
62 // Constructs a NetLogTempFile. Only one instance is created in browser
63 // process.
64 explicit NetLogTempFile(ChromeNetLog* chrome_net_log);
65
66 // Returns true if |log_path_| exists.
67 virtual bool NetExportLogExists();
68
69 private:
70 friend class ChromeNetLog;
71 friend class NetLogTempFileTest;
72
73 // Allow tests to access our innards for testing purposes.
74 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, Init);
75 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, InitAllowStart);
76 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, InitAllowStartOrSend);
77 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, ProcessCommandDoStartAndStop);
78 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, DoStartClearsFile);
79 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, CheckAddEvent);
80
81 // This enum lists the possible state NetLogTempFile could be in. It is used
82 // to enable/disable "Start", "Stop" and "Send" (email) UI actions.
83 enum State {
84 STATE_UNINITIALIZED,
85 STATE_ALLOW_START, // Only DO_START Command is allowed.
86 STATE_ALLOW_STOP, // Only DO_STOP Command is allowed.
87 STATE_ALLOW_START_SEND, // Either DO_START or DO_SEND is allowed.
88 };
89
90 // Initializes the |state_| to either STATE_ALLOW_START (if there is no
91 // temporary file from earlier run) or STATE_ALLOW_START_SEND (if there is a
92 // temporary file from earlier run). Returns false if initialization of
93 // |log_path_| fails.
94 bool Init();
95
96 // Start collecting NetLog data into chrome-net-export-log.json file in
97 // file_util::GetTempDir() directory. It is a no-op if we are already
98 // collecting data into a file.
99 void StartNetLog();
100
101 // Stop collecting NetLog data into the temporary file. It is a no-op if we
102 // are not collecting data into a file.
103 void StopNetLog();
104
105 // Updates |log_path_| with FilePath to |log_filename_| in the
106 // file_util::GetTempDir() directory. Returns false if file_util::GetTempDir()
107 // fails.
108 bool GetNetExportLog();
109
110 // Returns path name to file_util::GetTempDir() directory. Returns false if
111 // file_util::GetTempDir() fails.
112 bool GetNetExportLogDirectory(FilePath* path);
113
114 // Helper function for unit tests.
115 State state() const { return state_; }
116
117 State state_; // Current state of NetLogTempFile.
118
119 // Name of the file. It defaults to chrome-net-export-log.json, but can be
120 // overwritten by unit tests.
121 FilePath::StringType log_filename_;
122
123 FilePath log_path_; // FilePath to the temporary file.
124
125 // |net_log_logger_| watches the NetLog event stream, and sends all entries to
126 // the file created in StartNetLog().
127 scoped_ptr<NetLogLogger> net_log_logger_;
128
129 // The |chrome_net_log_| is owned by the browser process, cached here to avoid
130 // using global (g_browser_process).
131 ChromeNetLog* chrome_net_log_;
132
133 DISALLOW_COPY_AND_ASSIGN(NetLogTempFile);
134 };
135
136 #endif // CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698