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

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: 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 VLOG(1) << "Plugin::NexeFileDidOpen (pp_error=" << pp_error << ")";
239 VLOG(1) << "Plugin::NexeFileDidOpen (file_desc=" << fd << ")";
240 HistogramHTTPStatusCode(
241 is_installed_ ? "NaCl.HttpStatusCodeClass.Nexe.InstalledApp" :
242 "NaCl.HttpStatusCodeClass.Nexe.NotInstalledApp",
243 http_status);
244 // TODO(dmichael): fd is only used for error reporting here currently, and
245 // the trusted Plugin is responsible for using it and closing it.
246 // Note -1 is NACL_NO_FILE_DESC from nacl_macros.h.
247 if (pp_error != PP_OK || fd == -1) {
248 if (pp_error == PP_ERROR_ABORTED) {
249 ReportLoadAbort();
250 } else if (pp_error == PP_ERROR_NOACCESS) {
251 ReportLoadError(PP_NACL_ERROR_NEXE_NOACCESS_URL,
252 "access to nexe url was denied.");
253 } else {
254 ReportLoadError(PP_NACL_ERROR_NEXE_LOAD_URL,
255 "could not load nexe url.");
256 }
257 return;
258 } else if (nexe_bytes_read == -1) {
259 ReportLoadError(PP_NACL_ERROR_NEXE_STAT, "could not stat nexe file.");
260 return;
261 }
262
263 // TODO(dmichael): Can we avoid stashing away so much state?
264 nexe_size_ = nexe_bytes_read;
265 HistogramSizeKB("NaCl.Perf.Size.Nexe",
266 static_cast<int32_t>(nexe_size_ / 1024));
267
268 // Inform JavaScript that we successfully downloaded the nacl module.
269 ProgressEvent progress_event(pp_instance_, PP_NACL_EVENT_PROGRESS, url, true,
270 nexe_size_, nexe_size_);
271 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask(
272 FROM_HERE,
273 base::Bind(&NexeLoadManager::DispatchEvent,
274 weak_factory_.GetWeakPtr(),
275 progress_event));
276 }
277
194 void NexeLoadManager::ReportLoadSuccess(const std::string& url, 278 void NexeLoadManager::ReportLoadSuccess(const std::string& url,
195 uint64_t loaded_bytes, 279 uint64_t loaded_bytes,
196 uint64_t total_bytes) { 280 uint64_t total_bytes) {
197 // Check that we are on the main renderer thread. 281 // Check that we are on the main renderer thread.
198 DCHECK(content::RenderThread::Get()); 282 DCHECK(content::RenderThread::Get());
199 set_nacl_ready_state(PP_NACL_READY_STATE_DONE); 283 set_nacl_ready_state(PP_NACL_READY_STATE_DONE);
200 284
201 // Inform JavaScript that loading was successful and is complete. 285 // Inform JavaScript that loading was successful and is complete.
202 ProgressEvent load_event(pp_instance_, PP_NACL_EVENT_LOAD, url, true, 286 ProgressEvent load_event(pp_instance_, PP_NACL_EVENT_LOAD, url, true,
203 loaded_bytes, total_bytes); 287 loaded_bytes, total_bytes);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 // to provide error handling. 517 // to provide error handling.
434 } 518 }
435 519
436 void NexeLoadManager::CopyCrashLogToJsConsole(const std::string& crash_log) { 520 void NexeLoadManager::CopyCrashLogToJsConsole(const std::string& crash_log) {
437 base::StringTokenizer t(crash_log, "\n"); 521 base::StringTokenizer t(crash_log, "\n");
438 while (t.GetNext()) 522 while (t.GetNext())
439 LogToConsole(t.token()); 523 LogToConsole(t.token());
440 } 524 }
441 525
442 } // namespace nacl 526 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698