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

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: Comments addressed. 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..0a1de210d68c584ebae3122a7365c971e84599d8
--- /dev/null
+++ b/chrome/browser/metrics/variations/resource_request_allowed_notifier.h
@@ -0,0 +1,114 @@
+// 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;
Alexei Svitkine (slow) 2012/09/20 21:39:03 Is this needed? I don't see the header using it.
SteveT 2012/09/21 15:16:17 Removed now.
+}
+#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 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;
+ };
+
+ // Note that the constructor has some logic to register for notifications from
+ // the WizardController if the EULA was not accepted at startup (ChromeOS
Alexei Svitkine (slow) 2012/09/20 21:39:03 Nit: Prefix WizardController with its namespace in
SteveT 2012/09/21 15:16:17 Done.
+ // only).
+ ResourceRequestAllowedNotifier();
+ virtual ~ResourceRequestAllowedNotifier();
+
+ // Sets |observer| as the service to be notified by this instance. |observer|
+ // may not be NULL. This is to be called immediately after construction of
+ // an instance of ResourceRequestAllowedNotifier to pass it the interested
+ // service.
+ void Init(Observer* observer);
+
+ // Returns true iff all resource request criteria are 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();
+
+ 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();
+
+#if defined(OS_CHROMEOS)
+ // Returns true iff the EULA has been accepted by the user.
+ // This is virtual so it can be overriden by test classes to avoid making them
+ // aware of the ChromeOS details. This is protected so it call be overriden in
+ // subclasses for testing.
+ virtual bool IsEulaAccepted();
+#endif
+
+ private:
+ // net::NetworkChangeNotifier::ConnectionTypeObserver overrides:
+ virtual void OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
+
+#if defined(OS_CHROMEOS)
+ // content::NotificationObserver overrides:
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) 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