| OLD | NEW |
| 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 CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_ |
| 6 #define CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_ | 6 #define CHROME_BROWSER_NET_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 | 14 |
| 15 namespace base { | 15 namespace base { |
| 16 class DictionaryValue; | 16 class DictionaryValue; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 class NetLogLogger; | 20 class NetLogLogger; |
| 21 } | 21 } |
| 22 | 22 |
| 23 class ChromeNetLog; | 23 class ChromeNetLog; |
| 24 | 24 |
| 25 // NetLogTempFile logs all the NetLog entries into a temporary file | 25 // NetLogTempFile logs all the NetLog entries into a temporary file |
| 26 // "chrome-net-export-log.json" created in file_util::GetTempDir() directory. | 26 // "chrome-net-export-log.json" created in base::GetTempDir() directory. |
| 27 // | 27 // |
| 28 // NetLogTempFile maintains the current state (state_) of the logging into a | 28 // NetLogTempFile maintains the current state (state_) of the logging into a |
| 29 // chrome-net-export-log.json file. | 29 // chrome-net-export-log.json file. |
| 30 // | 30 // |
| 31 // The following are the possible states | 31 // The following are the possible states |
| 32 // a) Only Start is allowed (state_ == STATE_UNINITIALIZED). | 32 // a) Only Start is allowed (state_ == STATE_UNINITIALIZED). |
| 33 // b) Only Stop is allowed (state_ == STATE_ALLOW_STOP). | 33 // b) Only Stop is allowed (state_ == STATE_ALLOW_STOP). |
| 34 // c) Either Send or Start is allowed (state_ == STATE_ALLOW_START_SEND). | 34 // c) Either Send or Start is allowed (state_ == STATE_ALLOW_START_SEND). |
| 35 // | 35 // |
| 36 // This is created/destroyed on the UI thread, but all other function calls | 36 // This is created/destroyed on the UI thread, but all other function calls |
| (...skipping 21 matching lines...) Expand all Loading... |
| 58 | 58 |
| 59 // Creates a Value summary of the state of the NetLogTempFile. The caller is | 59 // Creates a Value summary of the state of the NetLogTempFile. The caller is |
| 60 // responsible for deleting the returned value. | 60 // responsible for deleting the returned value. |
| 61 base::DictionaryValue* GetState(); | 61 base::DictionaryValue* GetState(); |
| 62 | 62 |
| 63 protected: | 63 protected: |
| 64 // Constructs a NetLogTempFile. Only one instance is created in browser | 64 // Constructs a NetLogTempFile. Only one instance is created in browser |
| 65 // process. | 65 // process. |
| 66 explicit NetLogTempFile(ChromeNetLog* chrome_net_log); | 66 explicit NetLogTempFile(ChromeNetLog* chrome_net_log); |
| 67 | 67 |
| 68 // Returns path name to file_util::GetTempDir() directory. Returns false if | 68 // Returns path name to base::GetTempDir() directory. Returns false if |
| 69 // file_util::GetTempDir() fails. | 69 // base::GetTempDir() fails. |
| 70 virtual bool GetNetExportLogDirectory(base::FilePath* path); | 70 virtual bool GetNetExportLogDirectory(base::FilePath* path); |
| 71 | 71 |
| 72 // Returns true if |log_path_| exists. | 72 // Returns true if |log_path_| exists. |
| 73 virtual bool NetExportLogExists(); | 73 virtual bool NetExportLogExists(); |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 friend class ChromeNetLog; | 76 friend class ChromeNetLog; |
| 77 friend class NetLogTempFileTest; | 77 friend class NetLogTempFileTest; |
| 78 | 78 |
| 79 // Allow tests to access our innards for testing purposes. | 79 // Allow tests to access our innards for testing purposes. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 93 STATE_ALLOW_START_SEND, // Either DO_START or DO_SEND is allowed. | 93 STATE_ALLOW_START_SEND, // Either DO_START or DO_SEND is allowed. |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 // Initializes the |state_| to either STATE_ALLOW_START (if there is no | 96 // Initializes the |state_| to either STATE_ALLOW_START (if there is no |
| 97 // temporary file from earlier run) or STATE_ALLOW_START_SEND (if there is a | 97 // temporary file from earlier run) or STATE_ALLOW_START_SEND (if there is a |
| 98 // temporary file from earlier run). Returns false if initialization of | 98 // temporary file from earlier run). Returns false if initialization of |
| 99 // |log_path_| fails. | 99 // |log_path_| fails. |
| 100 bool EnsureInit(); | 100 bool EnsureInit(); |
| 101 | 101 |
| 102 // Start collecting NetLog data into chrome-net-export-log.json file in | 102 // Start collecting NetLog data into chrome-net-export-log.json file in |
| 103 // file_util::GetTempDir() directory. It is a no-op if we are already | 103 // base::GetTempDir() directory. It is a no-op if we are already |
| 104 // collecting data into a file. | 104 // collecting data into a file. |
| 105 void StartNetLog(); | 105 void StartNetLog(); |
| 106 | 106 |
| 107 // Stop collecting NetLog data into the temporary file. It is a no-op if we | 107 // Stop collecting NetLog data into the temporary file. It is a no-op if we |
| 108 // are not collecting data into a file. | 108 // are not collecting data into a file. |
| 109 void StopNetLog(); | 109 void StopNetLog(); |
| 110 | 110 |
| 111 // Updates |log_path_| with base::FilePath to |log_filename_| in the | 111 // Updates |log_path_| with base::FilePath to |log_filename_| in the |
| 112 // file_util::GetTempDir() directory. Returns false if file_util::GetTempDir() | 112 // base::GetTempDir() directory. Returns false if base::GetTempDir() |
| 113 // fails. | 113 // fails. |
| 114 bool GetNetExportLog(); | 114 bool GetNetExportLog(); |
| 115 | 115 |
| 116 // Helper function for unit tests. | 116 // Helper function for unit tests. |
| 117 State state() const { return state_; } | 117 State state() const { return state_; } |
| 118 | 118 |
| 119 State state_; // Current state of NetLogTempFile. | 119 State state_; // Current state of NetLogTempFile. |
| 120 | 120 |
| 121 // Name of the file. It defaults to chrome-net-export-log.json, but can be | 121 // Name of the file. It defaults to chrome-net-export-log.json, but can be |
| 122 // overwritten by unit tests. | 122 // overwritten by unit tests. |
| 123 base::FilePath::StringType log_filename_; | 123 base::FilePath::StringType log_filename_; |
| 124 | 124 |
| 125 base::FilePath log_path_; // base::FilePath to the temporary file. | 125 base::FilePath log_path_; // base::FilePath to the temporary file. |
| 126 | 126 |
| 127 // |net_log_logger_| watches the NetLog event stream, and sends all entries to | 127 // |net_log_logger_| watches the NetLog event stream, and sends all entries to |
| 128 // the file created in StartNetLog(). | 128 // the file created in StartNetLog(). |
| 129 scoped_ptr<net::NetLogLogger> net_log_logger_; | 129 scoped_ptr<net::NetLogLogger> net_log_logger_; |
| 130 | 130 |
| 131 // The |chrome_net_log_| is owned by the browser process, cached here to avoid | 131 // The |chrome_net_log_| is owned by the browser process, cached here to avoid |
| 132 // using global (g_browser_process). | 132 // using global (g_browser_process). |
| 133 ChromeNetLog* chrome_net_log_; | 133 ChromeNetLog* chrome_net_log_; |
| 134 | 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(NetLogTempFile); | 135 DISALLOW_COPY_AND_ASSIGN(NetLogTempFile); |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 #endif // CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_ | 138 #endif // CHROME_BROWSER_NET_NET_LOG_TEMP_FILE_H_ |
| OLD | NEW |