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

Side by Side Diff: chrome/browser/media/webrtc_log_uploader.cc

Issue 23691066: Hook up WebRTC logging extension API to the underlying functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: First patch ready for review. Created 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/media/webrtc_log_uploader.h" 5 #include "chrome/browser/media/webrtc_log_uploader.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 } 51 }
52 52
53 WebRtcLogUploader::~WebRtcLogUploader() {} 53 WebRtcLogUploader::~WebRtcLogUploader() {}
54 54
55 void WebRtcLogUploader::OnURLFetchComplete( 55 void WebRtcLogUploader::OnURLFetchComplete(
56 const net::URLFetcher* source) { 56 const net::URLFetcher* source) {
57 int response_code = source->GetResponseCode(); 57 int response_code = source->GetResponseCode();
58 std::string report_id; 58 std::string report_id;
59 if (response_code == 200 && source->GetResponseAsString(&report_id)) 59 if (response_code == 200 && source->GetResponseAsString(&report_id))
60 AddUploadedLogInfoToUploadListFile(report_id); 60 AddUploadedLogInfoToUploadListFile(report_id);
61 DCHECK(upload_done_data_.find(source) != upload_done_data_.end());
62 content::BrowserThread::PostTask(content::BrowserThread::IO, FROM_HERE,
63 base::Bind(&WebRtcLoggingHandlerHost::UploadLogDone,
64 upload_done_data_[source].host));
65 if (!upload_done_data_[source].callback.is_null()) {
66 bool success = response_code == 200;
67 std::string error_message;
68 if (!success) {
69 error_message = "Uploading failed, response code: " +
70 base::IntToString(response_code);
71 }
72 content::BrowserThread::PostTask(
73 content::BrowserThread::UI, FROM_HERE,
74 base::Bind(upload_done_data_[source].callback, success, report_id,
75 error_message));
76 }
77 upload_done_data_.erase(source);
61 } 78 }
62 79
63 void WebRtcLogUploader::OnURLFetchUploadProgress( 80 void WebRtcLogUploader::OnURLFetchUploadProgress(
64 const net::URLFetcher* source, int64 current, int64 total) { 81 const net::URLFetcher* source, int64 current, int64 total) {
65 } 82 }
66 83
67 bool WebRtcLogUploader::ApplyForStartLogging() { 84 bool WebRtcLogUploader::ApplyForStartLogging() {
68 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 85 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
69 if (log_count_ < kLogCountLimit) { 86 if (log_count_ < kLogCountLimit) {
70 ++log_count_; 87 ++log_count_;
71 return true; 88 return true;
72 } 89 }
73 return false; 90 return false;
74 } 91 }
75 92
76 void WebRtcLogUploader::UploadLog(net::URLRequestContextGetter* request_context, 93 void WebRtcLogUploader::LoggingStoppedDontUpload() {
77 scoped_ptr<base::SharedMemory> shared_memory, 94 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
78 uint32 length, 95 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this)));
79 const std::string& app_session_id, 96 }
80 const std::string& app_url) { 97
98 void WebRtcLogUploader::LoggingStoppedDoUpload(
99 net::URLRequestContextGetter* request_context,
100 scoped_ptr<base::SharedMemory> shared_memory,
101 uint32 length,
102 const std::map<std::string, std::string>& meta_data,
103 const std::string& app_url,
104 const WebRtcLogUploadDoneData& upload_done_data) {
81 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); 105 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE));
82 DCHECK(shared_memory); 106 DCHECK(shared_memory);
83 DCHECK(shared_memory->memory()); 107 DCHECK(shared_memory->memory());
84 108
85 std::string post_data; 109 std::string post_data;
86 SetupMultipart(&post_data, reinterpret_cast<uint8*>(shared_memory->memory()), 110 SetupMultipart(&post_data, reinterpret_cast<uint8*>(shared_memory->memory()),
87 length, app_session_id, app_url); 111 length, meta_data, app_url);
88 112
89 // If a test has set the test string pointer, write to it and skip uploading. 113 // If a test has set the test string pointer, write to it and skip uploading.
90 // This will be removed when the browser test for this feature is fully done 114 // This will be removed when the browser test for this feature is fully done
91 // according to the test plan. See http://crbug.com/257329. 115 // according to the test plan. See http://crbug.com/257329.
92 if (post_data_) { 116 if (post_data_) {
93 *post_data_ = post_data; 117 *post_data_ = post_data;
94 return; 118 return;
95 } 119 }
96 120
97 std::string content_type = kUploadContentType; 121 std::string content_type = kUploadContentType;
98 content_type.append("; boundary="); 122 content_type.append("; boundary=");
99 content_type.append(kMultipartBoundary); 123 content_type.append(kMultipartBoundary);
100 124
101 net::URLFetcher* url_fetcher = 125 net::URLFetcher* url_fetcher =
102 net::URLFetcher::Create(GURL(kUploadURL), net::URLFetcher::POST, this); 126 net::URLFetcher::Create(GURL(kUploadURL), net::URLFetcher::POST, this);
103 url_fetcher->SetRequestContext(request_context); 127 url_fetcher->SetRequestContext(request_context);
104 url_fetcher->SetUploadData(content_type, post_data); 128 url_fetcher->SetUploadData(content_type, post_data);
105 url_fetcher->Start(); 129 url_fetcher->Start();
130 upload_done_data_[url_fetcher] = upload_done_data;
106 131
107 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, 132 content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
108 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this))); 133 base::Bind(&WebRtcLogUploader::DecreaseLogCount, base::Unretained(this)));
109 } 134 }
110 135
111 void WebRtcLogUploader::SetupMultipart(std::string* post_data, 136 void WebRtcLogUploader::SetupMultipart(
112 uint8* log_buffer, 137 std::string* post_data, uint8* log_buffer, uint32 log_buffer_length,
113 uint32 log_buffer_length, 138 const std::map<std::string, std::string>& meta_data,
114 const std::string& app_session_id, 139 const std::string& app_url) {
115 const std::string& app_url) {
116 #if defined(OS_WIN) 140 #if defined(OS_WIN)
117 const char product[] = "Chrome"; 141 const char product[] = "Chrome";
118 #elif defined(OS_MACOSX) 142 #elif defined(OS_MACOSX)
119 const char product[] = "Chrome_Mac"; 143 const char product[] = "Chrome_Mac";
120 #elif defined(OS_LINUX) 144 #elif defined(OS_LINUX)
121 #if !defined(ADDRESS_SANITIZER) 145 #if !defined(ADDRESS_SANITIZER)
122 const char product[] = "Chrome_Linux"; 146 const char product[] = "Chrome_Linux";
123 #else 147 #else
124 const char product[] = "Chrome_Linux_ASan"; 148 const char product[] = "Chrome_Linux_ASan";
125 #endif 149 #endif
126 #elif defined(OS_ANDROID) 150 #elif defined(OS_ANDROID)
127 const char product[] = "Chrome_Android"; 151 const char product[] = "Chrome_Android";
128 #elif defined(OS_CHROMEOS) 152 #elif defined(OS_CHROMEOS)
129 const char product[] = "Chrome_ChromeOS"; 153 const char product[] = "Chrome_ChromeOS";
130 #else 154 #else
131 // This file should not be compiled for other platforms. 155 // This file should not be compiled for other platforms.
132 COMPILE_ASSERT(false); 156 COMPILE_ASSERT(false);
133 #endif 157 #endif
134 net::AddMultipartValueForUpload("prod", product, kMultipartBoundary, 158 net::AddMultipartValueForUpload("prod", product, kMultipartBoundary,
135 "", post_data); 159 "", post_data);
136 chrome::VersionInfo version_info; 160 chrome::VersionInfo version_info;
137 net::AddMultipartValueForUpload("ver", version_info.Version(), 161 net::AddMultipartValueForUpload("ver", version_info.Version(),
138 kMultipartBoundary, "", post_data); 162 kMultipartBoundary, "", post_data);
139 net::AddMultipartValueForUpload("guid", "0", kMultipartBoundary, 163 net::AddMultipartValueForUpload("guid", "0", kMultipartBoundary,
140 "", post_data); 164 "", post_data);
141 net::AddMultipartValueForUpload("type", "webrtc_log", kMultipartBoundary, 165 net::AddMultipartValueForUpload("type", "webrtc_log", kMultipartBoundary,
142 "", post_data); 166 "", post_data);
143 net::AddMultipartValueForUpload("app_session_id", app_session_id,
144 kMultipartBoundary, "", post_data);
145 net::AddMultipartValueForUpload("url", app_url, kMultipartBoundary, 167 net::AddMultipartValueForUpload("url", app_url, kMultipartBoundary,
146 "", post_data); 168 "", post_data);
169
170 // Add custom meta data.
171 std::map<std::string, std::string>::const_iterator it = meta_data.begin();
172 for (; it != meta_data.end(); ++it) {
173 net::AddMultipartValueForUpload(it->first, it->second, kMultipartBoundary,
174 "", post_data);
175 }
176
147 AddLogData(post_data, log_buffer, log_buffer_length); 177 AddLogData(post_data, log_buffer, log_buffer_length);
148 net::AddMultipartFinalDelimiterForUpload(kMultipartBoundary, post_data); 178 net::AddMultipartFinalDelimiterForUpload(kMultipartBoundary, post_data);
149 } 179 }
150 180
151 void WebRtcLogUploader::AddLogData(std::string* post_data, 181 void WebRtcLogUploader::AddLogData(std::string* post_data,
152 uint8* log_buffer, 182 uint8* log_buffer,
153 uint32 log_buffer_length) { 183 uint32 log_buffer_length) {
154 post_data->append("--"); 184 post_data->append("--");
155 post_data->append(kMultipartBoundary); 185 post_data->append(kMultipartBoundary);
156 post_data->append("\r\n"); 186 post_data->append("\r\n");
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 278
249 // Write the Unix time and report ID to the log list file. 279 // Write the Unix time and report ID to the log list file.
250 base::Time time_now = base::Time::Now(); 280 base::Time time_now = base::Time::Now();
251 contents += base::DoubleToString(time_now.ToDoubleT()) + 281 contents += base::DoubleToString(time_now.ToDoubleT()) +
252 "," + report_id + '\n'; 282 "," + report_id + '\n';
253 283
254 int written = file_util::WriteFile(upload_list_path_, &contents[0], 284 int written = file_util::WriteFile(upload_list_path_, &contents[0],
255 contents.size()); 285 contents.size());
256 DPCHECK(written == static_cast<int>(contents.size())); 286 DPCHECK(written == static_cast<int>(contents.size()));
257 } 287 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698