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

Unified Diff: chrome/browser/ui/webui/net_export_ui.cc

Issue 2698143004: Add ongoing events to net-export log when logging starts (Closed)
Patch Set: Forgot to update comment for StopNetLog() Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/net_export_ui.cc
diff --git a/chrome/browser/ui/webui/net_export_ui.cc b/chrome/browser/ui/webui/net_export_ui.cc
index 02368823ba6b87b7cd24f16eb5ccd3530e4e6219..f948bfe697f9c76f1ef7904c6e1e3f1cb46bd9ab 100644
--- a/chrome/browser/ui/webui/net_export_ui.cc
+++ b/chrome/browser/ui/webui/net_export_ui.cc
@@ -6,6 +6,7 @@
#include <memory>
#include <string>
+#include <vector>
#include "base/bind.h"
#include "base/lazy_instance.h"
@@ -17,6 +18,7 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/download/download_prefs.h"
+#include "chrome/browser/io_thread.h"
#include "chrome/browser/net/net_export_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/chrome_select_file_policy.h"
@@ -26,11 +28,13 @@
#include "components/net_log/net_export_ui_constants.h"
#include "components/net_log/net_log_file_writer.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/storage_partition.h"
#include "content/public/browser/url_data_source.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
+#include "extensions/features/features.h"
#include "net/log/net_log_capture_mode.h"
#include "net/url_request/url_request_context_getter.h"
#include "ui/shell_dialogs/select_file_dialog.h"
@@ -45,6 +49,40 @@ using content::WebUIMessageHandler;
namespace {
+class ProxyScriptFetcherContextGetter : public net::URLRequestContextGetter {
+ public:
+ explicit ProxyScriptFetcherContextGetter(IOThread* io_thread);
+
+ // net::URLRequestContextGetter implementation.
+ net::URLRequestContext* GetURLRequestContext() override;
+ scoped_refptr<base::SingleThreadTaskRunner> GetNetworkTaskRunner()
+ const override;
+
+ protected:
+ ~ProxyScriptFetcherContextGetter() override;
+
+ private:
+ IOThread* const io_thread_; // Owned by BrowserProcess.
+};
+
+ProxyScriptFetcherContextGetter::ProxyScriptFetcherContextGetter(
eroman 2017/02/22 02:03:29 [optional] My style suggestion here would be to in
wangyix1 2017/02/23 02:14:57 Done.
+ IOThread* io_thread)
+ : io_thread_(io_thread) {}
+
+ProxyScriptFetcherContextGetter::~ProxyScriptFetcherContextGetter() {}
+
+net::URLRequestContext*
+ProxyScriptFetcherContextGetter::GetURLRequestContext() {
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
+ DCHECK(io_thread_->globals()->proxy_script_fetcher_context.get());
+ return io_thread_->globals()->proxy_script_fetcher_context.get();
+}
+
+scoped_refptr<base::SingleThreadTaskRunner>
+ProxyScriptFetcherContextGetter::GetNetworkTaskRunner() const {
+ return BrowserThread::GetTaskRunnerForThread(BrowserThread::IO);
+}
+
// May only be accessed on the UI thread
base::LazyInstance<base::FilePath>::Leaky
last_save_dir = LAZY_INSTANCE_INITIALIZER;
@@ -98,6 +136,9 @@ class NetExportMessageHandler
void OnNewState(const base::DictionaryValue& state) override;
private:
+ using URLRequestContextGetterList =
+ std::vector<scoped_refptr<net::URLRequestContextGetter>>;
+
// Send NetLog data via email.
static void SendEmail(const base::FilePath& file_to_send);
@@ -121,6 +162,10 @@ class NetExportMessageHandler
// NetLog file.
void ShowSelectFileDialog(const base::FilePath& default_path);
+ // Returns a list of context getters used to retrieve ongoing events when
+ // logging starts so that net log entries can be added for those events.
+ URLRequestContextGetterList GetURLRequestContexts() const;
+
// Cache of g_browser_process->net_log()->net_log_file_writer(). This
// is owned by ChromeNetLog which is owned by BrowserProcessImpl.
net_log::NetLogFileWriter* file_writer_;
@@ -136,6 +181,11 @@ class NetExportMessageHandler
scoped_refptr<ui::SelectFileDialog> select_file_dialog_;
+ // A context getter for
+ // g_browser_process->io_thread()->globals()->proxy_script_fetcher_context.
+ scoped_refptr<net::URLRequestContextGetter>
+ proxy_script_fetcher_context_getter_;
eroman 2017/02/22 02:03:29 Please remove this variable (can be constructed di
wangyix1 2017/02/23 02:14:57 Done.
+
base::WeakPtrFactory<NetExportMessageHandler> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(NetExportMessageHandler);
@@ -144,6 +194,8 @@ class NetExportMessageHandler
NetExportMessageHandler::NetExportMessageHandler()
: file_writer_(g_browser_process->net_log()->net_log_file_writer()),
state_observer_manager_(this),
+ proxy_script_fetcher_context_getter_(
+ new ProxyScriptFetcherContextGetter(g_browser_process->io_thread())),
weak_ptr_factory_(this) {
file_writer_->Initialize(
BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE_USER_BLOCKING),
@@ -202,7 +254,8 @@ void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) {
net_log::NetLogFileWriter::CaptureModeFromString(capture_mode_string);
if (UsingMobileUI()) {
- file_writer_->StartNetLog(base::FilePath(), capture_mode_);
+ file_writer_->StartNetLog(base::FilePath(), capture_mode_,
+ GetURLRequestContexts());
} else {
base::FilePath initial_dir = last_save_dir.Pointer()->empty() ?
DownloadPrefs::FromBrowserContext(
@@ -254,7 +307,7 @@ void NetExportMessageHandler::FileSelected(const base::FilePath& path,
select_file_dialog_ = nullptr;
*last_save_dir.Pointer() = path.DirName();
- file_writer_->StartNetLog(path, capture_mode_);
+ file_writer_->StartNetLog(path, capture_mode_, GetURLRequestContexts());
}
void NetExportMessageHandler::FileSelectionCanceled(void* params) {
@@ -322,6 +375,26 @@ void NetExportMessageHandler::ShowSelectFileDialog(
&file_type_info, 0, base::FilePath::StringType(), owning_window, nullptr);
}
+NetExportMessageHandler::URLRequestContextGetterList
+NetExportMessageHandler::GetURLRequestContexts() const {
eroman 2017/02/22 02:03:29 Pelase add: DCHECK_CURRENTLY_ON(BrowserThread::UI)
wangyix1 2017/02/23 02:14:57 Done.
+ URLRequestContextGetterList context_getters;
+
+ Profile* profile = Profile::FromWebUI(web_ui());
+
+ context_getters.push_back(profile->GetRequestContext());
+ context_getters.push_back(
+ content::BrowserContext::GetDefaultStoragePartition(profile)
+ ->GetMediaURLRequestContext());
+#if BUILDFLAG(ENABLE_EXTENSIONS)
+ context_getters.push_back(profile->GetRequestContextForExtensions());
+#endif
+ context_getters.push_back(
+ g_browser_process->io_thread()->system_url_request_context_getter());
+ context_getters.push_back(proxy_script_fetcher_context_getter_);
+
+ return context_getters;
+}
+
} // namespace
NetExportUI::NetExportUI(content::WebUI* web_ui) : WebUIController(web_ui) {

Powered by Google App Engine
This is Rietveld 408576698