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

Unified Diff: chrome/browser/feedback/feedback_profile_observer.cc

Issue 141433011: Cache feedback reports to disk in case of send failure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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/feedback/feedback_profile_observer.cc
diff --git a/chrome/browser/feedback/feedback_profile_observer.cc b/chrome/browser/feedback/feedback_profile_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1e1a55b6da60cc7abeeef8cef863220fa44ed956
--- /dev/null
+++ b/chrome/browser/feedback/feedback_profile_observer.cc
@@ -0,0 +1,69 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
Zachary Kuznia 2014/01/23 05:21:01 2014
rkc 2014/01/23 21:48:00 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/feedback/feedback_profile_observer.h"
+
+#include "base/callback.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/feedback/feedback_report.h"
+#include "chrome/browser/feedback/feedback_uploader.h"
+#include "chrome/browser/feedback/feedback_uploader_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_service.h"
+
+using content::BrowserThread;
+
+namespace {
+
+static base::LazyInstance<feedback::FeedbackProfileObserver>::Leaky
+ g_feedback_profile_observer = LAZY_INSTANCE_INITIALIZER;
+
+}
+
+namespace feedback {
+
+// static
+void FeedbackProfileObserver::Initialize() {
+ g_feedback_profile_observer.Get();
+}
+
+FeedbackProfileObserver::FeedbackProfileObserver() {
+ prefs_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
+ content::NotificationService::AllSources());
+}
+
+FeedbackProfileObserver::~FeedbackProfileObserver() {
+ prefs_registrar_.RemoveAll();
+}
+
+void FeedbackProfileObserver::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ switch (type) {
+ case chrome::NOTIFICATION_PROFILE_CREATED: {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ Profile* profile = content::Source<Profile>(source).ptr();
+ if (!profile->IsOffTheRecord())
+ QueueUnsentReports(profile);
+ break;
+ }
+ default:
+ NOTREACHED();
+ }
+}
+
+void FeedbackProfileObserver::QueueUnsentReports(
+ content::BrowserContext* context) {
+ feedback::FeedbackUploader *uploader =
+ feedback::FeedbackUploaderFactory::GetForBrowserContext(context);
+ BrowserThread::PostBlockingPoolTask(FROM_HERE,
+ base::Bind(
+ &FeedbackReport::LoadReportsAndQueue, context, base::Bind(
+ &FeedbackUploader::QueueReport, uploader->AsWeakPtr())));
+}
+
+} // namespace feedback

Powered by Google App Engine
This is Rietveld 408576698