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

Unified Diff: chrome/browser/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: unit tests refactored 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/resource_request_allowed_notifier.h
diff --git a/chrome/browser/resource_request_allowed_notifier.h b/chrome/browser/resource_request_allowed_notifier.h
new file mode 100644
index 0000000000000000000000000000000000000000..0525cfaa361acc42338002710fb0ecec8336519c
--- /dev/null
+++ b/chrome/browser/resource_request_allowed_notifier.h
@@ -0,0 +1,93 @@
+// 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_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_
+#define CHROME_BROWSER_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_
Ilya Sherman 2012/09/11 22:51:27 nit: Is the variations service currently the only
Alexei Svitkine (slow) 2012/09/12 15:15:46 I agree with Ilya here. Let's add it under chrome/
SteveT 2012/09/14 20:25:09 Done.
SteveT 2012/09/14 20:25:09 Done.
+
+#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
+
+// Services that need to request resources over the network should use this
Alexei Svitkine (slow) 2012/09/12 15:15:46 Can you rephrase the first sentence and/or paragra
SteveT 2012/09/14 20:25:09 Done.
+// helper class to check if they can perform their requests. This class wraps
+// such criteria and notifies interested services if state ever changes in such
+// a way that resource access is allowed.
+//
+// Such 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.
+//
+// Currently, the criteria for allowing resource requests include:
+// 1. The network is currently available.
+// 2. The EULA was accepted by the user (ChromeOS only).
+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();
+
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ // 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.
+ bool ResourceRequestsAllowed();
+
+#if defined(OS_CHROMEOS)
+ // content::NotificationObserver overrides:
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
Ilya Sherman 2012/09/11 22:51:27 nit: Can this have private visibility?
SteveT 2012/09/14 20:25:09 Yes! Done.
+#endif
+
+ // net::NetworkChangeNotifier::ConnectionTypeObserver implementation.
+ virtual void OnConnectionTypeChanged(
+ net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
Ilya Sherman 2012/09/11 22:51:27 nit: Can this have private visibility?
SteveT 2012/09/14 20:25:09 Yeah, done.
+
+ void SetWasOfflineDuringLastRequestAttemptForTesting(bool offline);
+
+ private:
+ // Notifies observers if all criteria needed for resource requests are met.
+ void MaybeNotifyObservers();
+
+#if defined(OS_CHROMEOS)
Alexei Svitkine (slow) 2012/09/12 15:15:46 I think this ifdef was meant to go around the next
SteveT 2012/09/14 20:25:09 Yes, done.
+ // Tracks network connectivity criteria.
+ bool was_offline_during_last_request_attempt_;
Alexei Svitkine (slow) 2012/09/12 15:15:46 Can you name this consistently with |was_waiting_f
SteveT 2012/09/14 20:25:09 Sure. was_waiting_for_network_ and was_waiting_fo
+#endif
+
+ // Tracks EULA acceptance criteria.
+ bool was_waiting_for_user_to_accept_eula_;
Ilya Sherman 2012/09/11 22:51:27 nit: Should this also be in the #if defined(OS_CHR
SteveT 2012/09/14 20:25:09 Yes - thanks.
+
+ // List of observers interested in request permissions.
+ ObserverList<Observer> observer_list_;
+
+ content::NotificationRegistrar registrar_;
Ilya Sherman 2012/09/11 22:51:27 nit: Ditto
SteveT 2012/09/14 20:25:09 Done.
+
+ DISALLOW_COPY_AND_ASSIGN(ResourceRequestAllowedNotifier);
+};
+
+#endif // CHROME_BROWSER_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_

Powered by Google App Engine
This is Rietveld 408576698