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

Unified Diff: chrome/browser/metrics/variations/resource_request_allowed_notifier.h

Issue 10917120: Activate the VariationsService for ChromeOS and ensure that it does not ping the server until the E… (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: asvit nit 2 Created 8 years, 3 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/metrics/variations/resource_request_allowed_notifier.h
diff --git a/chrome/browser/metrics/variations/resource_request_allowed_notifier.h b/chrome/browser/metrics/variations/resource_request_allowed_notifier.h
new file mode 100644
index 0000000000000000000000000000000000000000..e405327a6805fe77eed102e95d258637eac5b36d
--- /dev/null
+++ b/chrome/browser/metrics/variations/resource_request_allowed_notifier.h
@@ -0,0 +1,108 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_METRICS_VARIATIONS_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_
+#define CHROME_BROWSER_METRICS_VARIATIONS_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_
+
+#include "base/observer_list.h"
+#include "net/base/network_change_notifier.h"
+
+#if defined(OS_CHROMEOS)
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#endif
+
+#if defined(OS_CHROMEOS)
+namespace chromeos {
+class WizardController;
+}
+#endif
+
+// This class informs an interested observer when resource requests over the
+// network are permitted.
+//
+// Currently, the criteria for allowing resource requests include:
+// 1. The network is currently available.
+// 2. The EULA was accepted by the user (ChromeOS only).
+//
+// Interested services should add themselves as an observer of
+// ResourceRequestAllowedNotifier and check ResourceRequestsAllowed() to see if
+// requests are permitted. If it returns true, they can go ahead and make their
+// request. If it returns false, ResourceRequestAllowedNotifier will notify the
+// service when the criteria is met.
+//
+// If the ResourceRequestsAllowed returns true the first time,
+// ResourceRequestAllowedNotifier will not notify the service in the future.
+//
+// Note that this class handles the criteria state for a single service, so
+// services should keep their own instance of this class rather than sharing a
+// global instance.
+class ResourceRequestAllowedNotifier :
+#if defined(OS_CHROMEOS)
+ public content::NotificationObserver,
+#endif
+ public net::NetworkChangeNotifier::ConnectionTypeObserver {
+ public:
+ // Observes resource request allowed state changes.
+ class Observer {
+ public:
+ virtual void OnResourceRequestsAllowed() = 0;
+ };
+
+ ResourceRequestAllowedNotifier();
+ virtual ~ResourceRequestAllowedNotifier();
+
+ // Sets |observer| as the observing service to be notified.
+ void SetObserver(Observer* observer);
+
+ // Clears the current observer.
+ void ClearObserver();
+
+ // Returns true iff all resource request criteria is met. If not, this call
+ // will set some flags so it knows to notify the observer if the criteria
+ // changes. This is virtual so it can be overriden for tests.
+ virtual bool ResourceRequestsAllowed();
+
+#if defined(OS_CHROMEOS)
+ // Registers for NOTIFICATION_WIZARD_EULA_ACCEPTED from |source|.
+ void RegisterForEulaAcceptedNotification(chromeos::WizardController* source);
+#endif
+
+ void SetWasWaitingForNetworkForTesting(bool waiting);
+#if defined(OS_CHROMEOS)
+ void SetWasWaitingForEulaForTesting(bool waiting);
+#endif
+
+ protected:
+ // Notifies observers if all criteria needed for resource requests are met.
+ // This is protected so it can be called from subclasses for testing.
+ void MaybeNotifyObservers();
+
+ private:
+#if defined(OS_CHROMEOS)
+ // content::NotificationObserver overrides:
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
+ // net::NetworkChangeNotifier::ConnectionTypeObserver implementation.
+ virtual void OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
+
+ content::NotificationRegistrar registrar_;
+
+ // Tracks EULA acceptance criteria.
+ bool was_waiting_for_user_to_accept_eula_;
+#endif
+
+ // Tracks network connectivity criteria.
+ bool was_waiting_for_network_;
+
+ // Observing service interested in request permissions.
+ Observer* observer_;
+
+ DISALLOW_COPY_AND_ASSIGN(ResourceRequestAllowedNotifier);
+};
+
+#endif // CHROME_BROWSER_METRICS_VARIATIONS_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_

Powered by Google App Engine
This is Rietveld 408576698