Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / net_internals / net_internals_ui.cc
index 05b4db3..1a4f239 100644 (file)
 #include "base/strings/string_util.h"
 #include "base/strings/utf_string_conversions.h"
 #include "base/task/cancelable_task_tracker.h"
-#include "base/threading/worker_pool.h"
 #include "base/values.h"
 #include "chrome/browser/browser_process.h"
 #include "chrome/browser/browsing_data/browsing_data_helper.h"
 #include "chrome/browser/browsing_data/browsing_data_remover.h"
 #include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/download/download_prefs.h"
-#include "chrome/browser/extensions/extension_service.h"
 #include "chrome/browser/io_thread.h"
 #include "chrome/browser/net/chrome_net_log.h"
 #include "chrome/browser/net/chrome_network_delegate.h"
 #include "chrome/browser/prerender/prerender_manager.h"
 #include "chrome/browser/prerender/prerender_manager_factory.h"
 #include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/ui/webui/extensions/extension_basic_info.h"
 #include "chrome/common/chrome_paths.h"
 #include "chrome/common/chrome_version_info.h"
-#include "chrome/common/logging_chrome.h"
-#include "chrome/common/net/url_fixer_upper.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/common/url_constants.h"
 #include "components/onc/onc_constants.h"
+#include "components/url_fixer/url_fixer.h"
 #include "content/public/browser/browser_thread.h"
 #include "content/public/browser/notification_details.h"
 #include "content/public/browser/resource_dispatcher_host.h"
@@ -57,9 +53,6 @@
 #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/browser/extension_registry.h"
-#include "extensions/browser/extension_system.h"
-#include "extensions/common/extension_set.h"
 #include "grit/generated_resources.h"
 #include "grit/net_internals_resources.h"
 #include "net/base/net_errors.h"
 #include "net/proxy/proxy_service.h"
 #include "net/url_request/url_request_context.h"
 #include "net/url_request/url_request_context_getter.h"
-#include "ui/base/resource/resource_bundle.h"
 
 #if defined(OS_CHROMEOS)
-#include "chrome/browser/chromeos/login/user.h"
-#include "chrome/browser/chromeos/login/user_manager.h"
+#include "chrome/browser/chromeos/file_manager/filesystem_api_util.h"
 #include "chrome/browser/chromeos/net/onc_utils.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
 #include "chrome/browser/chromeos/system/syslogs_provider.h"
+#include "chrome/browser/chromeos/system_logs/debug_log_writer.h"
 #include "chrome/browser/net/nss_context.h"
 #include "chromeos/dbus/dbus_thread_manager.h"
 #include "chromeos/dbus/debug_daemon_client.h"
 #include "chromeos/network/onc/onc_certificate_importer_impl.h"
 #include "chromeos/network/onc/onc_utils.h"
+#include "components/user_manager/user.h"
 #endif
+
 #if defined(OS_WIN)
 #include "chrome/browser/net/service_providers_win.h"
 #endif
 
+#if defined(ENABLE_EXTENSIONS)
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/ui/webui/extensions/extension_basic_info.h"
+#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/extension_system.h"
+#include "extensions/common/extension_set.h"
+#endif
+
 using base::StringValue;
 using content::BrowserThread;
 using content::WebContents;
@@ -208,128 +211,6 @@ content::WebUIDataSource* CreateNetInternalsHTMLSource() {
   return source;
 }
 
