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

Side by Side Diff: chrome/browser/media/media_engagement_service.cc

Issue 2840813002: Media Engagement: implement shell of the media engagement service. (Closed)
Patch Set: Created 3 years, 8 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media/media_engagement_service.h"
6
7 #include "chrome/browser/media/media_engagement_service_factory.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "content/public/browser/web_contents.h"
10 #include "content/public/browser/web_contents_observer.h"
11 #include "media/base/media_switches.h"
12
13 class MediaEngagementService::ContentsObserver
14 : public content::WebContentsObserver {
15 public:
16 explicit ContentsObserver(content::WebContents* web_contents,
DaleCurtis 2017/04/25 16:57:59 No explicit for 2 params.
mlamouri (slow - plz ping) 2017/04/25 17:14:40 Eh. As above :)
17 MediaEngagementService* service)
18 : WebContentsObserver(web_contents), service_(service) {}
19
20 ~ContentsObserver() override = default;
21
22 // WebContentsObserver implementation.
23 void WebContentsDestroyed() override {
24 service_->contents_observers_.erase(this);
25 delete this;
26 }
27
28 private:
29 DISALLOW_COPY_AND_ASSIGN(ContentsObserver);
DaleCurtis 2017/04/25 16:57:59 last.
mlamouri (slow - plz ping) 2017/04/25 17:14:40 Done.
30
31 // |this| is owned by |service_|.
32 MediaEngagementService* service_;
33 };
34
35 // static
36 bool MediaEngagementService::IsEnabled() {
37 return base::FeatureList::IsEnabled(media::kMediaEngagement);
38 }
39
40 // static
41 MediaEngagementService* MediaEngagementService::Get(Profile* profile) {
42 DCHECK(IsEnabled());
43 return MediaEngagementServiceFactory::GetForProfile(profile);
44 }
45
46 // static
47 void MediaEngagementService::CreateWebContentsObserver(
48 content::WebContents* web_contents) {
49 DCHECK(IsEnabled());
50 MediaEngagementService* service =
51 Get(Profile::FromBrowserContext(web_contents->GetBrowserContext()));
52 if (!service)
53 return;
54 service->contents_observers_.insert(
55 new ContentsObserver(web_contents, service));
56 }
57
58 MediaEngagementService::MediaEngagementService(Profile* profile) {
59 DCHECK(IsEnabled());
60 }
61
62 MediaEngagementService::~MediaEngagementService() = default;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698