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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/plugin.cc

Issue 61643022: Proxy private UMA pepper interface for out-of-process and NaCl plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove errant file, fix comment typo Created 7 years 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifdef _MSC_VER 5 #ifdef _MSC_VER
6 // Do not warn about use of std::copy with raw pointers. 6 // Do not warn about use of std::copy with raw pointers.
7 #pragma warning(disable : 4996) 7 #pragma warning(disable : 4996)
8 #endif 8 #endif
9 9
10 #include "ppapi/native_client/src/trusted/plugin/plugin.h" 10 #include "ppapi/native_client/src/trusted/plugin/plugin.h"
(...skipping 16 matching lines...) Expand all
27 #include "native_client/src/shared/platform/nacl_check.h" 27 #include "native_client/src/shared/platform/nacl_check.h"
28 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" 28 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
29 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" 29 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h"
30 #include "native_client/src/trusted/service_runtime/nacl_error_code.h" 30 #include "native_client/src/trusted/service_runtime/nacl_error_code.h"
31 31
32 #include "ppapi/c/pp_errors.h" 32 #include "ppapi/c/pp_errors.h"
33 #include "ppapi/c/ppb_console.h" 33 #include "ppapi/c/ppb_console.h"
34 #include "ppapi/c/ppb_var.h" 34 #include "ppapi/c/ppb_var.h"
35 #include "ppapi/c/ppp_instance.h" 35 #include "ppapi/c/ppp_instance.h"
36 #include "ppapi/c/private/ppb_nacl_private.h" 36 #include "ppapi/c/private/ppb_nacl_private.h"
37 #include "ppapi/c/private/ppb_uma_private.h"
38 #include "ppapi/cpp/dev/url_util_dev.h" 37 #include "ppapi/cpp/dev/url_util_dev.h"
39 #include "ppapi/cpp/module.h" 38 #include "ppapi/cpp/module.h"
40 #include "ppapi/cpp/text_input_controller.h" 39 #include "ppapi/cpp/text_input_controller.h"
41 40
42 #include "ppapi/native_client/src/trusted/plugin/file_utils.h" 41 #include "ppapi/native_client/src/trusted/plugin/file_utils.h"
43 #include "ppapi/native_client/src/trusted/plugin/json_manifest.h" 42 #include "ppapi/native_client/src/trusted/plugin/json_manifest.h"
44 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" 43 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h"
45 #include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h" 44 #include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h"
46 #include "ppapi/native_client/src/trusted/plugin/nexe_arch.h" 45 #include "ppapi/native_client/src/trusted/plugin/nexe_arch.h"
47 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h" 46 #include "ppapi/native_client/src/trusted/plugin/plugin_error.h"
(...skipping 23 matching lines...) Expand all
71 const size_t kNaClManifestMaxFileBytes = 1024 * 1024; 70 const size_t kNaClManifestMaxFileBytes = 1024 * 1024;
72 71
73 // Define an argument name to enable 'dev' interfaces. To make sure it doesn't 72 // Define an argument name to enable 'dev' interfaces. To make sure it doesn't
74 // collide with any user-defined HTML attribute, make the first character '@'. 73 // collide with any user-defined HTML attribute, make the first character '@'.
75 const char* const kDevAttribute = "@dev"; 74 const char* const kDevAttribute = "@dev";
76 75
77 // URL schemes that we treat in special ways. 76 // URL schemes that we treat in special ways.
78 const char* const kChromeExtensionUriScheme = "chrome-extension"; 77 const char* const kChromeExtensionUriScheme = "chrome-extension";
79 const char* const kDataUriScheme = "data"; 78 const char* const kDataUriScheme = "data";
80 79
80 const PPB_NaCl_Private* GetNaClInterface() {
81 pp::Module *module = pp::Module::Get();
82 CHECK(module);
83 return static_cast<const PPB_NaCl_Private*>(
84 module->GetBrowserInterface(PPB_NACL_PRIVATE_INTERFACE));
85 }
86
81 // Up to 20 seconds 87 // Up to 20 seconds
82 const int64_t kTimeSmallMin = 1; // in ms 88 const int64_t kTimeSmallMin = 1; // in ms
83 const int64_t kTimeSmallMax = 20000; // in ms 89 const int64_t kTimeSmallMax = 20000; // in ms
84 const uint32_t kTimeSmallBuckets = 100; 90 const uint32_t kTimeSmallBuckets = 100;
85 91
86 // Up to 3 minutes, 20 seconds 92 // Up to 3 minutes, 20 seconds
87 const int64_t kTimeMediumMin = 10; // in ms 93 const int64_t kTimeMediumMin = 10; // in ms
88 const int64_t kTimeMediumMax = 200000; // in ms 94 const int64_t kTimeMediumMax = 200000; // in ms
89 const uint32_t kTimeMediumBuckets = 100; 95 const uint32_t kTimeMediumBuckets = 100;
90 96
91 // Up to 33 minutes. 97 // Up to 33 minutes.
92 const int64_t kTimeLargeMin = 100; // in ms 98 const int64_t kTimeLargeMin = 100; // in ms
93 const int64_t kTimeLargeMax = 2000000; // in ms 99 const int64_t kTimeLargeMax = 2000000; // in ms
94 const uint32_t kTimeLargeBuckets = 100; 100 const uint32_t kTimeLargeBuckets = 100;
95 101
96 const int64_t kSizeKBMin = 1; 102 const int64_t kSizeKBMin = 1;
97 const int64_t kSizeKBMax = 512*1024; // very large .nexe 103 const int64_t kSizeKBMax = 512*1024; // very large .nexe
98 const uint32_t kSizeKBBuckets = 100; 104 const uint32_t kSizeKBBuckets = 100;
99 105
100 const PPB_NaCl_Private* GetNaClInterface() { 106 } // namespace
101 pp::Module *module = pp::Module::Get(); 107
102 CHECK(module); 108 void Plugin::HistogramTimeSmall(const std::string& name,
yzshen1 2013/12/04 19:32:51 Please keep the definitions in the same order as d
elijahtaylor1 2013/12/21 02:26:21 These Histogram functions were in the correct orde
yzshen1 2014/01/08 00:26:24 Yeah. It is good enough for me. Thanks! On 2013/12
103 return static_cast<const PPB_NaCl_Private*>( 109 int64_t ms) {
104 module->GetBrowserInterface(PPB_NACL_PRIVATE_INTERFACE)); 110 if (ms < 0) return;
111 uma_interface_.HistogramCustomTimes(name,
112 ms,
113 kTimeSmallMin, kTimeSmallMax,
114 kTimeSmallBuckets);
105 } 115 }
106 116
107 const PPB_UMA_Private* GetUMAInterface() { 117 void Plugin::HistogramTimeMedium(const std::string& name,
108 pp::Module *module = pp::Module::Get(); 118 int64_t ms) {
109 CHECK(module); 119 if (ms < 0) return;
110 return static_cast<const PPB_UMA_Private*>( 120 uma_interface_.HistogramCustomTimes(name,
111 module->GetBrowserInterface(PPB_UMA_PRIVATE_INTERFACE)); 121 ms,
122 kTimeMediumMin, kTimeMediumMax,
123 kTimeMediumBuckets);
112 } 124 }
113 125
114 void HistogramTimeSmall(const std::string& name, int64_t ms) { 126 void Plugin::HistogramTimeLarge(const std::string& name,
127 int64_t ms) {
115 if (ms < 0) return; 128 if (ms < 0) return;
116 129 uma_interface_.HistogramCustomTimes(name,
117 const PPB_UMA_Private* ptr = GetUMAInterface(); 130 ms,
118 if (ptr == NULL) return; 131 kTimeLargeMin, kTimeLargeMax,
119 132 kTimeLargeBuckets);
120 ptr->HistogramCustomTimes(pp::Var(name).pp_var(),
121 ms,
122 kTimeSmallMin, kTimeSmallMax,
123 kTimeSmallBuckets);
124 } 133 }
125 134
126 void HistogramTimeMedium(const std::string& name, int64_t ms) { 135 void Plugin::HistogramSizeKB(const std::string& name,
127 if (ms < 0) return; 136 int32_t sample) {
128 137 if (sample < 0) return;
129 const PPB_UMA_Private* ptr = GetUMAInterface(); 138 uma_interface_.HistogramCustomCounts(name,
130 if (ptr == NULL) return; 139 sample,
131 140 kSizeKBMin, kSizeKBMax,
132 ptr->HistogramCustomTimes(pp::Var(name).pp_var(), 141 kSizeKBBuckets);
133 ms,
134 kTimeMediumMin, kTimeMediumMax,
135 kTimeMediumBuckets);
136 } 142 }
137 143
138 void HistogramTimeLarge(const std::string& name, int64_t ms) { 144 void Plugin::HistogramEnumerate(const std::string& name,
139 if (ms < 0) return; 145 int sample,
140 146 int maximum,
141 const PPB_UMA_Private* ptr = GetUMAInterface(); 147 int out_of_range_replacement) {
142 if (ptr == NULL) return;
143
144 ptr->HistogramCustomTimes(pp::Var(name).pp_var(),
145 ms,
146 kTimeLargeMin, kTimeLargeMax,
147 kTimeLargeBuckets);
148 }
149
150 void HistogramSizeKB(const std::string& name, int32_t sample) {
151 if (sample < 0) return;
152
153 const PPB_UMA_Private* ptr = GetUMAInterface();
154 if (ptr == NULL) return;
155
156 ptr->HistogramCustomCounts(pp::Var(name).pp_var(),
157 sample,
158 kSizeKBMin, kSizeKBMax,
159 kSizeKBBuckets);
160 }
161
162 void HistogramEnumerate(const std::string& name, int sample, int maximum,
163 int out_of_range_replacement) {
164 if (sample < 0 || sample >= maximum) { 148 if (sample < 0 || sample >= maximum) {
165 if (out_of_range_replacement < 0) 149 if (out_of_range_replacement < 0)
166 // No replacement for bad input, abort. 150 // No replacement for bad input, abort.
167 return; 151 return;
168 else 152 else
169 // Use a specific value to signal a bad input. 153 // Use a specific value to signal a bad input.
170 sample = out_of_range_replacement; 154 sample = out_of_range_replacement;
171 } 155 }
172 const PPB_UMA_Private* ptr = GetUMAInterface(); 156 uma_interface_.HistogramEnumeration(name, sample, maximum);
173 if (ptr == NULL) return;
174 ptr->HistogramEnumeration(pp::Var(name).pp_var(), sample, maximum);
175 } 157 }
176 158
177 void HistogramEnumerateOsArch(const std::string& sandbox_isa) { 159 void Plugin::HistogramEnumerateOsArch(const std::string& sandbox_isa) {
178 enum NaClOSArch { 160 enum NaClOSArch {
179 kNaClLinux32 = 0, 161 kNaClLinux32 = 0,
180 kNaClLinux64, 162 kNaClLinux64,
181 kNaClLinuxArm, 163 kNaClLinuxArm,
182 kNaClMac32, 164 kNaClMac32,
183 kNaClMac64, 165 kNaClMac64,
184 kNaClMacArm, 166 kNaClMacArm,
185 kNaClWin32, 167 kNaClWin32,
186 kNaClWin64, 168 kNaClWin64,
187 kNaClWinArm, 169 kNaClWinArm,
(...skipping 10 matching lines...) Expand all
198 #endif 180 #endif
199 181
200 if (sandbox_isa == "x86-64") 182 if (sandbox_isa == "x86-64")
201 os_arch = static_cast<NaClOSArch>(os_arch + 1); 183 os_arch = static_cast<NaClOSArch>(os_arch + 1);
202 if (sandbox_isa == "arm") 184 if (sandbox_isa == "arm")
203 os_arch = static_cast<NaClOSArch>(os_arch + 2); 185 os_arch = static_cast<NaClOSArch>(os_arch + 2);
204 186
205 HistogramEnumerate("NaCl.Client.OSArch", os_arch, kNaClOSArchMax, -1); 187 HistogramEnumerate("NaCl.Client.OSArch", os_arch, kNaClOSArchMax, -1);
206 } 188 }
207 189
208 void HistogramEnumerateLoadStatus(PluginErrorCode error_code, 190 void Plugin::HistogramEnumerateLoadStatus(PluginErrorCode error_code,
209 bool is_installed) { 191 bool is_installed) {
210 HistogramEnumerate("NaCl.LoadStatus.Plugin", error_code, ERROR_MAX, 192 HistogramEnumerate("NaCl.LoadStatus.Plugin", error_code, ERROR_MAX,
211 ERROR_UNKNOWN); 193 ERROR_UNKNOWN);
212 194
213 // Gather data to see if being installed changes load outcomes. 195 // Gather data to see if being installed changes load outcomes.
214 const char* name = is_installed ? "NaCl.LoadStatus.Plugin.InstalledApp" : 196 const char* name = is_installed ? "NaCl.LoadStatus.Plugin.InstalledApp" :
215 "NaCl.LoadStatus.Plugin.NotInstalledApp"; 197 "NaCl.LoadStatus.Plugin.NotInstalledApp";
216 HistogramEnumerate(name, error_code, ERROR_MAX, 198 HistogramEnumerate(name, error_code, ERROR_MAX, ERROR_UNKNOWN);
217 ERROR_UNKNOWN);
218 } 199 }
219 200
220 void HistogramEnumerateSelLdrLoadStatus(NaClErrorCode error_code, 201 void Plugin::HistogramEnumerateSelLdrLoadStatus(NaClErrorCode error_code,
221 bool is_installed) { 202 bool is_installed) {
222 HistogramEnumerate("NaCl.LoadStatus.SelLdr", error_code, NACL_ERROR_CODE_MAX, 203 HistogramEnumerate("NaCl.LoadStatus.SelLdr", error_code,
223 LOAD_STATUS_UNKNOWN); 204 NACL_ERROR_CODE_MAX, LOAD_STATUS_UNKNOWN);
224 205
225 // Gather data to see if being installed changes load outcomes. 206 // Gather data to see if being installed changes load outcomes.
226 const char* name = is_installed ? "NaCl.LoadStatus.SelLdr.InstalledApp" : 207 const char* name = is_installed ? "NaCl.LoadStatus.SelLdr.InstalledApp" :
227 "NaCl.LoadStatus.SelLdr.NotInstalledApp"; 208 "NaCl.LoadStatus.SelLdr.NotInstalledApp";
228 HistogramEnumerate(name, error_code, NACL_ERROR_CODE_MAX, 209 HistogramEnumerate(name, error_code, NACL_ERROR_CODE_MAX,
229 LOAD_STATUS_UNKNOWN); 210 LOAD_STATUS_UNKNOWN);
230 } 211 }
231 212
232 void HistogramEnumerateManifestIsDataURI(bool is_data_uri) { 213 void Plugin::HistogramEnumerateManifestIsDataURI(bool is_data_uri) {
233 HistogramEnumerate("NaCl.Manifest.IsDataURI", is_data_uri, 2, -1); 214 HistogramEnumerate("NaCl.Manifest.IsDataURI", is_data_uri, 2, -1);
234 } 215 }
235 216
236 void HistogramHTTPStatusCode(const std::string& name, int status) { 217 void Plugin::HistogramHTTPStatusCode(const std::string& name,
218 int status) {
237 // Log the status codes in rough buckets - 1XX, 2XX, etc. 219 // Log the status codes in rough buckets - 1XX, 2XX, etc.
238 int sample = status / 100; 220 int sample = status / 100;
239 // HTTP status codes only go up to 5XX, using "6" to indicate an internal 221 // HTTP status codes only go up to 5XX, using "6" to indicate an internal
240 // error. 222 // error.
241 // Note: installed files may have "0" for a status code. 223 // Note: installed files may have "0" for a status code.
242 if (status < 0 || status >= 600) 224 if (status < 0 || status >= 600)
243 sample = 6; 225 sample = 6;
244 HistogramEnumerate(name, sample, 7, 6); 226 HistogramEnumerate(name, sample, 7, 6);
245 } 227 }
246 228
247 } // namespace
248
249 void Plugin::AddPropertyGet(const nacl::string& prop_name, 229 void Plugin::AddPropertyGet(const nacl::string& prop_name,
250 Plugin::PropertyGetter getter) { 230 Plugin::PropertyGetter getter) {
251 PLUGIN_PRINTF(("Plugin::AddPropertyGet (prop_name='%s')\n", 231 PLUGIN_PRINTF(("Plugin::AddPropertyGet (prop_name='%s')\n",
252 prop_name.c_str())); 232 prop_name.c_str()));
253 property_getters_[nacl::string(prop_name)] = getter; 233 property_getters_[nacl::string(prop_name)] = getter;
254 } 234 }
255 235
256 bool Plugin::HasProperty(const nacl::string& prop_name) { 236 bool Plugin::HasProperty(const nacl::string& prop_name) {
257 PLUGIN_PRINTF(("Plugin::HasProperty (prop_name=%s)\n", 237 PLUGIN_PRINTF(("Plugin::HasProperty (prop_name=%s)\n",
258 prop_name.c_str())); 238 prop_name.c_str()));
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 main_subprocess_("main subprocess", NULL, NULL), 674 main_subprocess_("main subprocess", NULL, NULL),
695 nacl_ready_state_(UNSENT), 675 nacl_ready_state_(UNSENT),
696 nexe_error_reported_(false), 676 nexe_error_reported_(false),
697 wrapper_factory_(NULL), 677 wrapper_factory_(NULL),
698 enable_dev_interfaces_(false), 678 enable_dev_interfaces_(false),
699 is_installed_(false), 679 is_installed_(false),
700 init_time_(0), 680 init_time_(0),
701 ready_time_(0), 681 ready_time_(0),
702 nexe_size_(0), 682 nexe_size_(0),
703 time_of_last_progress_event_(0), 683 time_of_last_progress_event_(0),
704 nacl_interface_(NULL) { 684 nacl_interface_(NULL),
685 uma_interface_(this) {
705 PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%" 686 PLUGIN_PRINTF(("Plugin::Plugin (this=%p, pp_instance=%"
706 NACL_PRId32 ")\n", static_cast<void*>(this), pp_instance)); 687 NACL_PRId32 ")\n", static_cast<void*>(this), pp_instance));
707 callback_factory_.Initialize(this); 688 callback_factory_.Initialize(this);
708 nexe_downloader_.Initialize(this); 689 nexe_downloader_.Initialize(this);
709 nacl_interface_ = GetNaClInterface(); 690 nacl_interface_ = GetNaClInterface();
710 CHECK(nacl_interface_ != NULL); 691 CHECK(nacl_interface_ != NULL);
711 } 692 }
712 693
713 694
714 Plugin::~Plugin() { 695 Plugin::~Plugin() {
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 EnqueueProgressEvent( 1329 EnqueueProgressEvent(
1349 PP_NACL_EVENT_LOAD, url, length_computable, loaded_bytes, total_bytes); 1330 PP_NACL_EVENT_LOAD, url, length_computable, loaded_bytes, total_bytes);
1350 EnqueueProgressEvent( 1331 EnqueueProgressEvent(
1351 PP_NACL_EVENT_LOADEND, url, length_computable, loaded_bytes, total_bytes); 1332 PP_NACL_EVENT_LOADEND, url, length_computable, loaded_bytes, total_bytes);
1352 1333
1353 // UMA 1334 // UMA
1354 HistogramEnumerateLoadStatus(ERROR_LOAD_SUCCESS, is_installed_); 1335 HistogramEnumerateLoadStatus(ERROR_LOAD_SUCCESS, is_installed_);
1355 } 1336 }
1356 1337
1357 1338
1358 // TODO(ncbray): report UMA stats
1359 void Plugin::ReportLoadError(const ErrorInfo& error_info) { 1339 void Plugin::ReportLoadError(const ErrorInfo& error_info) {
1360 PLUGIN_PRINTF(("Plugin::ReportLoadError (error='%s')\n", 1340 PLUGIN_PRINTF(("Plugin::ReportLoadError (error='%s')\n",
1361 error_info.message().c_str())); 1341 error_info.message().c_str()));
1362 // For errors the user (and not just the developer) should know about, 1342 // For errors the user (and not just the developer) should know about,
1363 // report them to the renderer so the browser can display a message. 1343 // report them to the renderer so the browser can display a message.
1364 if (error_info.error_code() == ERROR_MANIFEST_PROGRAM_MISSING_ARCH) { 1344 if (error_info.error_code() == ERROR_MANIFEST_PROGRAM_MISSING_ARCH) {
1365 // A special case: the manifest may otherwise be valid but is missing 1345 // A special case: the manifest may otherwise be valid but is missing
1366 // a program/file compatible with the user's sandbox. 1346 // a program/file compatible with the user's sandbox.
1367 nacl_interface()->ReportNaClError(pp_instance(), 1347 nacl_interface()->ReportNaClError(pp_instance(),
1368 PP_NACL_MANIFEST_MISSING_ARCH); 1348 PP_NACL_MANIFEST_MISSING_ARCH);
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 static_cast<uint32_t>(text.size())); 1579 static_cast<uint32_t>(text.size()));
1600 const PPB_Console* console_interface = 1580 const PPB_Console* console_interface =
1601 static_cast<const PPB_Console*>( 1581 static_cast<const PPB_Console*>(
1602 module->GetBrowserInterface(PPB_CONSOLE_INTERFACE)); 1582 module->GetBrowserInterface(PPB_CONSOLE_INTERFACE));
1603 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str); 1583 console_interface->LogWithSource(pp_instance(), PP_LOGLEVEL_LOG, prefix, str);
1604 var_interface->Release(prefix); 1584 var_interface->Release(prefix);
1605 var_interface->Release(str); 1585 var_interface->Release(str);
1606 } 1586 }
1607 1587
1608 } // namespace plugin 1588 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698