[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / feedback / feedback_profile_observer.cc
blob63d5ac75840ff7b7aef3252d5e3270f93d457e35
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
3 // found in the LICENSE file.
5 #include "chrome/browser/feedback/feedback_profile_observer.h"
7 #include "base/callback.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "components/feedback/feedback_report.h"
11 #include "components/feedback/feedback_uploader.h"
12 #include "components/feedback/feedback_uploader_factory.h"
13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/notification_service.h"
17 using content::BrowserThread;
19 static base::LazyInstance<feedback::FeedbackProfileObserver>::Leaky
20 g_feedback_profile_observer = LAZY_INSTANCE_INITIALIZER;
22 namespace feedback {
24 // static
25 void FeedbackProfileObserver::Initialize() {
26 g_feedback_profile_observer.Get();
29 FeedbackProfileObserver::FeedbackProfileObserver() {
30 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
31 content::NotificationService::AllSources());
34 FeedbackProfileObserver::~FeedbackProfileObserver() {
35 prefs_registrar_.RemoveAll();
38 void FeedbackProfileObserver::Observe(
39 int type,
40 const content::NotificationSource& source,
41 const content::NotificationDetails& details) {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
43 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CREATED, type);
45 Profile* profile = content::Source<Profile>(source).ptr();
46 if (profile && !profile->IsOffTheRecord())
47 QueueUnsentReports(profile);
50 void FeedbackProfileObserver::QueueSingleReport(
51 feedback::FeedbackUploader* uploader,
52 const std::string& data) {
53 BrowserThread::PostTask(
54 BrowserThread::UI, FROM_HERE, base::Bind(&FeedbackUploader::QueueReport,
55 uploader->AsWeakPtr(), data));
58 void FeedbackProfileObserver::QueueUnsentReports(
59 content::BrowserContext* context) {
60 feedback::FeedbackUploader* uploader =
61 feedback::FeedbackUploaderFactory::GetForBrowserContext(context);
62 BrowserThread::PostBlockingPoolTask(FROM_HERE,
63 base::Bind(
64 &FeedbackReport::LoadReportsAndQueue,
65 uploader->GetFeedbackReportsPath(),
66 base::Bind(&FeedbackProfileObserver::QueueSingleReport, uploader)));
69 } // namespace feedback