-#if defined(OS_CHROMEOS)
-// Small helper class used to create temporary log file and pass its
-// handle and error status to callback.
-// Use case:
-// DebugLogFileHelper* helper = new DebugLogFileHelper();
-// base::WorkerPool::PostTaskAndReply(FROM_HERE,
-//     base::Bind(&DebugLogFileHelper::DoWork, base::Unretained(helper), ...),
-//     base::Bind(&DebugLogFileHelper::Reply, base::Owned(helper), ...),
-//     false);
-class DebugLogFileHelper {
- public:
-  typedef base::Callback<void(base::File file,
-                              const base::FilePath& file_path)>
-      DebugLogFileCallback;
-
-  DebugLogFileHelper() {}
-
-  ~DebugLogFileHelper() {}
-
-  void DoWork(const base::FilePath& fileshelf) {
-    const base::FilePath::CharType kLogFileName[] =
-        FILE_PATH_LITERAL("debug-log.tgz");
-
-    file_path_ = fileshelf.Append(kLogFileName);
-    file_path_ = logging::GenerateTimestampedName(file_path_,
-                                                  base::Time::Now());
-
-    int flags =  base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE;
-    file_.Initialize(file_path_, flags);
-  }
-
-  void Reply(const DebugLogFileCallback& callback) {
-    DCHECK(!callback.is_null());
-    callback.Run(file_.Pass(), file_path_);
-  }
-
- private:
-  base::File file_;
-  base::FilePath file_path_;
-
-  DISALLOW_COPY_AND_ASSIGN(DebugLogFileHelper);
-};
-
-// Following functions are used for getting debug logs. Logs are
-// fetched from /var/log/* and put on the fileshelf.
-
-// Called once StoreDebugLogs is complete. Takes two parameters:
-// - log_path: where the log file was saved in the case of success;
-// - succeeded: was the log file saved successfully.
-typedef base::Callback<void(const base::FilePath& log_path,
-                            bool succeded)> StoreDebugLogsCallback;
-
-// Closes file handle, so, should be called on the WorkerPool thread.
-void CloseDebugLogFile(base::File file) {
-  file.Close();
-}
-
-// Closes file handle and deletes debug log file, so, should be called
-// on the WorkerPool thread.
-void CloseAndDeleteDebugLogFile(base::File file,
-                                const base::FilePath& file_path) {
-  file.Close();
-  base::DeleteFile(file_path, false);
-}
-
-// Called upon completion of |WriteDebugLogToFile|. Closes file
-// descriptor, deletes log file in the case of failure and calls
-// |callback|.
-void WriteDebugLogToFileCompleted(const StoreDebugLogsCallback& callback,
-                                  base::File file,
-                                  const base::FilePath& file_path,
-                                  bool succeeded) {
-  DCHECK_CURRENTLY_ON(BrowserThread::UI);
-  if (!succeeded) {
-    bool posted = base::WorkerPool::PostTaskAndReply(FROM_HERE,
-        base::Bind(&CloseAndDeleteDebugLogFile, Passed(&file), file_path),
-        base::Bind(callback, file_path, false), false);
-    DCHECK(posted);
-    return;
-  }
-  bool posted = base::WorkerPool::PostTaskAndReply(FROM_HERE,
-      base::Bind(&CloseDebugLogFile, Passed(&file)),
-      base::Bind(callback, file_path, true), false);
-  DCHECK(posted);
-}
-
-// Stores into |file_path| debug logs in the .tgz format. Calls
-// |callback| upon completion.
-void WriteDebugLogToFile(const StoreDebugLogsCallback& callback,
-                         base::File file,
-                         const base::FilePath& file_path) {
-  DCHECK_CURRENTLY_ON(BrowserThread::UI);
-  if (!file.IsValid()) {
-    LOG(ERROR) <<
-        "Can't create debug log file: " << file_path.AsUTF8Unsafe() << ", " <<
-        "error: " << file.error_details();
-    return;
-  }
-  chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->GetDebugLogs(
-      file.GetPlatformFile(),
-      base::Bind(&WriteDebugLogToFileCompleted,
-                 callback, Passed(&file), file_path));
-}
-
-// Stores debug logs in the .tgz archive on the |fileshelf|. The file
-// is created on the worker pool, then writing to it is triggered from
-// the UI thread, and finally it is closed (on success) or deleted (on
-// failure) on the worker pool, prior to calling |callback|.
-void StoreDebugLogs(const base::FilePath& fileshelf,
-                    const StoreDebugLogsCallback& callback) {
-  DCHECK_CURRENTLY_ON(BrowserThread::UI);
-  DCHECK(!callback.is_null());
-  DebugLogFileHelper* helper = new DebugLogFileHelper();
-  bool posted = base::WorkerPool::PostTaskAndReply(FROM_HERE,
-      base::Bind(&DebugLogFileHelper::DoWork,
-          base::Unretained(helper), fileshelf),
-      base::Bind(&DebugLogFileHelper::Reply, base::Owned(helper),
-          base::Bind(&WriteDebugLogToFile, callback)), false);
-  DCHECK(posted);
-}
-#endif  // defined(OS_CHROMEOS)
-
 // This class receives javascript messages from the renderer.
 // Note that the WebUI infrastructure runs on the UI thread, therefore all of
 // this class's methods are expected to run on the UI thread.
