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

Side by Side Diff: chrome/browser/metrics/chrome_metrics_service_client.cc

Issue 287193005: [Metrics] Move non-idle notifications from MetricsService to ChromeMetricsServiceClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: break! Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/metrics/chrome_metrics_service_client.h" 5 #include "chrome/browser/metrics/chrome_metrics_service_client.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/google/google_util.h" 10 #include "chrome/browser/google/google_util.h"
11 #include "chrome/browser/metrics/metrics_service.h"
10 #include "chrome/browser/ui/browser_otr_state.h" 12 #include "chrome/browser/ui/browser_otr_state.h"
11 #include "chrome/common/chrome_version_info.h" 13 #include "chrome/common/chrome_version_info.h"
12 #include "chrome/common/crash_keys.h" 14 #include "chrome/common/crash_keys.h"
15 #include "content/public/browser/notification_service.h"
13 16
14 namespace { 17 namespace {
15 18
16 metrics::SystemProfileProto::Channel AsProtobufChannel( 19 metrics::SystemProfileProto::Channel AsProtobufChannel(
17 chrome::VersionInfo::Channel channel) { 20 chrome::VersionInfo::Channel channel) {
18 switch (channel) { 21 switch (channel) {
19 case chrome::VersionInfo::CHANNEL_UNKNOWN: 22 case chrome::VersionInfo::CHANNEL_UNKNOWN:
20 return metrics::SystemProfileProto::CHANNEL_UNKNOWN; 23 return metrics::SystemProfileProto::CHANNEL_UNKNOWN;
21 case chrome::VersionInfo::CHANNEL_CANARY: 24 case chrome::VersionInfo::CHANNEL_CANARY:
22 return metrics::SystemProfileProto::CHANNEL_CANARY; 25 return metrics::SystemProfileProto::CHANNEL_CANARY;
23 case chrome::VersionInfo::CHANNEL_DEV: 26 case chrome::VersionInfo::CHANNEL_DEV:
24 return metrics::SystemProfileProto::CHANNEL_DEV; 27 return metrics::SystemProfileProto::CHANNEL_DEV;
25 case chrome::VersionInfo::CHANNEL_BETA: 28 case chrome::VersionInfo::CHANNEL_BETA:
26 return metrics::SystemProfileProto::CHANNEL_BETA; 29 return metrics::SystemProfileProto::CHANNEL_BETA;
27 case chrome::VersionInfo::CHANNEL_STABLE: 30 case chrome::VersionInfo::CHANNEL_STABLE:
28 return metrics::SystemProfileProto::CHANNEL_STABLE; 31 return metrics::SystemProfileProto::CHANNEL_STABLE;
29 } 32 }
30 NOTREACHED(); 33 NOTREACHED();
31 return metrics::SystemProfileProto::CHANNEL_UNKNOWN; 34 return metrics::SystemProfileProto::CHANNEL_UNKNOWN;
32 } 35 }
33 36
34 } // namespace 37 } // namespace
35 38
36 ChromeMetricsServiceClient::ChromeMetricsServiceClient() { 39 ChromeMetricsServiceClient::ChromeMetricsServiceClient() : service_(NULL) {
40 RegisterForNotifications();
37 } 41 }
38 42
39 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() { 43 ChromeMetricsServiceClient::~ChromeMetricsServiceClient() {
40 } 44 }
41 45
42 void ChromeMetricsServiceClient::SetClientID(const std::string& client_id) { 46 void ChromeMetricsServiceClient::SetClientID(const std::string& client_id) {
43 crash_keys::SetClientID(client_id); 47 crash_keys::SetClientID(client_id);
44 } 48 }
45 49
46 bool ChromeMetricsServiceClient::IsOffTheRecordSessionActive() { 50 bool ChromeMetricsServiceClient::IsOffTheRecordSessionActive() {
47 return !chrome::IsOffTheRecordSessionActive(); 51 return !chrome::IsOffTheRecordSessionActive();
48 } 52 }
49 53
50 std::string ChromeMetricsServiceClient::GetApplicationLocale() { 54 std::string ChromeMetricsServiceClient::GetApplicationLocale() {
51 return g_browser_process->GetApplicationLocale(); 55 return g_browser_process->GetApplicationLocale();
52 } 56 }
53 57
54 bool ChromeMetricsServiceClient::GetBrand(std::string* brand_code) { 58 bool ChromeMetricsServiceClient::GetBrand(std::string* brand_code) {
55 return google_util::GetBrand(brand_code); 59 return google_util::GetBrand(brand_code);
56 } 60 }
57 61
58 metrics::SystemProfileProto::Channel ChromeMetricsServiceClient::GetChannel() { 62 metrics::SystemProfileProto::Channel ChromeMetricsServiceClient::GetChannel() {
59 return AsProtobufChannel(chrome::VersionInfo::GetChannel()); 63 return AsProtobufChannel(chrome::VersionInfo::GetChannel());
60 } 64 }
61 65
62 std::string ChromeMetricsServiceClient::GetVersionString() { 66 std::string ChromeMetricsServiceClient::GetVersionString() {
63 // TODO(asvitkine): Move over from metrics_log.cc 67 // TODO(asvitkine): Move over from metrics_log.cc
64 return std::string(); 68 return std::string();
65 } 69 }
70
71 void ChromeMetricsServiceClient::RegisterForNotifications() {
72 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED,
73 content::NotificationService::AllBrowserContextsAndSources());
74 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED,
75 content::NotificationService::AllSources());
76 registrar_.Add(this, chrome::NOTIFICATION_TAB_PARENTED,
77 content::NotificationService::AllSources());
78 registrar_.Add(this, chrome::NOTIFICATION_TAB_CLOSING,
79 content::NotificationService::AllSources());
80 registrar_.Add(this, content::NOTIFICATION_LOAD_START,
81 content::NotificationService::AllSources());
82 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
83 content::NotificationService::AllSources());
84 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
85 content::NotificationService::AllSources());
86 registrar_.Add(this, content::NOTIFICATION_RENDER_WIDGET_HOST_HANG,
87 content::NotificationService::AllSources());
88 registrar_.Add(this, chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
89 content::NotificationService::AllSources());
90 }
91
92 void ChromeMetricsServiceClient::Observe(
93 int type,
94 const content::NotificationSource& source,
95 const content::NotificationDetails& details) {
96 DCHECK(thread_checker_.CalledOnValidThread());
97
98 switch (type) {
99 case chrome::NOTIFICATION_BROWSER_OPENED:
100 case chrome::NOTIFICATION_BROWSER_CLOSED:
101 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL:
102 case chrome::NOTIFICATION_TAB_PARENTED:
103 case chrome::NOTIFICATION_TAB_CLOSING:
104 case content::NOTIFICATION_LOAD_STOP:
105 case content::NOTIFICATION_LOAD_START:
106 case content::NOTIFICATION_RENDERER_PROCESS_CLOSED:
107 case content::NOTIFICATION_RENDER_WIDGET_HOST_HANG:
108 // TODO(isherman): Remove this NULL check: http://crbug.com/375248
109 if (service_)
110 service_->OnApplicationNotIdle();
111 break;
112
113 default:
114 NOTREACHED();
115 }
116 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/chrome_metrics_service_client.h ('k') | chrome/browser/metrics/metrics_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698