Index: content/browser/tracing/tracing_ui.cc |
diff --git a/content/browser/tracing/tracing_ui.cc b/content/browser/tracing/tracing_ui.cc |
index facad79f1939cffeb33b973759fe22b236995636..66ae8e8fe4ac6fcaa20feca8ba768d5526a3fc85 100644 |
--- a/content/browser/tracing/tracing_ui.cc |
+++ b/content/browser/tracing/tracing_ui.cc |
@@ -11,7 +11,6 @@ |
#include "base/base64.h" |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
-#include "base/command_line.h" |
#include "base/format_macros.h" |
#include "base/json/json_reader.h" |
#include "base/json/json_writer.h" |
@@ -23,23 +22,22 @@ |
#include "base/trace_event/trace_event.h" |
#include "base/values.h" |
#include "content/browser/tracing/grit/tracing_resources.h" |
-#include "content/browser/tracing/trace_uploader.h" |
#include "content/browser/tracing/tracing_controller_impl.h" |
#include "content/public/browser/browser_context.h" |
#include "content/public/browser/browser_thread.h" |
+#include "content/public/browser/content_browser_client.h" |
+#include "content/public/browser/trace_uploader.h" |
#include "content/public/browser/tracing_controller.h" |
+#include "content/public/browser/tracing_delegate.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/common/content_client.h" |
-#include "content/public/common/content_switches.h" |
#include "content/public/common/url_constants.h" |
namespace content { |
namespace { |
-const char kUploadURL[] = "https://clients2.google.com/cr/staging_report"; |
- |
void OnGotCategories(const WebUIDataSource::GotDataCallback& callback, |
const std::set<std::string>& categorySet) { |
scoped_ptr<base::ListValue> category_list(new base::ListValue()); |
@@ -281,6 +279,7 @@ bool OnTracingRequest(const std::string& path, |
TracingUI::TracingUI(WebUI* web_ui) |
: WebUIController(web_ui), |
+ delegate_(GetContentClient()->browser()->GetTracingDelegate()), |
weak_factory_(this) { |
web_ui->RegisterMessageCallback( |
"doUpload", |
@@ -309,27 +308,22 @@ void TracingUI::OnMonitoringStateChanged(bool is_monitoring) { |
} |
void TracingUI::DoUpload(const base::ListValue* args) { |
- const base::CommandLine& command_line = |
- *base::CommandLine::ForCurrentProcess(); |
- std::string upload_url = kUploadURL; |
- if (command_line.HasSwitch(switches::kTraceUploadURL)) { |
- upload_url = |
- command_line.GetSwitchValueASCII(switches::kTraceUploadURL); |
- } |
- if (!GURL(upload_url).is_valid()) { |
- upload_url.clear(); |
+ std::string file_contents; |
+ if (!args || args->empty() || !args->GetString(0, &file_contents)) { |
+ web_ui()->CallJavascriptFunction("onUploadError", |
+ base::StringValue("Missing data")); |
+ return; |
} |
- if (upload_url.empty()) { |
+ if (!delegate_) { |
web_ui()->CallJavascriptFunction("onUploadError", |
- base::StringValue("Upload URL empty or invalid")); |
+ base::StringValue("Not implemented")); |
return; |
} |
- std::string file_contents; |
- if (!args || args->empty() || !args->GetString(0, &file_contents)) { |
+ if (trace_uploader_) { |
web_ui()->CallJavascriptFunction("onUploadError", |
- base::StringValue("Missing data")); |
+ base::StringValue("Upload in progress")); |
return; |
} |
@@ -340,44 +334,10 @@ void TracingUI::DoUpload(const base::ListValue* args) { |
base::Bind(&TracingUI::OnTraceUploadComplete, |
weak_factory_.GetWeakPtr()); |
-#if defined(OS_WIN) |
- const char product[] = "Chrome"; |
-#elif defined(OS_MACOSX) |
- const char product[] = "Chrome_Mac"; |
-#elif defined(OS_LINUX) |
- const char product[] = "Chrome_Linux"; |
-#elif defined(OS_ANDROID) |
- const char product[] = "Chrome_Android"; |
-#elif defined(OS_CHROMEOS) |
- const char product[] = "Chrome_ChromeOS"; |
-#else |
-#error Platform not supported. |
-#endif |
- |
- // GetProduct() returns a string like "Chrome/aa.bb.cc.dd", split out |
- // the part before the "/". |
- std::vector<std::string> product_components; |
- base::SplitString(content::GetContentClient()->GetProduct(), '/', |
- &product_components); |
- DCHECK_EQ(2U, product_components.size()); |
- std::string version; |
- if (product_components.size() == 2U) { |
- version = product_components[1]; |
- } else { |
- version = "unknown"; |
- } |
- |
- BrowserContext* browser_context = |
- web_ui()->GetWebContents()->GetBrowserContext(); |
- TraceUploader* uploader = new TraceUploader( |
- product, version, upload_url, browser_context->GetRequestContext()); |
- |
- BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, base::Bind( |
- &TraceUploader::DoUpload, |
- base::Unretained(uploader), |
- file_contents, |
- progress_callback, |
- done_callback)); |
+ trace_uploader_ = delegate_->GetTraceUploader( |
+ web_ui()->GetWebContents()->GetBrowserContext()->GetRequestContext()); |
+ DCHECK(trace_uploader_); |
+ trace_uploader_->DoUpload(file_contents, progress_callback, done_callback); |
// TODO(mmandlis): Add support for stopping the upload in progress. |
} |
@@ -392,15 +352,15 @@ void TracingUI::OnTraceUploadProgress(int64 current, int64 total) { |
} |
void TracingUI::OnTraceUploadComplete(bool success, |
- const std::string& report_id, |
- const std::string& error_message) { |
+ const std::string& feedback) { |
if (success) { |
web_ui()->CallJavascriptFunction("onUploadComplete", |
- base::StringValue(report_id)); |
+ base::StringValue(feedback)); |
} else { |
web_ui()->CallJavascriptFunction("onUploadError", |
- base::StringValue(error_message)); |
+ base::StringValue(feedback)); |
} |
+ trace_uploader_.reset(); |
} |
} // namespace content |