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

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

Powered by Google App Engine
This is Rietveld 408576698