Chromium Code Reviews| OLD | NEW | 
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/feedback/feedback_profile_observer.h" | |
| 6 | |
| 7 #include "base/callback.h" | |
| 8 #include "chrome/browser/chrome_notification_types.h" | |
| 9 #include "chrome/browser/feedback/feedback_report.h" | |
| 10 #include "chrome/browser/feedback/feedback_uploader.h" | |
| 11 #include "chrome/browser/feedback/feedback_uploader_factory.h" | |
| 12 #include "chrome/browser/profiles/profile.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" | |
| 16 | |
| 17 using content::BrowserThread; | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 static base::LazyInstance<feedback::FeedbackProfileObserver>::Leaky | |
| 
 
Lei Zhang
2014/01/23 22:28:41
You don't need static inside an anonymous namespac
 
rkc
2014/01/23 22:57:21
Done.
 
 | |
| 22 g_feedback_profile_observer = LAZY_INSTANCE_INITIALIZER; | |
| 23 | |
| 24 } | |
| 25 | |
| 26 namespace feedback { | |
| 27 | |
| 28 // static | |
| 29 void FeedbackProfileObserver::Initialize() { | |
| 30 g_feedback_profile_observer.Get(); | |
| 31 } | |
| 32 | |
| 33 FeedbackProfileObserver::FeedbackProfileObserver() { | |
| 34 prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, | |
| 35 content::NotificationService::AllSources()); | |
| 36 } | |
| 37 | |
| 38 FeedbackProfileObserver::~FeedbackProfileObserver() { | |
| 39 prefs_registrar_.RemoveAll(); | |
| 40 } | |
| 41 | |
| 42 void FeedbackProfileObserver::Observe( | |
| 43 int type, | |
| 44 const content::NotificationSource& source, | |
| 45 const content::NotificationDetails& details) { | |
| 46 switch (type) { | |
| 
 
Lei Zhang
2014/01/23 22:28:41
Don't bother with the switch(). Just DCHECK_EQ(chr
 
rkc
2014/01/23 22:57:21
Done.
 
 | |
| 47 case chrome::NOTIFICATION_PROFILE_CREATED: { | |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 49 Profile* profile = content::Source<Profile>(source).ptr(); | |
| 50 if (!profile->IsOffTheRecord()) | |
| 51 QueueUnsentReports(profile); | |
| 52 break; | |
| 53 } | |
| 54 default: | |
| 55 NOTREACHED(); | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 void FeedbackProfileObserver::QueueUnsentReports( | |
| 60 content::BrowserContext* context) { | |
| 61 feedback::FeedbackUploader *uploader = | |
| 
 
Lei Zhang
2014/01/23 22:28:41
nit: feedback::FeedbackUploader*
 
rkc
2014/01/23 22:57:21
Done.
 
 | |
| 62 feedback::FeedbackUploaderFactory::GetForBrowserContext(context); | |
| 63 BrowserThread::PostBlockingPoolTask(FROM_HERE, | |
| 64 base::Bind( | |
| 65 &FeedbackReport::LoadReportsAndQueue, context, base::Bind( | |
| 66 &FeedbackUploader::QueueReport, uploader->AsWeakPtr()))); | |
| 67 } | |
| 68 | |
| 69 } // namespace feedback | |
| OLD | NEW |