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

Side by Side Diff: components/net_log/net_log_temp_file.h

Issue 1347043002: Move ChromeNetLog to //components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 3 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
« no previous file with comments | « components/net_log/chrome_net_log.cc ('k') | components/net_log/net_log_temp_file.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_ 5 #ifndef COMPONENTS_NET_LOG_NET_LOG_TEMP_FILE_H_
6 #define CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_ 6 #define COMPONENTS_NET_LOG_NET_LOG_TEMP_FILE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/command_line.h"
11 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
12 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/threading/thread_checker.h"
14 #include "net/log/net_log.h" 16 #include "net/log/net_log.h"
15 17
16 namespace base { 18 namespace base {
17 class DictionaryValue; 19 class DictionaryValue;
18 } 20 }
19 21
20 namespace net { 22 namespace net {
21 class WriteToFileNetLogObserver; 23 class WriteToFileNetLogObserver;
22 } 24 }
23 25
26 namespace net_log {
27
24 class ChromeNetLog; 28 class ChromeNetLog;
25 29
26 // NetLogTempFile logs all the NetLog entries into a temporary file 30 // NetLogTempFile logs all the NetLog entries into a temporary file
27 // "chrome-net-export-log.json" created in base::GetTempDir() directory. 31 // "chrome-net-export-log.json" created in base::GetTempDir() directory.
28 // 32 //
29 // NetLogTempFile maintains the current logging state (state_) and log file type 33 // NetLogTempFile maintains the current logging state (state_) and log file type
30 // (log_type_) of the logging into a chrome-net-export-log.json file. 34 // (log_type_) of the logging into a chrome-net-export-log.json file.
31 // 35 //
32 // The following are the possible states 36 // The following are the possible states
33 // a) Only Start is allowed (STATE_NOT_LOGGING, LOG_TYPE_NONE). 37 // a) Only Start is allowed (STATE_NOT_LOGGING, LOG_TYPE_NONE).
34 // b) Only Stop is allowed (STATE_LOGGING). 38 // b) Only Stop is allowed (STATE_LOGGING).
35 // c) Either Send or Start is allowed (STATE_NOT_LOGGING, anything but 39 // c) Either Send or Start is allowed (STATE_NOT_LOGGING, anything but
36 // LOG_TYPE_NONE). 40 // LOG_TYPE_NONE).
37 // 41 //
38 // This is created/destroyed on the UI thread, but all other function calls 42 // This is created/destroyed on the main thread, but all other function calls
39 // occur on the FILE_USER_BLOCKING thread. 43 // occur on a background thread.
40 // 44 //
41 // This relies on the UI thread outlasting all other named threads for thread 45 // This relies on the UI thread outlasting all other threads for thread safety.
42 // safety.
43 class NetLogTempFile { 46 class NetLogTempFile {
44 public: 47 public:
45 // This enum lists the UI button commands it could receive. 48 // This enum lists the UI button commands it could receive.
46 enum Command { 49 enum Command {
47 DO_START_LOG_BYTES, // Call StartNetLog logging all bytes received. 50 DO_START_LOG_BYTES, // Call StartNetLog logging all bytes received.
48 DO_START, // Call StartNetLog. 51 DO_START, // Call StartNetLog.
49 DO_START_STRIP_PRIVATE_DATA, // Call StartNetLog stripping private data. 52 DO_START_STRIP_PRIVATE_DATA, // Call StartNetLog stripping private data.
50 DO_STOP, // Call StopNetLog. 53 DO_STOP, // Call StopNetLog.
51 }; 54 };
52 55
53 virtual ~NetLogTempFile(); 56 virtual ~NetLogTempFile();
54 57
55 // Accepts the button command and executes it. 58 // Accepts the button command and executes it.
56 void ProcessCommand(Command command); 59 void ProcessCommand(Command command);
57 60
58 // Returns true and the path to the temporary file. If there is no file to 61 // Returns true and the path to the temporary file. If there is no file to
59 // send, then it returns false. It also returns false when actively logging to 62 // send, then it returns false. It also returns false when actively logging to
60 // the file. 63 // the file.
61 bool GetFilePath(base::FilePath* path); 64 bool GetFilePath(base::FilePath* path);
62 65
63 // Creates a Value summary of the state of the NetLogTempFile. The caller is 66 // Creates a Value summary of the state of the NetLogTempFile. The caller is
64 // responsible for deleting the returned value. 67 // responsible for deleting the returned value.
65 base::DictionaryValue* GetState(); 68 base::DictionaryValue* GetState();
66 69
67 protected: 70 protected:
68 // Constructs a NetLogTempFile. Only one instance is created in browser 71 // Constructs a NetLogTempFile. Only one instance is created in browser
69 // process. 72 // process.
70 explicit NetLogTempFile(ChromeNetLog* chrome_net_log); 73 NetLogTempFile(ChromeNetLog* chrome_net_log,
74 const base::CommandLine::StringType& command_line_string,
75 const std::string& channel_string);
71 76
72 // Returns path name to base::GetTempDir() directory. Returns false if 77 // Returns path name to base::GetTempDir() directory. Returns false if
73 // base::GetTempDir() fails. 78 // base::GetTempDir() fails.
74 virtual bool GetNetExportLogBaseDirectory( 79 virtual bool GetNetExportLogBaseDirectory(base::FilePath* path) const;
75 base::FilePath* path) const;
76 80
77 private: 81 private:
78 friend class ChromeNetLog; 82 friend class ChromeNetLog;
79 friend class NetLogTempFileTest; 83 friend class NetLogTempFileTest;
80 84
81 // Allow tests to access our innards for testing purposes. 85 // Allow tests to access our innards for testing purposes.
82 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, EnsureInitFailure); 86 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, EnsureInitFailure);
83 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, EnsureInitAllowStart); 87 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, EnsureInitAllowStart);
84 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, EnsureInitAllowStartOrSend); 88 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, EnsureInitAllowStartOrSend);
85 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, ProcessCommandDoStartAndStop); 89 FRIEND_TEST_ALL_PREFIXES(NetLogTempFileTest, ProcessCommandDoStartAndStop);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 137
134 // Updates |log_path_| to be the base::FilePath to use for log files, which 138 // Updates |log_path_| to be the base::FilePath to use for log files, which
135 // will be inside the base::GetTempDir() directory. Returns false if 139 // will be inside the base::GetTempDir() directory. Returns false if
136 // base::GetTempDir() fails, or unable to create a subdirectory for logging 140 // base::GetTempDir() fails, or unable to create a subdirectory for logging
137 // withinh that directory. 141 // withinh that directory.
138 bool SetUpNetExportLogPath(); 142 bool SetUpNetExportLogPath();
139 143
140 // Returns true if a file exists at |log_path_|. 144 // Returns true if a file exists at |log_path_|.
141 bool NetExportLogExists() const; 145 bool NetExportLogExists() const;
142 146
147 base::ThreadChecker thread_checker_;
148
143 // Helper function for unit tests. 149 // Helper function for unit tests.
144 State state() const { return state_; } 150 State state() const { return state_; }
145 LogType log_type() const { return log_type_; } 151 LogType log_type() const { return log_type_; }
146 152
147 State state_; // Current state of NetLogTempFile. 153 State state_; // Current state of NetLogTempFile.
148 LogType log_type_; // Type of current log file on disk. 154 LogType log_type_; // Type of current log file on disk.
149 155
150 base::FilePath log_path_; // base::FilePath to the temporary file. 156 base::FilePath log_path_; // base::FilePath to the temporary file.
151 157
152 // |write_to_file_observer_| watches the NetLog event stream, and 158 // |write_to_file_observer_| watches the NetLog event stream, and
153 // sends all entries to the file created in StartNetLog(). 159 // sends all entries to the file created in StartNetLog().
154 scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_; 160 scoped_ptr<net::WriteToFileNetLogObserver> write_to_file_observer_;
155 161
156 // The |chrome_net_log_| is owned by the browser process, cached here to avoid 162 // The |chrome_net_log_| is owned by the browser process, cached here to avoid
157 // using global (g_browser_process). 163 // using global (g_browser_process).
158 ChromeNetLog* chrome_net_log_; 164 ChromeNetLog* chrome_net_log_;
159 165
166 const base::CommandLine::StringType command_line_string_;
167 const std::string channel_string_;
168
160 DISALLOW_COPY_AND_ASSIGN(NetLogTempFile); 169 DISALLOW_COPY_AND_ASSIGN(NetLogTempFile);
161 }; 170 };
162 171
163 #endif // CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_ 172 } // namespace net_log
173
174 #endif // COMPONENTS_NET_LOG_NET_LOG_TEMP_FILE_H_
OLDNEW
« no previous file with comments | « components/net_log/chrome_net_log.cc ('k') | components/net_log/net_log_temp_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698