@@ -521,7 +402,6 @@ class NetInternalsMessageHandler::IOThreadImpl
 #if defined(OS_WIN)
   void OnGetServiceProviders(const base::ListValue* list);
 #endif
-  void OnGetHttpPipeliningStatus(const base::ListValue* list);
   void OnSetLogLevel(const base::ListValue* list);
 
   // ChromeNetLog::ThreadSafeObserver implementation:
@@ -734,10 +614,6 @@ void NetInternalsMessageHandler::RegisterMessages() {
 #endif
 
   web_ui()->RegisterMessageCallback(
-      "getHttpPipeliningStatus",
-      base::Bind(&IOThreadImpl::CallbackHelper,
-                 &IOThreadImpl::OnGetHttpPipeliningStatus, proxy_));
-  web_ui()->RegisterMessageCallback(
       "setLogLevel",
       base::Bind(&IOThreadImpl::CallbackHelper,
                  &IOThreadImpl::OnSetLogLevel, proxy_));
@@ -838,6 +714,7 @@ void NetInternalsMessageHandler::OnGetExtensionInfo(
     const base::ListValue* list) {
   DCHECK_CURRENTLY_ON(BrowserThread::UI);
   base::ListValue* extension_list = new base::ListValue();
+#if defined(ENABLE_EXTENSIONS)
   Profile* profile = Profile::FromWebUI(web_ui());
   extensions::ExtensionSystem* extension_system =
       extensions::ExtensionSystem::Get(profile);
@@ -856,6 +733,7 @@ void NetInternalsMessageHandler::OnGetExtensionInfo(
       }
     }
   }
+#endif
   SendJavascriptCommand("receivedExtensionInfo", extension_list);
 }
 
