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

Unified Diff: chrome/browser/media/media_engagement_service.cc

Issue 2840813002: Media Engagement: implement shell of the media engagement service. (Closed)
Patch Set: rebase Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/media_engagement_service.cc
diff --git a/chrome/browser/media/media_engagement_service.cc b/chrome/browser/media/media_engagement_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2eb7ffb2bca60a2dd25ea37ef9792f8e5967a8dc
--- /dev/null
+++ b/chrome/browser/media/media_engagement_service.cc
@@ -0,0 +1,62 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/media/media_engagement_service.h"
+
+#include "chrome/browser/media/media_engagement_service_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_observer.h"
+#include "media/base/media_switches.h"
+
+class MediaEngagementService::ContentsObserver
+ : public content::WebContentsObserver {
+ public:
+ ContentsObserver(content::WebContents* web_contents,
+ MediaEngagementService* service)
+ : WebContentsObserver(web_contents), service_(service) {}
+
+ ~ContentsObserver() override = default;
+
+ // WebContentsObserver implementation.
+ void WebContentsDestroyed() override {
+ service_->contents_observers_.erase(this);
+ delete this;
+ }
+
+ private:
+ // |this| is owned by |service_|.
+ MediaEngagementService* service_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContentsObserver);
+};
+
+// static
+bool MediaEngagementService::IsEnabled() {
+ return base::FeatureList::IsEnabled(media::kMediaEngagement);
+}
+
+// static
+MediaEngagementService* MediaEngagementService::Get(Profile* profile) {
+ DCHECK(IsEnabled());
+ return MediaEngagementServiceFactory::GetForProfile(profile);
+}
+
+// static
+void MediaEngagementService::CreateWebContentsObserver(
+ content::WebContents* web_contents) {
+ DCHECK(IsEnabled());
+ MediaEngagementService* service =
+ Get(Profile::FromBrowserContext(web_contents->GetBrowserContext()));
+ if (!service)
+ return;
+ service->contents_observers_.insert(
+ new ContentsObserver(web_contents, service));
+}
+
+MediaEngagementService::MediaEngagementService(Profile* profile) {
+ DCHECK(IsEnabled());
+}
+
+MediaEngagementService::~MediaEngagementService() = default;
« no previous file with comments | « chrome/browser/media/media_engagement_service.h ('k') | chrome/browser/media/media_engagement_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698