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

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

Issue 1380763003: [iOS] Integration of ChromeNetLog and NetExportUI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup whitelist Created 5 years, 2 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
« no previous file with comments | « ios/chrome/browser/ui/webui/net_export/net_export_ui.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/webui/net_export/net_export_ui.cc
diff --git a/chrome/browser/ui/webui/net_export_ui.cc b/ios/chrome/browser/ui/webui/net_export/net_export_ui.cc
similarity index 65%
copy from chrome/browser/ui/webui/net_export_ui.cc
copy to ios/chrome/browser/ui/webui/net_export/net_export_ui.cc
index e5f96eaf110698165d8b698ebfb5decd398e7d14..342ffebecc8e3582df139dc6c53309046e0cc5a2 100644
--- a/chrome/browser/ui/webui/net_export_ui.cc
+++ b/ios/chrome/browser/ui/webui/net_export/net_export_ui.cc
@@ -1,43 +1,36 @@
-// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/webui/net_export_ui.h"
+#include "ios/chrome/browser/ui/webui/net_export/net_export_ui.h"
#include <string>
#include "base/bind.h"
+#include "base/location.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/profiles/profile.h"
-#include "chrome/common/url_constants.h"
-#include "components/grit/components_resources.h"
#include "components/net_log/chrome_net_log.h"
#include "components/net_log/net_export_ui_constants.h"
#include "components/net_log/net_log_temp_file.h"
-#include "content/public/browser/browser_thread.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"
-
-#if defined(OS_ANDROID)
-#include "chrome/browser/android/intent_helper.h"
-#endif
-
-using content::BrowserThread;
-using content::WebContents;
-using content::WebUIMessageHandler;
+#include "grit/components_resources.h"
+#include "ios/chrome/browser/application_context.h"
+#include "ios/chrome/browser/chrome_url_constants.h"
+#include "ios/chrome/browser/ui/show_mail_composer_util.h"
+#include "ios/chrome/grit/ios_strings.h"
+#include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state.h"
+#include "ios/public/provider/web/web_ui_ios.h"
+#include "ios/public/provider/web/web_ui_ios_message_handler.h"
+#include "ios/web/public/web_thread.h"
+#include "ios/web/public/web_ui_ios_data_source.h"
namespace {
-content::WebUIDataSource* CreateNetExportHTMLSource() {
- content::WebUIDataSource* source =
- content::WebUIDataSource::Create(chrome::kChromeUINetExportHost);
+web::WebUIIOSDataSource* CreateNetExportHTMLSource() {
+ web::WebUIIOSDataSource* source =
+ web::WebUIIOSDataSource::Create(kChromeUINetExportHost);
source->SetJsonPath("strings.js");
source->AddResourcePath(net_log::kNetExportUIJS, IDR_NET_LOG_NET_EXPORT_JS);
@@ -50,7 +43,7 @@ content::WebUIDataSource* CreateNetExportHTMLSource() {
// this class's public methods are expected to run on the UI thread. All static
// functions except SendEmail run on FILE_USER_BLOCKING thread.
class NetExportMessageHandler
- : public WebUIMessageHandler,
+ : public web::WebUIIOSMessageHandler,
public base::SupportsWeakPtr<NetExportMessageHandler> {
public:
NetExportMessageHandler();
@@ -88,7 +81,7 @@ class NetExportMessageHandler
// renderer, passing in |arg|. Takes ownership of |arg|.
void OnExportNetLogInfoChanged(base::Value* arg);
- // Cache of g_browser_process->net_log()->net_log_temp_file().
+ // Cache of GetApplicationContex()->GetNetLog()->net_log_temp_file().
net_log::NetLogTempFile* net_log_temp_file_;
base::WeakPtrFactory<NetExportMessageHandler> weak_ptr_factory_;
@@ -97,20 +90,21 @@ class NetExportMessageHandler
};
NetExportMessageHandler::NetExportMessageHandler()
- : net_log_temp_file_(g_browser_process->net_log()->net_log_temp_file()),
- weak_ptr_factory_(this) {
-}
+ : net_log_temp_file_(GetApplicationContext()
+ ->GetNetLog()
+ ->net_log_temp_file()),
+ weak_ptr_factory_(this) {}
NetExportMessageHandler::~NetExportMessageHandler() {
// Cancel any in-progress requests to collect net_log into temporary file.
- BrowserThread::PostTask(BrowserThread::FILE_USER_BLOCKING, FROM_HERE,
- base::Bind(&net_log::NetLogTempFile::ProcessCommand,
- base::Unretained(net_log_temp_file_),
- net_log::NetLogTempFile::DO_STOP));
+ web::WebThread::PostTask(web::WebThread::FILE_USER_BLOCKING, FROM_HERE,
+ base::Bind(&net_log::NetLogTempFile::ProcessCommand,
+ base::Unretained(net_log_temp_file_),
+ net_log::NetLogTempFile::DO_STOP));
}
void NetExportMessageHandler::RegisterMessages() {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
web_ui()->RegisterMessageCallback(
net_log::kGetExportNetLogInfoHandler,
@@ -132,12 +126,10 @@ void NetExportMessageHandler::RegisterMessages() {
void NetExportMessageHandler::OnGetExportNetLogInfo(
const base::ListValue* list) {
- BrowserThread::PostTask(
- BrowserThread::FILE_USER_BLOCKING,
- FROM_HERE,
+ web::WebThread::PostTask(
+ web::WebThread::FILE_USER_BLOCKING, FROM_HERE,
base::Bind(&NetExportMessageHandler::SendExportNetLogInfo,
- weak_ptr_factory_.GetWeakPtr(),
- net_log_temp_file_));
+ weak_ptr_factory_.GetWeakPtr(), net_log_temp_file_));
}
void NetExportMessageHandler::OnStartNetLog(const base::ListValue* list) {
@@ -165,12 +157,11 @@ void NetExportMessageHandler::OnStopNetLog(const base::ListValue* list) {
}
void NetExportMessageHandler::OnSendNetLog(const base::ListValue* list) {
- content::BrowserThread::PostTaskAndReplyWithResult(
- content::BrowserThread::FILE_USER_BLOCKING,
- FROM_HERE,
- base::Bind(&NetExportMessageHandler::GetNetLogFileName,
- base::Unretained(net_log_temp_file_)),
- base::Bind(&NetExportMessageHandler::SendEmail));
+ web::WebThread::PostTaskAndReplyWithResult(
+ web::WebThread::FILE_USER_BLOCKING, FROM_HERE,
+ base::Bind(&NetExportMessageHandler::GetNetLogFileName,
+ base::Unretained(net_log_temp_file_)),
+ base::Bind(&NetExportMessageHandler::SendEmail));
}
// static
@@ -178,18 +169,15 @@ void NetExportMessageHandler::ProcessNetLogCommand(
base::WeakPtr<NetExportMessageHandler> net_export_message_handler,
net_log::NetLogTempFile* net_log_temp_file,
net_log::NetLogTempFile::Command command) {
- if (!BrowserThread::CurrentlyOn(BrowserThread::FILE_USER_BLOCKING)) {
- BrowserThread::PostTask(
- BrowserThread::FILE_USER_BLOCKING,
- FROM_HERE,
+ if (!web::WebThread::CurrentlyOn(web::WebThread::FILE_USER_BLOCKING)) {
+ web::WebThread::PostTask(
+ web::WebThread::FILE_USER_BLOCKING, FROM_HERE,
base::Bind(&NetExportMessageHandler::ProcessNetLogCommand,
- net_export_message_handler,
- net_log_temp_file,
- command));
+ net_export_message_handler, net_log_temp_file, command));
return;
}
- DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
+ DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::FILE_USER_BLOCKING);
net_log_temp_file->ProcessCommand(command);
SendExportNetLogInfo(net_export_message_handler, net_log_temp_file);
}
@@ -197,7 +185,7 @@ void NetExportMessageHandler::ProcessNetLogCommand(
// static
base::FilePath NetExportMessageHandler::GetNetLogFileName(
net_log::NetLogTempFile* net_log_temp_file) {
- DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
+ DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::FILE_USER_BLOCKING);
base::FilePath net_export_file_path;
net_log_temp_file->GetFilePath(&net_export_file_path);
return net_export_file_path;
@@ -207,13 +195,12 @@ base::FilePath NetExportMessageHandler::GetNetLogFileName(
void NetExportMessageHandler::SendExportNetLogInfo(
base::WeakPtr<NetExportMessageHandler> net_export_message_handler,
net_log::NetLogTempFile* net_log_temp_file) {
- DCHECK_CURRENTLY_ON(BrowserThread::FILE_USER_BLOCKING);
+ DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::FILE_USER_BLOCKING);
base::Value* value = net_log_temp_file->GetState();
- if (!BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&NetExportMessageHandler::OnExportNetLogInfoChanged,
- net_export_message_handler,
- value))) {
+ if (!web::WebThread::PostTask(
+ web::WebThread::UI, FROM_HERE,
+ base::Bind(&NetExportMessageHandler::OnExportNetLogInfoChanged,
+ net_export_message_handler, value))) {
// Failed posting the task, avoid leaking.
delete value;
}
@@ -223,34 +210,31 @@ void NetExportMessageHandler::SendExportNetLogInfo(
void NetExportMessageHandler::SendEmail(const base::FilePath& file_to_send) {
if (file_to_send.empty())
return;
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
-#if defined(OS_ANDROID)
std::string email;
std::string subject = "net_internals_log";
std::string title = "Issue number: ";
std::string body =
"Please add some informative text about the network issues.";
- base::FilePath::StringType file_to_attach(file_to_send.value());
- chrome::android::SendEmail(
- base::UTF8ToUTF16(email), base::UTF8ToUTF16(subject),
- base::UTF8ToUTF16(body), base::UTF8ToUTF16(title),
- base::UTF8ToUTF16(file_to_attach));
-#endif
+ ShowMailComposer(base::UTF8ToUTF16(email), base::UTF8ToUTF16(subject),
+ base::UTF8ToUTF16(body), base::UTF8ToUTF16(title),
+ file_to_send,
+ IDS_IOS_NET_EXPORT_NO_EMAIL_ACCOUNTS_ALERT_TITLE,
+ IDS_IOS_NET_EXPORT_NO_EMAIL_ACCOUNTS_ALERT_MESSAGE);
}
void NetExportMessageHandler::OnExportNetLogInfoChanged(base::Value* arg) {
scoped_ptr<base::Value> value(arg);
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ DCHECK_CURRENTLY_ON_WEB_THREAD(web::WebThread::UI);
web_ui()->CallJavascriptFunction(net_log::kOnExportNetLogInfoChanged, *arg);
}
} // namespace
-NetExportUI::NetExportUI(content::WebUI* web_ui) : WebUIController(web_ui) {
+NetExportUI::NetExportUI(web::WebUIIOS* web_ui)
+ : web::WebUIIOSController(web_ui) {
web_ui->AddMessageHandler(new NetExportMessageHandler());
-
- // Set up the chrome://net-export/ source.
- Profile* profile = Profile::FromWebUI(web_ui);
- content::WebUIDataSource::Add(profile, CreateNetExportHTMLSource());
+ web::WebUIIOSDataSource::Add(ios::ChromeBrowserState::FromWebUIIOS(web_ui),
+ CreateNetExportHTMLSource());
}
« no previous file with comments | « ios/chrome/browser/ui/webui/net_export/net_export_ui.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698