diff options
author | elijahtaylor@chromium.org <elijahtaylor@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-21 22:44:01 +0000 |
---|---|---|
committer | elijahtaylor@chromium.org <elijahtaylor@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-21 22:44:01 +0000 |
commit | 1ef13cf522915b73185907981d10802f1e45fdb5 (patch) | |
tree | 3b98db85e311ff0ab99cfa03efb42215c10ad5be | |
parent | bca4951052ae6cea48d405eeb002de704de08cfa (diff) | |
download | chromium_src-1ef13cf522915b73185907981d10802f1e45fdb5.zip chromium_src-1ef13cf522915b73185907981d10802f1e45fdb5.tar.gz chromium_src-1ef13cf522915b73185907981d10802f1e45fdb5.tar.bz2 |
Add IsCrashReportingEnabled call to Pepper UMA API
This mirrors the existing metricsPrivate JS API.
BUG=341130
Review URL: https://codereview.chromium.org/195793026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258702 0039d316-1c4b-4281-b951-d872f2087c98
25 files changed, 255 insertions, 109 deletions
diff --git a/chrome/browser/extensions/api/metrics_private/metrics_private_api.cc b/chrome/browser/extensions/api/metrics_private/metrics_private_api.cc index deada1e..3265bb4 100644 --- a/chrome/browser/extensions/api/metrics_private/metrics_private_api.cc +++ b/chrome/browser/extensions/api/metrics_private/metrics_private_api.cc @@ -8,18 +8,12 @@ #include "base/metrics/field_trial.h" #include "base/metrics/histogram.h" -#include "base/prefs/pref_service.h" -#include "chrome/browser/browser_process.h" +#include "chrome/browser/metrics/metrics_service.h" #include "chrome/common/extensions/api/metrics_private.h" -#include "chrome/common/pref_names.h" #include "components/variations/variations_associated_data.h" #include "content/public/browser/user_metrics.h" #include "extensions/common/extension.h" -#if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/settings/cros_settings.h" -#endif // OS_CHROMEOS - namespace extensions { namespace GetIsCrashReportingEnabled = @@ -43,30 +37,9 @@ const size_t kMaxBuckets = 10000; // We don't ever want more than these many // and would cause crazy memory usage } // namespace -// Returns true if the user opted in to sending crash reports. -// TODO(vadimt): Unify with CrashesUI::CrashReportingUIEnabled -static bool IsCrashReportingEnabled() { -#if defined(GOOGLE_CHROME_BUILD) -#if defined(OS_CHROMEOS) - bool reporting_enabled = false; - chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, - &reporting_enabled); - return reporting_enabled; -#elif defined(OS_ANDROID) - // Android has its own settings for metrics / crash uploading. - PrefService* prefs = g_browser_process->local_state(); - return prefs->GetBoolean(prefs::kCrashReportingEnabled); -#else - PrefService* prefs = g_browser_process->local_state(); - return prefs->GetBoolean(prefs::kMetricsReportingEnabled); -#endif -#else - return false; -#endif -} - bool MetricsPrivateGetIsCrashReportingEnabledFunction::RunImpl() { - SetResult(new base::FundamentalValue(IsCrashReportingEnabled())); + SetResult(new base::FundamentalValue( + MetricsServiceHelper::IsCrashReportingEnabled())); return true; } diff --git a/chrome/browser/feedback/system_logs/log_sources/chrome_internal_log_source.cc b/chrome/browser/feedback/system_logs/log_sources/chrome_internal_log_source.cc index ebcc786..6db19b3 100644 --- a/chrome/browser/feedback/system_logs/log_sources/chrome_internal_log_source.cc +++ b/chrome/browser/feedback/system_logs/log_sources/chrome_internal_log_source.cc @@ -8,10 +8,10 @@ #include "base/sys_info.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/sync/about_sync_util.h" #include "chrome/browser/sync/profile_sync_service_factory.h" -#include "chrome/browser/ui/webui/crashes_ui.h" #include "chrome/common/chrome_version_info.h" #include "content/public/browser/browser_thread.h" #include "extensions/browser/extension_system.h" @@ -94,7 +94,7 @@ void ChromeInternalLogSource::PopulateSyncLogs(SystemLogsResponse* response) { void ChromeInternalLogSource::PopulateExtensionInfoLogs( SystemLogsResponse* response) { - if (!CrashesUI::CrashReportingUIEnabled()) + if (!MetricsServiceHelper::IsCrashReportingEnabled()) return; Profile* primary_profile = diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc index 80fa396..5f69919 100644 --- a/chrome/browser/metrics/metrics_service.cc +++ b/chrome/browser/metrics/metrics_service.cc @@ -233,6 +233,7 @@ #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/external_metrics.h" +#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chromeos/system/statistics_provider.h" #endif @@ -2068,3 +2069,22 @@ bool MetricsServiceHelper::IsMetricsReportingEnabled() { } return result; } + +bool MetricsServiceHelper::IsCrashReportingEnabled() { +#if defined(GOOGLE_CHROME_BUILD) +#if defined(OS_CHROMEOS) + bool reporting_enabled = false; + chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, + &reporting_enabled); + return reporting_enabled; +#elif defined(OS_ANDROID) + // Android has its own settings for metrics / crash uploading. + const PrefService* prefs = g_browser_process->local_state(); + return prefs->GetBoolean(prefs::kCrashReportingEnabled); +#else + return MetricsServiceHelper::IsMetricsReportingEnabled(); +#endif +#else + return false; +#endif +} diff --git a/chrome/browser/metrics/metrics_service.h b/chrome/browser/metrics/metrics_service.h index f1a2fb0..4ed9e04 100644 --- a/chrome/browser/metrics/metrics_service.h +++ b/chrome/browser/metrics/metrics_service.h @@ -42,6 +42,11 @@ class PrefRegistrySimple; class Profile; class TemplateURLService; +namespace { +class CrashesDOMHandler; +class FlashDOMHandler; +} + namespace base { class DictionaryValue; class MessageLoopProxy; @@ -60,6 +65,7 @@ struct WebPluginInfo; namespace extensions { class ExtensionDownloader; class ManifestFetchData; +class MetricsPrivateGetIsCrashReportingEnabledFunction; } namespace net { @@ -70,6 +76,10 @@ namespace prerender { bool IsOmniboxEnabled(Profile* profile); } +namespace system_logs { +class ChromeInternalLogSource; +} + namespace tracked_objects { struct ProcessDataSnapshot; } @@ -626,18 +636,30 @@ class MetricsService DISALLOW_COPY_AND_ASSIGN(MetricsService); }; -// This class limits and documents access to the IsMetricsReportingEnabled() -// method. Since the method is private, each user has to be explicitly declared -// as a 'friend' below. +// This class limits and documents access to the IsMetricsReportingEnabled() and +// IsCrashReportingEnabled() methods. Since these methods are private, each user +// has to be explicitly declared as a 'friend' below. class MetricsServiceHelper { private: friend bool prerender::IsOmniboxEnabled(Profile* profile); + friend class ChromeRenderMessageFilter; + friend class ::CrashesDOMHandler; friend class extensions::ExtensionDownloader; friend class extensions::ManifestFetchData; + friend class extensions::MetricsPrivateGetIsCrashReportingEnabledFunction; + friend class ::FlashDOMHandler; + friend class system_logs::ChromeInternalLogSource; + FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, MetricsReportingEnabled); + FRIEND_TEST_ALL_PREFIXES(MetricsServiceTest, CrashReportingEnabled); // Returns true if prefs::kMetricsReportingEnabled is set. static bool IsMetricsReportingEnabled(); + // Returns true if crash reporting is enabled. This is set at the platform + // level for Android and ChromeOS, and otherwise is the same as + // IsMetricsReportingEnabled for desktop Chrome. + static bool IsCrashReportingEnabled(); + DISALLOW_IMPLICIT_CONSTRUCTORS(MetricsServiceHelper); }; diff --git a/chrome/browser/metrics/metrics_service_unittest.cc b/chrome/browser/metrics/metrics_service_unittest.cc index 2d38c44..3ca255b 100644 --- a/chrome/browser/metrics/metrics_service_unittest.cc +++ b/chrome/browser/metrics/metrics_service_unittest.cc @@ -336,3 +336,41 @@ TEST_F(MetricsServiceTest, RegisterSyntheticTrial) { EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial3", "Group3")); service.log_manager_.FinishCurrentLog(); } + +TEST_F(MetricsServiceTest, MetricsReportingEnabled) { +#if !defined(OS_CHROMEOS) + GetLocalState()->SetBoolean(prefs::kMetricsReportingEnabled, false); + EXPECT_FALSE(MetricsServiceHelper::IsMetricsReportingEnabled()); + GetLocalState()->SetBoolean(prefs::kMetricsReportingEnabled, true); + EXPECT_TRUE(MetricsServiceHelper::IsMetricsReportingEnabled()); + GetLocalState()->ClearPref(prefs::kMetricsReportingEnabled); + EXPECT_FALSE(MetricsServiceHelper::IsMetricsReportingEnabled()); +#else + // ChromeOS does not register prefs::kMetricsReportingEnabled and uses + // device settings for metrics reporting. + EXPECT_FALSE(MetricsServiceHelper::IsMetricsReportingEnabled()); +#endif +} + + +TEST_F(MetricsServiceTest, CrashReportingEnabled) { +#if defined(GOOGLE_CHROME_BUILD) +// ChromeOS has different device settings for crash reporting. +#if !defined(OS_CHROMEOS) +#if defined(OS_ANDROID) + const char* crash_pref = prefs::kCrashReportingEnabled; +#else + const char* crash_pref = prefs::kMetricsReportingEnabled; +#endif + GetLocalState()->SetBoolean(crash_pref, false); + EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); + GetLocalState()->SetBoolean(crash_pref, true); + EXPECT_TRUE(MetricsServiceHelper::IsCrashReportingEnabled()); + GetLocalState()->ClearPref(crash_pref); + EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); +#endif // !defined(OS_CHROMEOS) +#else // defined(GOOGLE_CHROME_BUILD) + // Chromium branded browsers never have crash reporting enabled. + EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); +#endif // defined(GOOGLE_CHROME_BUILD) +} diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.cc b/chrome/browser/renderer_host/chrome_render_message_filter.cc index a077fd9..a20b731 100644 --- a/chrome/browser/renderer_host/chrome_render_message_filter.cc +++ b/chrome/browser/renderer_host/chrome_render_message_filter.cc @@ -19,6 +19,7 @@ #include "chrome/browser/extensions/activity_log/activity_log.h" #include "chrome/browser/extensions/api/activity_log_private/activity_log_private_api.h" #include "chrome/browser/extensions/api/messaging/message_service.h" +#include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/net/chrome_url_request_context.h" #include "chrome/browser/net/predictor.h" #include "chrome/browser/profiles/profile_manager.h" @@ -133,6 +134,8 @@ bool ChromeRenderMessageFilter::OnMessageReceived(const IPC::Message& message, OnCanTriggerClipboardRead) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_CanTriggerClipboardWrite, OnCanTriggerClipboardWrite) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_IsCrashReportingEnabled, + OnIsCrashReportingEnabled) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -493,3 +496,7 @@ void ChromeRenderMessageFilter::OnCanTriggerClipboardWrite( extension_info_map_->SecurityOriginHasAPIPermission( origin, render_process_id_, APIPermission::kClipboardWrite)); } + +void ChromeRenderMessageFilter::OnIsCrashReportingEnabled(bool* enabled) { + *enabled = MetricsServiceHelper::IsCrashReportingEnabled(); +} diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.h b/chrome/browser/renderer_host/chrome_render_message_filter.h index ffbb07c..1e8c527 100644 --- a/chrome/browser/renderer_host/chrome_render_message_filter.h +++ b/chrome/browser/renderer_host/chrome_render_message_filter.h @@ -166,6 +166,7 @@ class ChromeRenderMessageFilter : public content::BrowserMessageFilter { bool* allowed); void OnCanTriggerClipboardRead(const GURL& origin, bool* allowed); void OnCanTriggerClipboardWrite(const GURL& origin, bool* allowed); + void OnIsCrashReportingEnabled(bool* enabled); int render_process_id_; diff --git a/chrome/browser/ui/webui/crashes_ui.cc b/chrome/browser/ui/webui/crashes_ui.cc index 64fbfff..a2f1c61 100644 --- a/chrome/browser/ui/webui/crashes_ui.cc +++ b/chrome/browser/ui/webui/crashes_ui.cc @@ -10,14 +10,12 @@ #include "base/bind_helpers.h" #include "base/i18n/time_formatting.h" #include "base/memory/ref_counted_memory.h" -#include "base/prefs/pref_service.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" -#include "chrome/browser/browser_process.h" #include "chrome/browser/crash_upload_list.h" +#include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/chrome_version_info.h" -#include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" @@ -30,10 +28,6 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" -#if defined(OS_CHROMEOS) -#include "chrome/browser/chromeos/settings/cros_settings.h" -#endif - using content::WebContents; using content::WebUIMessageHandler; @@ -128,7 +122,8 @@ void CrashesDOMHandler::OnUploadListAvailable() { } void CrashesDOMHandler::UpdateUI() { - bool crash_reporting_enabled = CrashesUI::CrashReportingUIEnabled(); + bool crash_reporting_enabled = + MetricsServiceHelper::IsCrashReportingEnabled(); base::ListValue crash_list; if (crash_reporting_enabled) { @@ -175,24 +170,3 @@ base::RefCountedMemory* CrashesUI::GetFaviconResourceBytes( return ResourceBundle::GetSharedInstance(). LoadDataResourceBytesForScale(IDR_SAD_FAVICON, scale_factor); } - -// static -bool CrashesUI::CrashReportingUIEnabled() { -#if defined(GOOGLE_CHROME_BUILD) -#if defined(OS_CHROMEOS) - bool reporting_enabled = false; - chromeos::CrosSettings::Get()->GetBoolean(chromeos::kStatsReportingPref, - &reporting_enabled); - return reporting_enabled; -#elif defined(OS_ANDROID) - // Android has it's own setings for metrics / crash uploading. - PrefService* prefs = g_browser_process->local_state(); - return prefs->GetBoolean(prefs::kCrashReportingEnabled); -#else - PrefService* prefs = g_browser_process->local_state(); - return prefs->GetBoolean(prefs::kMetricsReportingEnabled); -#endif -#else - return false; -#endif -} diff --git a/chrome/browser/ui/webui/crashes_ui.h b/chrome/browser/ui/webui/crashes_ui.h index 47b12907..99a678c 100644 --- a/chrome/browser/ui/webui/crashes_ui.h +++ b/chrome/browser/ui/webui/crashes_ui.h @@ -19,9 +19,6 @@ class CrashesUI : public content::WebUIController { static base::RefCountedMemory* GetFaviconResourceBytes( ui::ScaleFactor scale_factor); - // Whether crash reporting UI has been enabled. - static bool CrashReportingUIEnabled(); - private: DISALLOW_COPY_AND_ASSIGN(CrashesUI); }; diff --git a/chrome/browser/ui/webui/flash_ui.cc b/chrome/browser/ui/webui/flash_ui.cc index 7809614..e9f1222 100644 --- a/chrome/browser/ui/webui/flash_ui.cc +++ b/chrome/browser/ui/webui/flash_ui.cc @@ -20,9 +20,9 @@ #include "base/timer/timer.h" #include "base/values.h" #include "chrome/browser/crash_upload_list.h" +#include "chrome/browser/metrics/metrics_service.h" #include "chrome/browser/plugins/plugin_prefs.h" #include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/webui/crashes_ui.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/url_constants.h" #include "content/public/browser/gpu_data_manager.h" @@ -298,7 +298,8 @@ void FlashDOMHandler::MaybeRespondToPage() { // Crash information. AddPair(list, base::string16(), "--- Crash data ---"); - bool crash_reporting_enabled = CrashesUI::CrashReportingUIEnabled(); + bool crash_reporting_enabled = + MetricsServiceHelper::IsCrashReportingEnabled(); if (crash_reporting_enabled) { std::vector<CrashUploadList::UploadInfo> crashes; upload_list_->GetUploads(10, &crashes); diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index d8e4d18..2967cfa 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -777,3 +777,7 @@ IPC_MESSAGE_ROUTED4(ChromeViewHostMsg_DetailedConsoleMessageAdded, base::string16 /* source */, extensions::StackTrace /* stack trace */, int32 /* severity level */) + +// Sent by the renderer to check if crash reporting is enabled. +IPC_SYNC_MESSAGE_CONTROL0_1(ChromeViewHostMsg_IsCrashReportingEnabled, + bool /* enabled */) diff --git a/chrome/renderer/pepper/pepper_uma_host.cc b/chrome/renderer/pepper/pepper_uma_host.cc index 7ecdcf9..c165928 100644 --- a/chrome/renderer/pepper/pepper_uma_host.cc +++ b/chrome/renderer/pepper/pepper_uma_host.cc @@ -8,7 +8,9 @@ #include "base/sha1.h" #include "base/strings/string_number_conversions.h" #include "chrome/common/chrome_switches.h" +#include "chrome/common/render_messages.h" #include "chrome/renderer/chrome_content_renderer_client.h" +#include "content/public/renderer/render_thread.h" #include "content/public/renderer/renderer_ppapi_host.h" #include "extensions/common/constants.h" #include "extensions/common/extension.h" @@ -65,19 +67,23 @@ int32_t PepperUMAHost::OnResourceMessageReceived( OnHistogramCustomCounts); PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UMA_HistogramEnumeration, OnHistogramEnumeration); + PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( + PpapiHostMsg_UMA_IsCrashReportingEnabled, OnIsCrashReportingEnabled); IPC_END_MESSAGE_MAP() return PP_ERROR_FAILED; } +bool PepperUMAHost::IsPluginWhitelisted() { + return ChromeContentRendererClient::IsExtensionOrSharedModuleWhitelisted( + document_url_, allowed_origins_); +} + bool PepperUMAHost::IsHistogramAllowed(const std::string& histogram) { if (is_plugin_in_process_ && histogram.find("NaCl.") == 0) { return true; } - bool is_whitelisted = - ChromeContentRendererClient::IsExtensionOrSharedModuleWhitelisted( - document_url_, allowed_origins_); - if (is_whitelisted && + if (IsPluginWhitelisted() && allowed_histogram_prefixes_.find(HashPrefix(histogram)) != allowed_histogram_prefixes_.end()) { return true; @@ -169,3 +175,15 @@ int32_t PepperUMAHost::OnHistogramEnumeration( return PP_OK; } +int32_t PepperUMAHost::OnIsCrashReportingEnabled( + ppapi::host::HostMessageContext* context) { + if (!IsPluginWhitelisted()) + return PP_ERROR_NOACCESS; + bool enabled = false; + content::RenderThread::Get()->Send( + new ChromeViewHostMsg_IsCrashReportingEnabled(&enabled)); + if (enabled) + return PP_OK; + return PP_ERROR_FAILED; +} + diff --git a/chrome/renderer/pepper/pepper_uma_host.h b/chrome/renderer/pepper/pepper_uma_host.h index 7039cce..a998128 100644 --- a/chrome/renderer/pepper/pepper_uma_host.h +++ b/chrome/renderer/pepper/pepper_uma_host.h @@ -37,6 +37,7 @@ class PepperUMAHost : public ppapi::host::ResourceHost { ppapi::host::HostMessageContext* context) OVERRIDE; private: + bool IsPluginWhitelisted(); bool IsHistogramAllowed(const std::string& histogram); int32_t OnHistogramCustomTimes( @@ -61,6 +62,9 @@ class PepperUMAHost : public ppapi::host::ResourceHost { int32_t sample, int32_t boundary_value); + int32_t OnIsCrashReportingEnabled( + ppapi::host::HostMessageContext* context); + const GURL document_url_; bool is_plugin_in_process_; diff --git a/ppapi/api/private/ppb_uma_private.idl b/ppapi/api/private/ppb_uma_private.idl index a115cee..2d9b950 100644 --- a/ppapi/api/private/ppb_uma_private.idl +++ b/ppapi/api/private/ppb_uma_private.idl @@ -10,7 +10,7 @@ [generate_thunk,thunk_include="ppapi/thunk/ppb_uma_singleton_api.h"] label Chrome { - M33 = 0.2 + M35 = 0.3 }; /** @@ -54,4 +54,14 @@ interface PPB_UMA_Private { [in] PP_Var name, [in] int32_t sample, [in] int32_t boundary_value); + + /** + * IsCrashReportingEnabled returns PP_OK to the completion callback to + * indicate that the current user has opted-in to crash reporting, or + * PP_ERROR_* on failure or when a user has not opted-in. This can be used to + * gate other reporting processes such as analytics and crash reporting. + */ + [singleton,api=PPB_UMA_Singleton_API] + int32_t IsCrashReportingEnabled([in] PP_Instance instance, + [in] PP_CompletionCallback callback); }; diff --git a/ppapi/c/private/ppb_uma_private.h b/ppapi/c/private/ppb_uma_private.h index c23ba99..04cad42 100644 --- a/ppapi/c/private/ppb_uma_private.h +++ b/ppapi/c/private/ppb_uma_private.h @@ -3,19 +3,20 @@ * found in the LICENSE file. */ -/* From private/ppb_uma_private.idl modified Mon Nov 18 14:39:43 2013. */ +/* From private/ppb_uma_private.idl modified Fri Mar 14 16:59:33 2014. */ #ifndef PPAPI_C_PRIVATE_PPB_UMA_PRIVATE_H_ #define PPAPI_C_PRIVATE_PPB_UMA_PRIVATE_H_ #include "ppapi/c/pp_bool.h" +#include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_instance.h" #include "ppapi/c/pp_macros.h" #include "ppapi/c/pp_stdint.h" #include "ppapi/c/pp_var.h" -#define PPB_UMA_PRIVATE_INTERFACE_0_2 "PPB_UMA_Private;0.2" -#define PPB_UMA_PRIVATE_INTERFACE PPB_UMA_PRIVATE_INTERFACE_0_2 +#define PPB_UMA_PRIVATE_INTERFACE_0_3 "PPB_UMA_Private;0.3" +#define PPB_UMA_PRIVATE_INTERFACE PPB_UMA_PRIVATE_INTERFACE_0_3 /** * @file @@ -30,7 +31,7 @@ /** * Contains functions for plugins to report UMA usage stats. */ -struct PPB_UMA_Private_0_2 { +struct PPB_UMA_Private_0_3 { /** * HistogramCustomTimes is a pointer to a function which records a time * sample given in milliseconds in the histogram given by |name|, possibly @@ -63,9 +64,17 @@ struct PPB_UMA_Private_0_2 { struct PP_Var name, int32_t sample, int32_t boundary_value); + /** + * IsCrashReportingEnabled returns PP_OK to the completion callback to + * indicate that the current user has opted-in to crash reporting, or + * PP_ERROR_* on failure or when a user has not opted-in. This can be used to + * gate other reporting processes such as analytics and crash reporting. + */ + int32_t (*IsCrashReportingEnabled)(PP_Instance instance, + struct PP_CompletionCallback callback); }; -typedef struct PPB_UMA_Private_0_2 PPB_UMA_Private; +typedef struct PPB_UMA_Private_0_3 PPB_UMA_Private; /** * @} */ diff --git a/ppapi/cpp/private/uma_private.cc b/ppapi/cpp/private/uma_private.cc index ed8b6e9..3ec0872 100644 --- a/ppapi/cpp/private/uma_private.cc +++ b/ppapi/cpp/private/uma_private.cc @@ -6,6 +6,7 @@ #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_uma_private.h" +#include "ppapi/cpp/completion_callback.h" #include "ppapi/cpp/module_impl.h" #include "ppapi/cpp/var.h" @@ -13,8 +14,8 @@ namespace pp { namespace { -template <> const char* interface_name<PPB_UMA_Private_0_2>() { - return PPB_UMA_PRIVATE_INTERFACE_0_2; +template <> const char* interface_name<PPB_UMA_Private_0_3>() { + return PPB_UMA_PRIVATE_INTERFACE_0_3; } } // namespace @@ -30,7 +31,7 @@ UMAPrivate::~UMAPrivate() { } bool UMAPrivate::IsAvailable() { - return has_interface<PPB_UMA_Private_0_2>(); + return has_interface<PPB_UMA_Private_0_3>(); } void UMAPrivate::HistogramCustomTimes(const std::string& name, @@ -40,7 +41,7 @@ void UMAPrivate::HistogramCustomTimes(const std::string& name, uint32_t bucket_count) { if (!IsAvailable()) return; - get_interface<PPB_UMA_Private_0_2>()-> + get_interface<PPB_UMA_Private_0_3>()-> HistogramCustomTimes(instance_, pp::Var(name).pp_var(), sample, min, max, bucket_count); } @@ -52,7 +53,7 @@ void UMAPrivate::HistogramCustomCounts(const std::string& name, uint32_t bucket_count) { if (!IsAvailable()) return; - get_interface<PPB_UMA_Private_0_2>()-> + get_interface<PPB_UMA_Private_0_3>()-> HistogramCustomCounts(instance_, pp::Var(name).pp_var(), sample, min, max, bucket_count); } @@ -62,9 +63,17 @@ void UMAPrivate::HistogramEnumeration(const std::string& name, int32_t boundary_value) { if (!IsAvailable()) return; - get_interface<PPB_UMA_Private_0_2>()-> + get_interface<PPB_UMA_Private_0_3>()-> HistogramEnumeration(instance_, pp::Var(name).pp_var(), sample, boundary_value); } +int32_t UMAPrivate::IsCrashReportingEnabled(const CompletionCallback& cc) { + if (!IsAvailable()) + return PP_ERROR_NOINTERFACE; + + return get_interface<PPB_UMA_Private_0_3>()-> + IsCrashReportingEnabled(instance_, cc.pp_completion_callback()); +} + } // namespace pp diff --git a/ppapi/cpp/private/uma_private.h b/ppapi/cpp/private/uma_private.h index 23de400..78d526d 100644 --- a/ppapi/cpp/private/uma_private.h +++ b/ppapi/cpp/private/uma_private.h @@ -12,6 +12,8 @@ namespace pp { +class CompletionCallback; + class UMAPrivate { public: UMAPrivate(); @@ -36,6 +38,8 @@ class UMAPrivate { int32_t sample, int32_t boundary_value); + int32_t IsCrashReportingEnabled(const CompletionCallback& cc); + private: PP_Instance instance_; }; diff --git a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c index 1a6fbb7..cdf6126 100644 --- a/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c +++ b/ppapi/native_client/src/untrusted/pnacl_irt_shim/pnacl_shim.c @@ -190,7 +190,7 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Testing_Private_1_0; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_UDPSocket_Private_0_2; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_UDPSocket_Private_0_3; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_UDPSocket_Private_0_4; -static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_UMA_Private_0_2; +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_UMA_Private_0_3; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_VideoDestination_Private_0_1; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_VideoSource_Private_0_1; static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_X509Certificate_Private_0_1; @@ -3839,24 +3839,29 @@ static void Pnacl_M23_PPB_UDPSocket_Private_Close(PP_Resource udp_socket) { /* End wrapper methods for PPB_UDPSocket_Private_0_4 */ -/* Begin wrapper methods for PPB_UMA_Private_0_2 */ +/* Begin wrapper methods for PPB_UMA_Private_0_3 */ -static void Pnacl_M33_PPB_UMA_Private_HistogramCustomTimes(PP_Instance instance, struct PP_Var* name, int64_t sample, int64_t min, int64_t max, uint32_t bucket_count) { - const struct PPB_UMA_Private_0_2 *iface = Pnacl_WrapperInfo_PPB_UMA_Private_0_2.real_iface; +static void Pnacl_M35_PPB_UMA_Private_HistogramCustomTimes(PP_Instance instance, struct PP_Var* name, int64_t sample, int64_t min, int64_t max, uint32_t bucket_count) { + const struct PPB_UMA_Private_0_3 *iface = Pnacl_WrapperInfo_PPB_UMA_Private_0_3.real_iface; iface->HistogramCustomTimes(instance, *name, sample, min, max, bucket_count); } -static void Pnacl_M33_PPB_UMA_Private_HistogramCustomCounts(PP_Instance instance, struct PP_Var* name, int32_t sample, int32_t min, int32_t max, uint32_t bucket_count) { - const struct PPB_UMA_Private_0_2 *iface = Pnacl_WrapperInfo_PPB_UMA_Private_0_2.real_iface; +static void Pnacl_M35_PPB_UMA_Private_HistogramCustomCounts(PP_Instance instance, struct PP_Var* name, int32_t sample, int32_t min, int32_t max, uint32_t bucket_count) { + const struct PPB_UMA_Private_0_3 *iface = Pnacl_WrapperInfo_PPB_UMA_Private_0_3.real_iface; iface->HistogramCustomCounts(instance, *name, sample, min, max, bucket_count); } -static void Pnacl_M33_PPB_UMA_Private_HistogramEnumeration(PP_Instance instance, struct PP_Var* name, int32_t sample, int32_t boundary_value) { - const struct PPB_UMA_Private_0_2 *iface = Pnacl_WrapperInfo_PPB_UMA_Private_0_2.real_iface; +static void Pnacl_M35_PPB_UMA_Private_HistogramEnumeration(PP_Instance instance, struct PP_Var* name, int32_t sample, int32_t boundary_value) { + const struct PPB_UMA_Private_0_3 *iface = Pnacl_WrapperInfo_PPB_UMA_Private_0_3.real_iface; iface->HistogramEnumeration(instance, *name, sample, boundary_value); } -/* End wrapper methods for PPB_UMA_Private_0_2 */ +static int32_t Pnacl_M35_PPB_UMA_Private_IsCrashReportingEnabled(PP_Instance instance, struct PP_CompletionCallback* callback) { + const struct PPB_UMA_Private_0_3 *iface = Pnacl_WrapperInfo_PPB_UMA_Private_0_3.real_iface; + return iface->IsCrashReportingEnabled(instance, *callback); +} + +/* End wrapper methods for PPB_UMA_Private_0_3 */ /* Begin wrapper methods for PPB_VideoDestination_Private_0_1 */ @@ -5252,10 +5257,11 @@ static const struct PPB_UDPSocket_Private_0_4 Pnacl_Wrappers_PPB_UDPSocket_Priva .Close = (void (*)(PP_Resource udp_socket))&Pnacl_M23_PPB_UDPSocket_Private_Close }; -static const struct PPB_UMA_Private_0_2 Pnacl_Wrappers_PPB_UMA_Private_0_2 = { - .HistogramCustomTimes = (void (*)(PP_Instance instance, struct PP_Var name, int64_t sample, int64_t min, int64_t max, uint32_t bucket_count))&Pnacl_M33_PPB_UMA_Private_HistogramCustomTimes, - .HistogramCustomCounts = (void (*)(PP_Instance instance, struct PP_Var name, int32_t sample, int32_t min, int32_t max, uint32_t bucket_count))&Pnacl_M33_PPB_UMA_Private_HistogramCustomCounts, - .HistogramEnumeration = (void (*)(PP_Instance instance, struct PP_Var name, int32_t sample, int32_t boundary_value))&Pnacl_M33_PPB_UMA_Private_HistogramEnumeration +static const struct PPB_UMA_Private_0_3 Pnacl_Wrappers_PPB_UMA_Private_0_3 = { + .HistogramCustomTimes = (void (*)(PP_Instance instance, struct PP_Var name, int64_t sample, int64_t min, int64_t max, uint32_t bucket_count))&Pnacl_M35_PPB_UMA_Private_HistogramCustomTimes, + .HistogramCustomCounts = (void (*)(PP_Instance instance, struct PP_Var name, int32_t sample, int32_t min, int32_t max, uint32_t bucket_count))&Pnacl_M35_PPB_UMA_Private_HistogramCustomCounts, + .HistogramEnumeration = (void (*)(PP_Instance instance, struct PP_Var name, int32_t sample, int32_t boundary_value))&Pnacl_M35_PPB_UMA_Private_HistogramEnumeration, + .IsCrashReportingEnabled = (int32_t (*)(PP_Instance instance, struct PP_CompletionCallback callback))&Pnacl_M35_PPB_UMA_Private_IsCrashReportingEnabled }; static const struct PPB_VideoDestination_Private_0_1 Pnacl_Wrappers_PPB_VideoDestination_Private_0_1 = { @@ -5922,9 +5928,9 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_UDPSocket_Private_0_4 = { .real_iface = NULL }; -static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_UMA_Private_0_2 = { - .iface_macro = PPB_UMA_PRIVATE_INTERFACE_0_2, - .wrapped_iface = (const void *) &Pnacl_Wrappers_PPB_UMA_Private_0_2, +static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_UMA_Private_0_3 = { + .iface_macro = PPB_UMA_PRIVATE_INTERFACE_0_3, + .wrapped_iface = (const void *) &Pnacl_Wrappers_PPB_UMA_Private_0_3, .real_iface = NULL }; @@ -6065,7 +6071,7 @@ static struct __PnaclWrapperInfo *s_ppb_wrappers[] = { &Pnacl_WrapperInfo_PPB_UDPSocket_Private_0_2, &Pnacl_WrapperInfo_PPB_UDPSocket_Private_0_3, &Pnacl_WrapperInfo_PPB_UDPSocket_Private_0_4, - &Pnacl_WrapperInfo_PPB_UMA_Private_0_2, + &Pnacl_WrapperInfo_PPB_UMA_Private_0_3, &Pnacl_WrapperInfo_PPB_VideoDestination_Private_0_1, &Pnacl_WrapperInfo_PPB_VideoSource_Private_0_1, &Pnacl_WrapperInfo_PPB_X509Certificate_Private_0_1, diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index ead5680..5691b0c 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -1277,6 +1277,8 @@ IPC_MESSAGE_CONTROL3(PpapiHostMsg_UMA_HistogramEnumeration, std::string /* name */, int32_t /* sample */, int32_t /* boundary_value */) +IPC_MESSAGE_CONTROL0(PpapiHostMsg_UMA_IsCrashReportingEnabled); +IPC_MESSAGE_CONTROL0(PpapiPluginMsg_UMA_IsCrashReportingEnabledReply); // File chooser. IPC_MESSAGE_CONTROL0(PpapiHostMsg_FileChooser_Create) diff --git a/ppapi/proxy/uma_private_resource.cc b/ppapi/proxy/uma_private_resource.cc index d17a005..2932e6c 100644 --- a/ppapi/proxy/uma_private_resource.cc +++ b/ppapi/proxy/uma_private_resource.cc @@ -84,6 +84,27 @@ void UMAPrivateResource::HistogramEnumeration( boundary_value)); } +int32_t UMAPrivateResource::IsCrashReportingEnabled( + PP_Instance instance, + scoped_refptr<TrackedCallback> callback) { + if (pending_callback_ != NULL) + return PP_ERROR_INPROGRESS; + pending_callback_ = callback; + Call<PpapiPluginMsg_UMA_IsCrashReportingEnabledReply>( + RENDERER, + PpapiHostMsg_UMA_IsCrashReportingEnabled(), + base::Bind(&UMAPrivateResource::OnPluginMsgIsCrashReportingEnabled, + this)); + return PP_OK_COMPLETIONPENDING; +} + +void UMAPrivateResource::OnPluginMsgIsCrashReportingEnabled( + const ResourceMessageReplyParams& params) { + if (TrackedCallback::IsPending(pending_callback_)) + pending_callback_->Run(params.result()); + pending_callback_ = NULL; +} + } // namespace proxy } // namespace ppapi diff --git a/ppapi/proxy/uma_private_resource.h b/ppapi/proxy/uma_private_resource.h index 94c7d3c..93328e8 100644 --- a/ppapi/proxy/uma_private_resource.h +++ b/ppapi/proxy/uma_private_resource.h @@ -44,7 +44,15 @@ class PPAPI_PROXY_EXPORT UMAPrivateResource int32_t sample, int32_t boundary_value) OVERRIDE; + virtual int32_t IsCrashReportingEnabled( + PP_Instance instance, + scoped_refptr<TrackedCallback> callback) OVERRIDE; + private: + void OnPluginMsgIsCrashReportingEnabled( + const ResourceMessageReplyParams& params); + scoped_refptr<TrackedCallback> pending_callback_; + DISALLOW_COPY_AND_ASSIGN(UMAPrivateResource); }; diff --git a/ppapi/thunk/interfaces_ppb_private_no_permissions.h b/ppapi/thunk/interfaces_ppb_private_no_permissions.h index 83e8243..6c224fe 100644 --- a/ppapi/thunk/interfaces_ppb_private_no_permissions.h +++ b/ppapi/thunk/interfaces_ppb_private_no_permissions.h @@ -48,7 +48,7 @@ PROXIED_IFACE(PPB_VIDEODESTINATION_PRIVATE_INTERFACE_0_1, PROXIED_IFACE(PPB_VIDEOSOURCE_PRIVATE_INTERFACE_0_1, PPB_VideoSource_Private_0_1) -PROXIED_IFACE(PPB_UMA_PRIVATE_INTERFACE_0_2, - PPB_UMA_Private_0_2) +PROXIED_IFACE(PPB_UMA_PRIVATE_INTERFACE_0_3, + PPB_UMA_Private_0_3) #include "ppapi/thunk/interfaces_postamble.h" diff --git a/ppapi/thunk/ppb_uma_private_thunk.cc b/ppapi/thunk/ppb_uma_private_thunk.cc index 1171d19..299b643 100644 --- a/ppapi/thunk/ppb_uma_private_thunk.cc +++ b/ppapi/thunk/ppb_uma_private_thunk.cc @@ -2,8 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// From private/ppb_uma_private.idl modified Fri Jan 24 13:23:21 2014. +// From private/ppb_uma_private.idl modified Thu Mar 13 11:54:51 2014. +#include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/private/ppb_uma_private.h" #include "ppapi/shared_impl/tracked_callback.h" @@ -66,16 +67,28 @@ void HistogramEnumeration(PP_Instance instance, boundary_value); } -const PPB_UMA_Private_0_2 g_ppb_uma_private_thunk_0_2 = { +int32_t IsCrashReportingEnabled(PP_Instance instance, + struct PP_CompletionCallback callback) { + VLOG(4) << "PPB_UMA_Private::IsCrashReportingEnabled()"; + EnterInstanceAPI<PPB_UMA_Singleton_API> enter(instance, callback); + if (enter.failed()) + return enter.retval(); + return enter.SetResult(enter.functions()->IsCrashReportingEnabled( + instance, + enter.callback())); +} + +const PPB_UMA_Private_0_3 g_ppb_uma_private_thunk_0_3 = { &HistogramCustomTimes, &HistogramCustomCounts, - &HistogramEnumeration + &HistogramEnumeration, + &IsCrashReportingEnabled }; } // namespace -PPAPI_THUNK_EXPORT const PPB_UMA_Private_0_2* GetPPB_UMA_Private_0_2_Thunk() { - return &g_ppb_uma_private_thunk_0_2; +PPAPI_THUNK_EXPORT const PPB_UMA_Private_0_3* GetPPB_UMA_Private_0_3_Thunk() { + return &g_ppb_uma_private_thunk_0_3; } } // namespace thunk diff --git a/ppapi/thunk/ppb_uma_singleton_api.h b/ppapi/thunk/ppb_uma_singleton_api.h index efb6736..f8414b9 100644 --- a/ppapi/thunk/ppb_uma_singleton_api.h +++ b/ppapi/thunk/ppb_uma_singleton_api.h @@ -34,6 +34,10 @@ class PPAPI_THUNK_EXPORT PPB_UMA_Singleton_API { int32_t sample, int32_t boundary_value) = 0; + virtual int32_t IsCrashReportingEnabled( + PP_Instance instance, + scoped_refptr<TrackedCallback> cc) = 0; + static const SingletonResourceID kSingletonResourceID = UMA_SINGLETON_ID; }; diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml index 768c4a1..176148f 100644 --- a/tools/metrics/histograms/histograms.xml +++ b/tools/metrics/histograms/histograms.xml @@ -36059,6 +36059,7 @@ other types of suffix sets. <int value="138418890" label="PPB_Memory(Dev);0.1"/> <int value="153443470" label="PPB_URLResponseInfo;1.0"/> <int value="153532707" label="PPB_Buffer(Dev);0.4"/> + <int value="156766028" label="PPB_UMA_Private;0.3"/> <int value="162107265" label="PPB_NetworkMonitor;1.0"/> <int value="180906214" label="PPB_Instance_Private;0.1"/> <int value="221802429" label="PPB_URLUtil(Dev);0.7"/> |