Commit b01b47e4 authored by Steven Holte's avatar Steven Holte Committed by Commit Bot

Update UKM API docs with current best practices.

Change-Id: Ida79579f16af6c2d0dcd97a7d972b2444f2280c3
Reviewed-on: https://chromium-review.googlesource.com/827541Reviewed-by: default avatarBrian White <bcwhite@chromium.org>
Commit-Queue: Steven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524446}
parent 497cdcd6
...@@ -24,13 +24,11 @@ namespace ukm { ...@@ -24,13 +24,11 @@ namespace ukm {
* *
* Usage Example: * Usage Example:
* *
* ukm::mojom::UkmRecorderInterfacePtr interface; * std::unique_ptr<ukm::MojoUkmRecorder> ukm_recorder =
* content::RenderThread::Get()->GetConnector()->BindInterface( * ukm::MojoUkmRecorder::Create(context()->connector());
* content::mojom::kBrowserServiceName, mojo::MakeRequest(&interface));
* ukm::MojoUkmRecorder ukm_recorder(std::move(interface));
* ukm::builders::MyEvent(source_id) * ukm::builders::MyEvent(source_id)
* .SetMyMetric(metric_value) * .SetMyMetric(metric_value)
* .Record(ukm_recorder); * .Record(ukm_recorder.get());
*/ */
class METRICS_EXPORT MojoUkmRecorder : public UkmRecorder { class METRICS_EXPORT MojoUkmRecorder : public UkmRecorder {
public: public:
......
...@@ -39,24 +39,30 @@ In order to record UKM events, your code needs a UkmRecorder object, defined by ...@@ -39,24 +39,30 @@ In order to record UKM events, your code needs a UkmRecorder object, defined by
There are two main ways of getting a UkmRecorder instance. There are two main ways of getting a UkmRecorder instance.
1) Use ukm::UkmRecorder::Get(). This only works from the UI thread of the Browser process. 1) Use ukm::UkmRecorder::Get(). This currently only works from the Browser process.
2) Use a service connector and get a MojoUkmRecorder. 2) Use a service connector and get a MojoUkmRecorder.
``` ```
ukm::mojom::UkmRecorderInterfacePtr interface; std::unique_ptr<ukm::MojoUkmRecorder> ukm_recorder =
service_connector->BindInterface( ukm::MojoUkmRecorder::Create(context()->connector());
content::mojom::kBrowserServiceName, ukm::builders::MyEvent(source_id)
mojo::MakeRequest(&interface)); .SetMyMetric(metric_value)
ukm::MojoUkmRecorder ukm_recorder(std::move(interface)); .Record(ukm_recorder.get());
``` ```
Note: This will eventually move out of the browser service.
## Get a ukm::SourceId ## Get a ukm::SourceId
UKM identifies navigations by thier source ID and you'll need to associate and ID with your event in order to tie it to a main frame URL. Preferrably, get an existing ID for the navigation from another object. UKM identifies navigations by thier source ID and you'll need to associate and ID with your event in order to tie it to a main frame URL. Preferrably, get an existing ID for the navigation from another object.
The main methods for doing this are using one of the following methods:
```
ukm::SourceId source_id = GetSourceIdForWebContentsDocument(web_contents);
ukm::SourceId source_id = ukm::ConvertToSourceId(
navigation_handle->GetNavigationId(), ukm::SourceIdType::NAVIGATION_ID);
```
Currently, however, the code for passing these IDs around is incomplete so you may need to temporarily create your own IDs and associate the URL with them. Example: Currently, however, the code for passing these IDs around is incomplete so you may need to temporarily create your own IDs and associate the URL with them. Example:
``` ```
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment