OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/tracing/crash_service_uploader.h" | 5 #include "chrome/browser/tracing/crash_service_uploader.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 const char kMultipartBoundary[] = | 36 const char kMultipartBoundary[] = |
37 "----**--yradnuoBgoLtrapitluMklaTelgooG--**----"; | 37 "----**--yradnuoBgoLtrapitluMklaTelgooG--**----"; |
38 const int kHttpResponseOk = 200; | 38 const int kHttpResponseOk = 200; |
39 | 39 |
40 } // namespace | 40 } // namespace |
41 | 41 |
42 TraceCrashServiceUploader::TraceCrashServiceUploader( | 42 TraceCrashServiceUploader::TraceCrashServiceUploader( |
43 net::URLRequestContextGetter* request_context) | 43 net::URLRequestContextGetter* request_context) |
44 : request_context_(request_context) { | 44 : request_context_(request_context) { |
45 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 45 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 46 const base::CommandLine& command_line = |
| 47 *base::CommandLine::ForCurrentProcess(); |
| 48 std::string upload_url = kUploadURL; |
| 49 if (command_line.HasSwitch(switches::kTraceUploadURL)) { |
| 50 upload_url = command_line.GetSwitchValueASCII(switches::kTraceUploadURL); |
| 51 } |
| 52 SetUploadURL(upload_url); |
46 } | 53 } |
47 | 54 |
48 TraceCrashServiceUploader::~TraceCrashServiceUploader() { | 55 TraceCrashServiceUploader::~TraceCrashServiceUploader() { |
49 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
50 } | 57 } |
51 | 58 |
| 59 void TraceCrashServiceUploader::SetUploadURL(const std::string& url) { |
| 60 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 61 upload_url_ = url; |
| 62 |
| 63 if (!GURL(upload_url_).is_valid()) |
| 64 upload_url_.clear(); |
| 65 } |
| 66 |
52 void TraceCrashServiceUploader::OnURLFetchComplete( | 67 void TraceCrashServiceUploader::OnURLFetchComplete( |
53 const net::URLFetcher* source) { | 68 const net::URLFetcher* source) { |
54 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 69 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
55 DCHECK_EQ(source, url_fetcher_.get()); | 70 DCHECK_EQ(source, url_fetcher_.get()); |
56 int response_code = source->GetResponseCode(); | 71 int response_code = source->GetResponseCode(); |
57 string feedback; | 72 string feedback; |
58 bool success = (response_code == kHttpResponseOk); | 73 bool success = (response_code == kHttpResponseOk); |
59 if (success) { | 74 if (success) { |
60 source->GetResponseAsString(&feedback); | 75 source->GetResponseAsString(&feedback); |
61 } else { | 76 } else { |
(...skipping 20 matching lines...) Expand all Loading... |
82 } | 97 } |
83 | 98 |
84 void TraceCrashServiceUploader::DoUpload( | 99 void TraceCrashServiceUploader::DoUpload( |
85 const std::string& file_contents, | 100 const std::string& file_contents, |
86 const UploadProgressCallback& progress_callback, | 101 const UploadProgressCallback& progress_callback, |
87 const UploadDoneCallback& done_callback) { | 102 const UploadDoneCallback& done_callback) { |
88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 103 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
89 content::BrowserThread::PostTask( | 104 content::BrowserThread::PostTask( |
90 content::BrowserThread::FILE, FROM_HERE, | 105 content::BrowserThread::FILE, FROM_HERE, |
91 base::Bind(&TraceCrashServiceUploader::DoUploadOnFileThread, | 106 base::Bind(&TraceCrashServiceUploader::DoUploadOnFileThread, |
92 base::Unretained(this), file_contents, progress_callback, | 107 base::Unretained(this), file_contents, upload_url_, |
93 done_callback)); | 108 progress_callback, done_callback)); |
94 } | 109 } |
95 | 110 |
96 void TraceCrashServiceUploader::DoUploadOnFileThread( | 111 void TraceCrashServiceUploader::DoUploadOnFileThread( |
97 const std::string& file_contents, | 112 const std::string& file_contents, |
| 113 const std::string& upload_url, |
98 const UploadProgressCallback& progress_callback, | 114 const UploadProgressCallback& progress_callback, |
99 const UploadDoneCallback& done_callback) { | 115 const UploadDoneCallback& done_callback) { |
100 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); | 116 DCHECK_CURRENTLY_ON(content::BrowserThread::FILE); |
101 DCHECK(!url_fetcher_.get()); | 117 DCHECK(!url_fetcher_.get()); |
102 | 118 |
103 progress_callback_ = progress_callback; | 119 progress_callback_ = progress_callback; |
104 done_callback_ = done_callback; | 120 done_callback_ = done_callback; |
105 | 121 |
106 const base::CommandLine& command_line = | |
107 *base::CommandLine::ForCurrentProcess(); | |
108 std::string upload_url = kUploadURL; | |
109 if (command_line.HasSwitch(switches::kTraceUploadURL)) { | |
110 upload_url = command_line.GetSwitchValueASCII(switches::kTraceUploadURL); | |
111 } | |
112 if (!GURL(upload_url).is_valid()) | |
113 upload_url.clear(); | |
114 | |
115 if (upload_url.empty()) { | 122 if (upload_url.empty()) { |
116 OnUploadError("Upload URL empty or invalid"); | 123 OnUploadError("Upload URL empty or invalid"); |
117 return; | 124 return; |
118 } | 125 } |
119 | 126 |
120 #if defined(OS_WIN) | 127 #if defined(OS_WIN) |
121 const char product[] = "Chrome"; | 128 const char product[] = "Chrome"; |
122 #elif defined(OS_MACOSX) | 129 #elif defined(OS_MACOSX) |
123 const char product[] = "Chrome_Mac"; | 130 const char product[] = "Chrome_Mac"; |
124 #elif defined(OS_LINUX) | 131 #elif defined(OS_LINUX) |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 std::string content_type = kUploadContentType; | 262 std::string content_type = kUploadContentType; |
256 content_type.append("; boundary="); | 263 content_type.append("; boundary="); |
257 content_type.append(kMultipartBoundary); | 264 content_type.append(kMultipartBoundary); |
258 | 265 |
259 url_fetcher_ = | 266 url_fetcher_ = |
260 net::URLFetcher::Create(GURL(upload_url), net::URLFetcher::POST, this); | 267 net::URLFetcher::Create(GURL(upload_url), net::URLFetcher::POST, this); |
261 url_fetcher_->SetRequestContext(request_context_); | 268 url_fetcher_->SetRequestContext(request_context_); |
262 url_fetcher_->SetUploadData(content_type, post_data); | 269 url_fetcher_->SetUploadData(content_type, post_data); |
263 url_fetcher_->Start(); | 270 url_fetcher_->Start(); |
264 } | 271 } |
OLD | NEW |