diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-01-31 16:33:43 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-02-06 16:33:22 +0000 |
commit | da51f56cc21233c2d30f0fe0d171727c3102b2e0 (patch) | |
tree | 4e579ab70ce4b19bee7984237f3ce05a96d59d83 /chromium/components/ukm | |
parent | c8c2d1901aec01e934adf561a9fdf0cc776cdef8 (diff) | |
download | qtwebengine-chromium-da51f56cc21233c2d30f0fe0d171727c3102b2e0.tar.gz |
BASELINE: Update Chromium to 65.0.3525.40
Also imports missing submodules
Change-Id: I36901b7c6a325cda3d2c10cedb2186c25af3b79b
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/components/ukm')
-rw-r--r-- | chromium/components/ukm/content/source_url_recorder.cc | 47 | ||||
-rw-r--r-- | chromium/components/ukm/content/source_url_recorder.h | 6 | ||||
-rw-r--r-- | chromium/components/ukm/content/source_url_recorder_browsertest.cc | 11 | ||||
-rw-r--r-- | chromium/components/ukm/content/source_url_recorder_test.cc | 12 | ||||
-rw-r--r-- | chromium/components/ukm/observers/sync_disable_observer.cc | 7 | ||||
-rw-r--r-- | chromium/components/ukm/test_ukm_recorder.cc | 9 | ||||
-rw-r--r-- | chromium/components/ukm/test_ukm_recorder.h | 3 | ||||
-rw-r--r-- | chromium/components/ukm/ukm_recorder_impl.cc | 10 | ||||
-rw-r--r-- | chromium/components/ukm/ukm_reporting_service.cc | 5 | ||||
-rw-r--r-- | chromium/components/ukm/ukm_service.cc | 9 | ||||
-rw-r--r-- | chromium/components/ukm/ukm_service_unittest.cc | 4 | ||||
-rw-r--r-- | chromium/components/ukm/ukm_source.cc | 23 | ||||
-rw-r--r-- | chromium/components/ukm/ukm_source.h | 21 |
13 files changed, 110 insertions, 57 deletions
diff --git a/chromium/components/ukm/content/source_url_recorder.cc b/chromium/components/ukm/content/source_url_recorder.cc index 43d0f8d1efb..fb8dc18b943 100644 --- a/chromium/components/ukm/content/source_url_recorder.cc +++ b/chromium/components/ukm/content/source_url_recorder.cc @@ -16,10 +16,12 @@ #include "services/metrics/public/cpp/ukm_source_id.h" #include "url/gurl.h" -namespace { +namespace ukm { + +namespace internal { // SourceUrlRecorderWebContentsObserver is responsible for recording UKM source -// URLs, for all main frame navigations in a given WebContents. +// URLs, for all (any only) main frame navigations in a given WebContents. // SourceUrlRecorderWebContentsObserver records both the final URL for a // navigation, and, if the navigation was redirected, the initial URL as well. class SourceUrlRecorderWebContentsObserver @@ -37,6 +39,8 @@ class SourceUrlRecorderWebContentsObserver void DidFinishNavigation( content::NavigationHandle* navigation_handle) override; + ukm::SourceId GetLastCommittedSourceId(); + private: explicit SourceUrlRecorderWebContentsObserver( content::WebContents* web_contents); @@ -49,12 +53,15 @@ class SourceUrlRecorderWebContentsObserver // Map from navigation ID to the initial URL for that navigation. base::flat_map<int64_t, GURL> pending_navigations_; + int64_t last_committed_source_id_; + DISALLOW_COPY_AND_ASSIGN(SourceUrlRecorderWebContentsObserver); }; SourceUrlRecorderWebContentsObserver::SourceUrlRecorderWebContentsObserver( content::WebContents* web_contents) - : content::WebContentsObserver(web_contents) {} + : content::WebContentsObserver(web_contents), + last_committed_source_id_(ukm::kInvalidSourceId) {} void SourceUrlRecorderWebContentsObserver::DidStartNavigation( content::NavigationHandle* navigation_handle) { @@ -82,6 +89,14 @@ void SourceUrlRecorderWebContentsObserver::DidFinishNavigation( if (it == pending_navigations_.end()) return; + DCHECK(navigation_handle->IsInMainFrame()); + DCHECK(!navigation_handle->IsSameDocument()); + + if (navigation_handle->HasCommitted()) { + last_committed_source_id_ = ukm::ConvertToSourceId( + navigation_handle->GetNavigationId(), ukm::SourceIdType::NAVIGATION_ID); + } + GURL initial_url = std::move(it->second); pending_navigations_.erase(it); @@ -92,9 +107,16 @@ void SourceUrlRecorderWebContentsObserver::DidFinishNavigation( MaybeRecordUrl(navigation_handle, initial_url); } +ukm::SourceId SourceUrlRecorderWebContentsObserver::GetLastCommittedSourceId() { + return last_committed_source_id_; +} + void SourceUrlRecorderWebContentsObserver::MaybeRecordUrl( content::NavigationHandle* navigation_handle, const GURL& initial_url) { + DCHECK(navigation_handle->IsInMainFrame()); + DCHECK(!navigation_handle->IsSameDocument()); + ukm::UkmRecorder* ukm_recorder = ukm::UkmRecorder::Get(); if (!ukm_recorder) return; @@ -119,15 +141,22 @@ void SourceUrlRecorderWebContentsObserver::CreateForWebContents( } } -} // namespace - -DEFINE_WEB_CONTENTS_USER_DATA_KEY(SourceUrlRecorderWebContentsObserver); - -namespace ukm { +} // namespace internal void InitializeSourceUrlRecorderForWebContents( content::WebContents* web_contents) { - SourceUrlRecorderWebContentsObserver::CreateForWebContents(web_contents); + internal::SourceUrlRecorderWebContentsObserver::CreateForWebContents( + web_contents); +} + +SourceId GetSourceIdForWebContentsDocument(content::WebContents* web_contents) { + internal::SourceUrlRecorderWebContentsObserver* obs = + internal::SourceUrlRecorderWebContentsObserver::FromWebContents( + web_contents); + return obs ? obs->GetLastCommittedSourceId() : kInvalidSourceId; } } // namespace ukm + +DEFINE_WEB_CONTENTS_USER_DATA_KEY( + ukm::internal::SourceUrlRecorderWebContentsObserver); diff --git a/chromium/components/ukm/content/source_url_recorder.h b/chromium/components/ukm/content/source_url_recorder.h index d124bc4cd45..eff51240c18 100644 --- a/chromium/components/ukm/content/source_url_recorder.h +++ b/chromium/components/ukm/content/source_url_recorder.h @@ -5,6 +5,8 @@ #ifndef COMPONENTS_UKM_CONTENT_SOURCE_URL_RECORDER_H_ #define COMPONENTS_UKM_CONTENT_SOURCE_URL_RECORDER_H_ +#include "services/metrics/public/cpp/ukm_source_id.h" + namespace content { class WebContents; } // namespace content @@ -15,6 +17,10 @@ namespace ukm { void InitializeSourceUrlRecorderForWebContents( content::WebContents* web_contents); +// Get a UKM SourceId for the currently committed document of web contents. +// Returns kInvalidSourceId if no commit has been observed. +SourceId GetSourceIdForWebContentsDocument(content::WebContents* web_contents); + } // namespace ukm #endif // COMPONENTS_UKM_CONTENT_SOURCE_URL_RECORDER_H_ diff --git a/chromium/components/ukm/content/source_url_recorder_browsertest.cc b/chromium/components/ukm/content/source_url_recorder_browsertest.cc index d2501867c12..82d3425380c 100644 --- a/chromium/components/ukm/content/source_url_recorder_browsertest.cc +++ b/chromium/components/ukm/content/source_url_recorder_browsertest.cc @@ -40,6 +40,12 @@ class SourceUrlRecorderWebContentsObserverBrowserTest return test_ukm_recorder_->GetSourceForSourceId(source_id); } + GURL GetAssociatedURLForWebContentsDocument() { + const ukm::UkmSource* src = test_ukm_recorder_->GetSourceForSourceId( + ukm::GetSourceIdForWebContentsDocument(shell()->web_contents())); + return src ? src->url() : GURL(); + } + private: base::test::ScopedFeatureList scoped_feature_list_; std::unique_ptr<ukm::TestAutoSetUkmRecorder> test_ukm_recorder_; @@ -79,6 +85,8 @@ IN_PROC_BROWSER_TEST_F(SourceUrlRecorderWebContentsObserverBrowserTest, Basic) { EXPECT_NE(nullptr, source); EXPECT_EQ(url, source->url()); EXPECT_TRUE(source->initial_url().is_empty()); + + EXPECT_EQ(url, GetAssociatedURLForWebContentsDocument()); } IN_PROC_BROWSER_TEST_F(SourceUrlRecorderWebContentsObserverBrowserTest, @@ -102,6 +110,8 @@ IN_PROC_BROWSER_TEST_F(SourceUrlRecorderWebContentsObserverBrowserTest, EXPECT_EQ(main_url, source->url()); EXPECT_EQ(nullptr, GetSourceForNavigationId(subframe_observer.navigation_id())); + + EXPECT_EQ(main_url, GetAssociatedURLForWebContentsDocument()); } IN_PROC_BROWSER_TEST_F(SourceUrlRecorderWebContentsObserverDownloadBrowserTest, @@ -112,4 +122,5 @@ IN_PROC_BROWSER_TEST_F(SourceUrlRecorderWebContentsObserverDownloadBrowserTest, EXPECT_FALSE(observer.has_committed()); EXPECT_TRUE(observer.is_download()); EXPECT_EQ(nullptr, GetSourceForNavigationId(observer.navigation_id())); + EXPECT_EQ(GURL(), GetAssociatedURLForWebContentsDocument()); } diff --git a/chromium/components/ukm/content/source_url_recorder_test.cc b/chromium/components/ukm/content/source_url_recorder_test.cc index 6ac04ae7f1b..2f532480cfc 100644 --- a/chromium/components/ukm/content/source_url_recorder_test.cc +++ b/chromium/components/ukm/content/source_url_recorder_test.cc @@ -22,6 +22,12 @@ class SourceUrlRecorderWebContentsObserverTest ukm::InitializeSourceUrlRecorderForWebContents(web_contents()); } + GURL GetAssociatedURLForWebContentsDocument() { + const ukm::UkmSource* src = test_ukm_recorder_.GetSourceForSourceId( + ukm::GetSourceIdForWebContentsDocument(web_contents())); + return src ? src->url() : GURL(); + } + protected: ukm::TestAutoSetUkmRecorder test_ukm_recorder_; }; @@ -52,6 +58,8 @@ TEST_F(SourceUrlRecorderWebContentsObserverTest, InitialUrl) { EXPECT_EQ(final_url, kv.second->url()); EXPECT_EQ(initial_url, kv.second->initial_url()); } + + EXPECT_EQ(final_url, GetAssociatedURLForWebContentsDocument()); } TEST_F(SourceUrlRecorderWebContentsObserverTest, IgnoreUrlInSubframe) { @@ -69,6 +77,8 @@ TEST_F(SourceUrlRecorderWebContentsObserverTest, IgnoreUrlInSubframe) { EXPECT_EQ(main_frame_url, kv.second->url()); EXPECT_TRUE(kv.second->initial_url().is_empty()); } + + EXPECT_EQ(main_frame_url, GetAssociatedURLForWebContentsDocument()); } TEST_F(SourceUrlRecorderWebContentsObserverTest, IgnoreSameDocumentNavigation) { @@ -86,4 +96,6 @@ TEST_F(SourceUrlRecorderWebContentsObserverTest, IgnoreSameDocumentNavigation) { EXPECT_EQ(url, kv.second->url()); EXPECT_TRUE(kv.second->initial_url().is_empty()); } + + EXPECT_EQ(url, GetAssociatedURLForWebContentsDocument()); } diff --git a/chromium/components/ukm/observers/sync_disable_observer.cc b/chromium/components/ukm/observers/sync_disable_observer.cc index 23ae99581f5..7609b7a0ce2 100644 --- a/chromium/components/ukm/observers/sync_disable_observer.cc +++ b/chromium/components/ukm/observers/sync_disable_observer.cc @@ -16,11 +16,12 @@ SyncDisableObserver::~SyncDisableObserver() {} // static SyncDisableObserver::SyncState SyncDisableObserver::GetSyncState( syncer::SyncService* sync_service) { + const bool initialized = sync_service->IsEngineInitialized(); return SyncDisableObserver::SyncState{ sync_service->GetPreferredDataTypes().Has( syncer::HISTORY_DELETE_DIRECTIVES), - sync_service->IsEngineInitialized(), - sync_service->IsUsingSecondaryPassphrase(), + initialized, + initialized ? sync_service->IsUsingSecondaryPassphrase() : false, }; } @@ -58,6 +59,8 @@ void SyncDisableObserver::OnStateChanged(syncer::SyncService* sync) { bool must_purge = // Trigger a purge if history sync was disabled. (previous_state.history_enabled && !state.history_enabled) || + // Trigger a purge if engine has become disabled. + (previous_state.initialized && !state.initialized) || // Trigger a purge if the user added a passphrase. Since we can't detect // the use of a passphrase while the engine is not initialized, we may // miss the transition if the user adds a passphrase in this state. diff --git a/chromium/components/ukm/test_ukm_recorder.cc b/chromium/components/ukm/test_ukm_recorder.cc index c3c876cb05a..5a9139585d9 100644 --- a/chromium/components/ukm/test_ukm_recorder.cc +++ b/chromium/components/ukm/test_ukm_recorder.cc @@ -84,14 +84,11 @@ std::set<ukm::SourceId> TestUkmRecorder::GetSourceIds() const { } const UkmSource* TestUkmRecorder::GetSourceForUrl(const char* url) const { - const UkmSource* source = nullptr; for (const auto& kv : sources()) { - if (kv.second->url() == url) { - DCHECK_EQ(nullptr, source); - source = kv.second.get(); - } + if (kv.second->url() == url) + return kv.second.get(); } - return source; + return nullptr; } std::vector<const UkmSource*> TestUkmRecorder::GetSourcesForUrl( diff --git a/chromium/components/ukm/test_ukm_recorder.h b/chromium/components/ukm/test_ukm_recorder.h index 0ad19b71244..e2ec2ffe84e 100644 --- a/chromium/components/ukm/test_ukm_recorder.h +++ b/chromium/components/ukm/test_ukm_recorder.h @@ -78,6 +78,9 @@ class TestUkmRecorder : public UkmRecorderImpl { // Get all SourceIds with any data associated with them. std::set<ukm::SourceId> GetSourceIds() const; + // Returns the UKM source for the given URL. If there are multiple sources for + // the given URL, this returns the first source that is created. If there is + // no source for the given URL, this returns nullptr. const UkmSource* GetSourceForUrl(const char* url) const; const UkmSource* GetSourceForUrl(const GURL& url) const { return GetSourceForUrl(url.spec().c_str()); diff --git a/chromium/components/ukm/ukm_recorder_impl.cc b/chromium/components/ukm/ukm_recorder_impl.cc index 28a5bbdf095..7f431a86841 100644 --- a/chromium/components/ukm/ukm_recorder_impl.cc +++ b/chromium/components/ukm/ukm_recorder_impl.cc @@ -32,8 +32,7 @@ std::string GetWhitelistEntries() { } bool IsWhitelistedSourceId(SourceId source_id) { - return (static_cast<int64_t>(source_id) & - static_cast<int64_t>(SourceIdType::NAVIGATION_ID)) != 0; + return GetSourceIdType(source_id) == SourceIdType::NAVIGATION_ID; } // Gets the maximum number of Sources we'll keep in memory before discarding any @@ -202,7 +201,7 @@ void UkmRecorderImpl::StoreRecordingsInReport(Report* report) { bool UkmRecorderImpl::ShouldRestrictToWhitelistedSourceIds() const { return base::GetFieldTrialParamByFeatureAsBool( - kUkmFeature, "RestrictToWhitelistedSourceIds", true); + kUkmFeature, "RestrictToWhitelistedSourceIds", false); } void UkmRecorderImpl::UpdateSourceURL(SourceId source_id, @@ -239,10 +238,7 @@ void UkmRecorderImpl::UpdateSourceURL(SourceId source_id, RecordDroppedSource(DroppedDataReason::MAX_HIT); return; } - std::unique_ptr<UkmSource> source = base::MakeUnique<UkmSource>(); - source->set_id(source_id); - source->set_url(url); - sources_.insert(std::make_pair(source_id, std::move(source))); + sources_.emplace(source_id, base::MakeUnique<UkmSource>(source_id, url)); } void UkmRecorderImpl::AddEntry(mojom::UkmEntryPtr entry) { diff --git a/chromium/components/ukm/ukm_reporting_service.cc b/chromium/components/ukm/ukm_reporting_service.cc index 9a7502ff9b5..2ff266d6d9c 100644 --- a/chromium/components/ukm/ukm_reporting_service.cc +++ b/chromium/components/ukm/ukm_reporting_service.cc @@ -8,6 +8,7 @@ #include "base/memory/ptr_util.h" #include "base/metrics/field_trial_params.h" +#include "base/metrics/histogram_functions.h" #include "base/metrics/histogram_macros.h" #include "components/prefs/pref_registry_simple.h" #include "components/ukm/persisted_logs_metrics_impl.h" @@ -97,8 +98,8 @@ void UkmReportingService::LogResponseOrErrorCode(int response_code, int error_code, bool was_https) { // |was_https| is ignored since all UKM logs are received over HTTPS. - UMA_HISTOGRAM_SPARSE_SLOWLY("UKM.LogUpload.ResponseOrErrorCode", - response_code >= 0 ? response_code : error_code); + base::UmaHistogramSparse("UKM.LogUpload.ResponseOrErrorCode", + response_code >= 0 ? response_code : error_code); } void UkmReportingService::LogSuccess(size_t log_size) { diff --git a/chromium/components/ukm/ukm_service.cc b/chromium/components/ukm/ukm_service.cc index aa21e48d02f..90a43fc3bba 100644 --- a/chromium/components/ukm/ukm_service.cc +++ b/chromium/components/ukm/ukm_service.cc @@ -31,10 +31,6 @@ namespace ukm { namespace { -// The delay, in seconds, after starting recording before doing expensive -// initialization work. -constexpr int kInitializationDelaySeconds = 5; - // Generates a new client id and stores it in prefs. uint64_t GenerateClientId(PrefService* pref_service) { uint64_t client_id = 0; @@ -108,10 +104,7 @@ void UkmService::Initialize() { DVLOG(1) << "UkmService::Initialize"; initialize_started_ = true; - base::SequencedTaskRunnerHandle::Get()->PostDelayedTask( - FROM_HERE, - base::Bind(&UkmService::StartInitTask, self_ptr_factory_.GetWeakPtr()), - base::TimeDelta::FromSeconds(kInitializationDelaySeconds)); + StartInitTask(); } void UkmService::EnableReporting() { diff --git a/chromium/components/ukm/ukm_service_unittest.cc b/chromium/components/ukm/ukm_service_unittest.cc index d5437dbc719..2e507b8b6b8 100644 --- a/chromium/components/ukm/ukm_service_unittest.cc +++ b/chromium/components/ukm/ukm_service_unittest.cc @@ -167,9 +167,7 @@ TEST_F(UkmServiceTest, EnableDisableSchedule) { UkmService service(&prefs_, &client_); EXPECT_FALSE(task_runner_->HasPendingTask()); service.Initialize(); - EXPECT_TRUE(task_runner_->HasPendingTask()); - // Allow initialization to complete. - task_runner_->RunUntilIdle(); + EXPECT_FALSE(task_runner_->HasPendingTask()); service.EnableRecording(); service.EnableReporting(); EXPECT_TRUE(task_runner_->HasPendingTask()); diff --git a/chromium/components/ukm/ukm_source.cc b/chromium/components/ukm/ukm_source.cc index e74e05356a2..75ed807a22e 100644 --- a/chromium/components/ukm/ukm_source.cc +++ b/chromium/components/ukm/ukm_source.cc @@ -39,17 +39,26 @@ void UkmSource::SetCustomTabVisible(bool visible) { g_custom_tab_state = visible ? kCustomTabTrue : kCustomTabFalse; } -UkmSource::UkmSource() - : custom_tab_state_(g_custom_tab_state), - creation_time_(base::TimeTicks::Now()) {} +UkmSource::UkmSource(ukm::SourceId id, const GURL& url) + : id_(id), + url_(url), + custom_tab_state_(g_custom_tab_state), + creation_time_(base::TimeTicks::Now()) { + DCHECK(!url_.is_empty()); +} UkmSource::~UkmSource() = default; void UkmSource::UpdateUrl(const GURL& url) { - DCHECK(!url_.is_empty()); + DCHECK(!url.is_empty()); if (url_ == url) return; - if (initial_url_.is_empty()) + // We only track multiple URLs for navigation-based Sources. These are + // currently the only sources that intentionally record multiple entries, + // and this makes it easier to compare other source URLs against a + // whitelist. + if (initial_url_.is_empty() && + GetSourceIdType(id_) == SourceIdType::NAVIGATION_ID) initial_url_ = url_; url_ = url; } @@ -61,8 +70,10 @@ void UkmSource::PopulateProto(Source* proto_source) const { proto_source->set_id(id_); proto_source->set_url(GetShortenedURL(url_)); - if (!initial_url_.is_empty()) + if (!initial_url_.is_empty()) { + DCHECK_EQ(SourceIdType::NAVIGATION_ID, GetSourceIdType(id_)); proto_source->set_initial_url(GetShortenedURL(initial_url_)); + } if (custom_tab_state_ != kCustomTabUnset) proto_source->set_is_custom_tab(custom_tab_state_ == kCustomTabTrue); diff --git a/chromium/components/ukm/ukm_source.h b/chromium/components/ukm/ukm_source.h index e053a1f22c7..9ad8acecd5a 100644 --- a/chromium/components/ukm/ukm_source.h +++ b/chromium/components/ukm/ukm_source.h @@ -17,7 +17,7 @@ namespace ukm { class Source; -// Contains UKM data for a single navigation entry. +// Contains UKM URL data for a single source id. class UkmSource { public: enum CustomTabState { @@ -26,11 +26,10 @@ class UkmSource { kCustomTabFalse, }; - UkmSource(); + UkmSource(SourceId id, const GURL& url); ~UkmSource(); ukm::SourceId id() const { return id_; } - void set_id(ukm::SourceId id) { id_ = id; } const GURL& initial_url() const { return initial_url_; } const GURL& url() const { return url_; } @@ -39,14 +38,7 @@ class UkmSource { // intended to be anything useful for UKM clients. const base::TimeTicks creation_time() const { return creation_time_; } - // Sets the URL for this source. Should be invoked when a source is - // initialized. - void set_url(const GURL& url) { url_ = url; } - - // Updates the URL for this source. Must be called after set_url. If a new URL - // is passed to UpdateUrl, the initial_url field is populated with the - // original URL provided to set_url, and the url field is updated with the - // value provided to this method. + // Records a new URL for this source. void UpdateUrl(const GURL& url); // Serializes the members of the class into the supplied proto. @@ -56,13 +48,14 @@ class UkmSource { static void SetCustomTabVisible(bool visible); private: - ukm::SourceId id_; + const ukm::SourceId id_; // The final, canonical URL for this source. GURL url_; - // The initial URL for this source. Only set if different from |url_| (i.e. if - // the URL changed over the lifetime of this source). + // The initial URL for this source. + // Only set for navigation-id based sources where more than one value of URL + // was recorded. GURL initial_url_; // A flag indicating if metric was collected in a custom tab. This is set |