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

Side by Side Diff: components/nacl/renderer/nexe_load_manager.cc

Issue 231243002: PPAPI: Move some of NexeFileDidOpen to NexeLoadManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix crash Created 6 years, 8 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 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 "components/nacl/renderer/nexe_load_manager.h" 5 #include "components/nacl/renderer/nexe_load_manager.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_tokenizer.h" 10 #include "base/strings/string_tokenizer.h"
(...skipping 22 matching lines...) Expand all
33 #include "third_party/WebKit/public/web/WebDOMResourceProgressEvent.h" 33 #include "third_party/WebKit/public/web/WebDOMResourceProgressEvent.h"
34 #include "third_party/WebKit/public/web/WebDocument.h" 34 #include "third_party/WebKit/public/web/WebDocument.h"
35 #include "third_party/WebKit/public/web/WebElement.h" 35 #include "third_party/WebKit/public/web/WebElement.h"
36 #include "third_party/WebKit/public/web/WebFrame.h" 36 #include "third_party/WebKit/public/web/WebFrame.h"
37 #include "third_party/WebKit/public/web/WebPluginContainer.h" 37 #include "third_party/WebKit/public/web/WebPluginContainer.h"
38 #include "third_party/WebKit/public/web/WebView.h" 38 #include "third_party/WebKit/public/web/WebView.h"
39 #include "v8/include/v8.h" 39 #include "v8/include/v8.h"
40 40
41 namespace { 41 namespace {
42 42
43 void HistogramCustomCounts(const std::string& name,
44 int32_t sample,
45 int32_t min,
46 int32_t max,
47 uint32_t bucket_count) {
48 base::HistogramBase* counter =
49 base::Histogram::FactoryGet(
50 name,
51 min,
52 max,
53 bucket_count,
54 base::HistogramBase::kUmaTargetedHistogramFlag);
55 // The histogram can be NULL if it is constructed with bad arguments. Ignore
56 // that data for this API. An error message will be logged.
57 if (counter)
58 counter->Add(sample);
59 }
60
43 void HistogramEnumerate(const std::string& name, 61 void HistogramEnumerate(const std::string& name,
44 int32_t sample, 62 int32_t sample,
45 int32_t boundary_value) { 63 int32_t boundary_value) {
46 base::HistogramBase* counter = 64 base::HistogramBase* counter =
47 base::LinearHistogram::FactoryGet( 65 base::LinearHistogram::FactoryGet(
48 name, 66 name,
49 1, 67 1,
50 boundary_value, 68 boundary_value,
51 boundary_value + 1, 69 boundary_value + 1,
52 base::HistogramBase::kUmaTargetedHistogramFlag); 70 base::HistogramBase::kUmaTargetedHistogramFlag);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 base::TimeDelta td, 146 base::TimeDelta td,
129 int64_t nexe_size) { 147 int64_t nexe_size) {
130 HistogramTimeMedium(name, static_cast<int64_t>(td.InMilliseconds())); 148 HistogramTimeMedium(name, static_cast<int64_t>(td.InMilliseconds()));
131 if (nexe_size > 0) { 149 if (nexe_size > 0) {
132 float size_in_MB = static_cast<float>(nexe_size) / (1024.f * 1024.f); 150 float size_in_MB = static_cast<float>(nexe_size) / (1024.f * 1024.f);
133 HistogramTimeMedium(name + "PerMB", 151 HistogramTimeMedium(name + "PerMB",
134 static_cast<int64_t>(td.InMilliseconds() / size_in_MB)); 152 static_cast<int64_t>(td.InMilliseconds() / size_in_MB));
135 } 153 }
136 } 154 }
137 155
156 void HistogramSizeKB(const std::string& name, int32_t sample) {
157 if (sample < 0) return;
158 HistogramCustomCounts(name,
159 sample,
160 1,
161 512 * 1024, // A very large .nexe.
162 100);
163 }
164
165 void HistogramHTTPStatusCode(const std::string& name,
166 int32_t status) {
167 // Log the status codes in rough buckets - 1XX, 2XX, etc.
168 int sample = status / 100;
169 // HTTP status codes only go up to 5XX, using "6" to indicate an internal
170 // error.
171 // Note: installed files may have "0" for a status code.
172 if (status < 0 || status >= 600)
173 sample = 6;
174 HistogramEnumerate(name, sample, 7);
175 }
176
138 blink::WebString EventTypeToString(PP_NaClEventType event_type) { 177 blink::WebString EventTypeToString(PP_NaClEventType event_type) {
139 switch (event_type) { 178 switch (event_type) {
140 case PP_NACL_EVENT_LOADSTART: 179 case PP_NACL_EVENT_LOADSTART:
141 return blink::WebString::fromUTF8("loadstart"); 180 return blink::WebString::fromUTF8("loadstart");
142 case PP_NACL_EVENT_PROGRESS: 181 case PP_NACL_EVENT_PROGRESS:
143 return blink::WebString::fromUTF8("progress"); 182 return blink::WebString::fromUTF8("progress");
144 case PP_NACL_EVENT_ERROR: 183 case PP_NACL_EVENT_ERROR:
145 return blink::WebString::fromUTF8("error"); 184 return blink::WebString::fromUTF8("error");
146 case PP_NACL_EVENT_ABORT: 185 case PP_NACL_EVENT_ABORT:
147 return blink::WebString::fromUTF8("abort"); 186 return blink::WebString::fromUTF8("abort");
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 HistogramEnumerateOsArch(GetSandboxArch()); 223 HistogramEnumerateOsArch(GetSandboxArch());
185 } 224 }
186 225
187 NexeLoadManager::~NexeLoadManager() { 226 NexeLoadManager::~NexeLoadManager() {
188 if (!nexe_error_reported_) { 227 if (!nexe_error_reported_) {
189 base::TimeDelta uptime = base::Time::Now() - ready_time_; 228 base::TimeDelta uptime = base::Time::Now() - ready_time_;
190 HistogramTimeLarge("NaCl.ModuleUptime.Normal", uptime.InMilliseconds()); 229 HistogramTimeLarge("NaCl.ModuleUptime.Normal", uptime.InMilliseconds());
191 } 230 }
192 } 231 }
193 232
233 void NexeLoadManager::NexeFileDidOpen(int32_t pp_error,
234 int32_t fd,
235 int32_t http_status,
236 int64_t nexe_bytes_read,
237 const std::string& url) {
238 // Check that we are on the main renderer thread.
239 DCHECK(content::RenderThread::Get());
240 VLOG(1) << "Plugin::NexeFileDidOpen (pp_error=" << pp_error << ")";
241 VLOG(1) << "Plugin::NexeFileDidOpen (file_desc=" << fd << ")";
242 HistogramHTTPStatusCode(
243 is_installed_ ? "NaCl.HttpStatusCodeClass.Nexe.InstalledApp" :
244 "NaCl.HttpStatusCodeClass.Nexe.NotInstalledApp",
245 http_status);
246 // TODO(dmichael): fd is only used for error reporting here currently, and
247 // the trusted Plugin is responsible for using it and closing it.
248 // Note -1 is NACL_NO_FILE_DESC from nacl_macros.h.
249 if (pp_error != PP_OK || fd == -1) {
250 if (pp_error == PP_ERROR_ABORTED) {
251 ReportLoadAbort();
252 } else if (pp_error == PP_ERROR_NOACCESS) {
253 ReportLoadError(PP_NACL_ERROR_NEXE_NOACCESS_URL,
254 "access to nexe url was denied.");
255 } else {
256 ReportLoadError(PP_NACL_ERROR_NEXE_LOAD_URL,
257 "could not load nexe url.");
258 }
259 return;
260 } else if (nexe_bytes_read == -1) {
261 ReportLoadError(PP_NACL_ERROR_NEXE_STAT, "could not stat nexe file.");
262 return;
263 }
264
265 // TODO(dmichael): Can we avoid stashing away so much state?
266 nexe_size_ = nexe_bytes_read;
267 HistogramSizeKB("NaCl.Perf.Size.Nexe",
268 static_cast<int32_t>(nexe_size_ / 1024));
269
270 // Inform JavaScript that we successfully downloaded the nacl module.
271 ProgressEvent progress_event(pp_instance_, PP_NACL_EVENT_PROGRESS, url, true,
272 nexe_size_, nexe_size_);
273 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
274 FROM_HERE,
275 base::Bind(&NexeLoadManager::DispatchEvent,
276 weak_factory_.GetWeakPtr(),
277 progress_event));
278 }
279
194 void NexeLoadManager::ReportLoadSuccess(const std::string& url, 280 void NexeLoadManager::ReportLoadSuccess(const std::string& url,
195 uint64_t loaded_bytes, 281 uint64_t loaded_bytes,
196 uint64_t total_bytes) { 282 uint64_t total_bytes) {
197 // Check that we are on the main renderer thread. 283 // Check that we are on the main renderer thread.
198 DCHECK(content::RenderThread::Get()); 284 DCHECK(content::RenderThread::Get());
199 set_nacl_ready_state(PP_NACL_READY_STATE_DONE); 285 set_nacl_ready_state(PP_NACL_READY_STATE_DONE);
200 286
201 // Inform JavaScript that loading was successful and is complete. 287 // Inform JavaScript that loading was successful and is complete.
202 ProgressEvent load_event(pp_instance_, PP_NACL_EVENT_LOAD, url, true, 288 ProgressEvent load_event(pp_instance_, PP_NACL_EVENT_LOAD, url, true,
203 loaded_bytes, total_bytes); 289 loaded_bytes, total_bytes);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 // to provide error handling. 519 // to provide error handling.
434 } 520 }
435 521
436 void NexeLoadManager::CopyCrashLogToJsConsole(const std::string& crash_log) { 522 void NexeLoadManager::CopyCrashLogToJsConsole(const std::string& crash_log) {
437 base::StringTokenizer t(crash_log, "\n"); 523 base::StringTokenizer t(crash_log, "\n");
438 while (t.GetNext()) 524 while (t.GetNext())
439 LogToConsole(t.token()); 525 LogToConsole(t.token());
440 } 526 }
441 527
442 } // namespace nacl 528 } // namespace nacl
OLDNEW
« no previous file with comments | « components/nacl/renderer/nexe_load_manager.h ('k') | components/nacl/renderer/ppb_nacl_private_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698