@@ -1185,7 +1063,7 @@ void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTests(
 
   // Try to fix-up the user provided URL into something valid.
   // For example, turn "www.google.com" into "http://www.google.com".
-  GURL url(URLFixerUpper::FixupURL(base::UTF16ToUTF8(url_str), std::string()));
+  GURL url(url_fixer::FixupURL(base::UTF16ToUTF8(url_str), std::string()));
 
   connection_tester_.reset(new ConnectionTester(
       this,
@@ -1414,24 +1292,22 @@ void NetInternalsMessageHandler::IOThreadImpl::OnGetSpdyStatus(
   DCHECK(!list);
   base::DictionaryValue* status_dict = new base::DictionaryValue();
 
-  status_dict->Set("spdy_enabled",
-                   base::Value::CreateBooleanValue(
-                       net::HttpStreamFactory::spdy_enabled()));
-  status_dict->Set("use_alternate_protocols",
-                   base::Value::CreateBooleanValue(
-                       net::HttpStreamFactory::use_alternate_protocols()));
-  status_dict->Set("force_spdy_over_ssl",
-                   base::Value::CreateBooleanValue(
-                       net::HttpStreamFactory::force_spdy_over_ssl()));
-  status_dict->Set("force_spdy_always",
-                   base::Value::CreateBooleanValue(
-                       net::HttpStreamFactory::force_spdy_always()));
-
-  // The next_protos may not be specified for certain configurations of SPDY.
-  std::string next_protos_string;
-  if (net::HttpStreamFactory::has_next_protos()) {
-    next_protos_string = JoinString(net::HttpStreamFactory::next_protos(), ',');
-  }
+  net::HttpNetworkSession* http_network_session =
+      GetHttpNetworkSession(GetMainContext());
+
+  status_dict->SetBoolean("spdy_enabled",
+                          net::HttpStreamFactory::spdy_enabled());
+  status_dict->SetBoolean(
+      "use_alternate_protocols",
+      http_network_session->params().use_alternate_protocols);
+  status_dict->SetBoolean("force_spdy_over_ssl",
+                          http_network_session->params().force_spdy_over_ssl);
+  status_dict->SetBoolean("force_spdy_always",
+                          http_network_session->params().force_spdy_always);
+
+  std::vector<std::string> next_protos;
+  http_network_session->GetNextProtos(&next_protos);
+  std::string next_protos_string = JoinString(next_protos, ',');
   status_dict->SetString("next_protos", next_protos_string);
 
   SendJavascriptCommand("receivedSpdyStatus", status_dict);
@@ -1533,7 +1409,7 @@ void NetInternalsMessageHandler::ImportONCFileToNSSDB(
     const std::string& passcode,
     net::NSSCertDatabase* nssdb) {
   std::string error;
-  chromeos::User* user = chromeos::UserManager::Get()->GetUserByProfile(
+  user_manager::User* user = chromeos::ProfileHelper::Get()->GetUserByProfile(
       Profile::FromWebUI(web_ui()));
 
   if (user) {
@@ -1588,9 +1464,14 @@ void NetInternalsMessageHandler::OnStoreDebugLogs(const base::ListValue* list) {
 
   SendJavascriptCommand("receivedStoreDebugLogs",
                         new base::StringValue("Creating log file..."));
-  const DownloadPrefs* const prefs =
-      DownloadPrefs::FromBrowserContext(Profile::FromWebUI(web_ui()));
-  StoreDebugLogs(prefs->DownloadPath(),
+  Profile* profile = Profile::FromWebUI(web_ui());
+  const DownloadPrefs* const prefs = DownloadPrefs::FromBrowserContext(profile);
+  base::FilePath path = prefs->DownloadPath();
+  if (file_manager::util::IsUnderNonNativeLocalPath(profile, path))
+    path = prefs->GetDefaultDownloadDirectoryForProfile();
+  chromeos::DebugLogWriter::StoreLogs(
+      path,
+      true,  // should_compress
       base::Bind(&NetInternalsMessageHandler::OnStoreDebugLogsCompleted,
                  AsWeakPtr()));
 }
@@ -1633,63 +1514,6 @@ void NetInternalsMessageHandler::OnSetNetworkDebugModeCompleted(
 }
 #endif  // defined(OS_CHROMEOS)
 
-void NetInternalsMessageHandler::IOThreadImpl::OnGetHttpPipeliningStatus(
-    const base::ListValue* list) {
-  DCHECK(!list);
-  base::DictionaryValue* status_dict = new base::DictionaryValue();
-
-  base::Value* pipelined_connection_info = NULL;
-  net::HttpNetworkSession* http_network_session =
-      GetHttpNetworkSession(GetMainContext());
-  if (http_network_session) {
-    status_dict->Set("pipelining_enabled", base::Value::CreateBooleanValue(
-        http_network_session->params().http_pipelining_enabled));
-
-    pipelined_connection_info =
-        http_network_session->http_stream_factory()->PipelineInfoToValue();
-  }
-  status_dict->Set("pipelined_connection_info", pipelined_connection_info);
-
-  const net::HttpServerProperties& http_server_properties =
-      *GetMainContext()->http_server_properties();
-
-  // TODO(simonjam): This call is slow.
-  const net::PipelineCapabilityMap pipeline_capability_map =
-      http_server_properties.GetPipelineCapabilityMap();
-
-  base::ListValue* known_hosts_list = new base::ListValue();
-  net::PipelineCapabilityMap::const_iterator it;
-  for (it = pipeline_capability_map.begin();
-       it != pipeline_capability_map.end(); ++it) {
-    base::DictionaryValue* host_dict = new base::DictionaryValue();
-    host_dict->SetString("host", it->first.ToString());
-    std::string capability;
-    switch (it->second) {
-      case net::PIPELINE_CAPABLE:
-        capability = "capable";
-        break;
-
-      case net::PIPELINE_PROBABLY_CAPABLE:
-        capability = "probably capable";
-        break;
-
-      case net::PIPELINE_INCAPABLE:
-        capability = "incapable";
-        break;
-
-      case net::PIPELINE_UNKNOWN:
-      default:
-        capability = "unknown";
-        break;
-    }
-    host_dict->SetString("capability", capability);
-    known_hosts_list->Append(host_dict);
-  }
-  status_dict->Set("pipelined_host_info", known_hosts_list);
-
-  SendJavascriptCommand("receivedHttpPipeliningStatus", status_dict);
-}
-
 void NetInternalsMessageHandler::IOThreadImpl::OnSetLogLevel(
     const base::ListValue* list) {
   int log_level;