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

Side by Side 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: Flip EULA and added test. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_METRICS_VARIATIONS_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_
6 #define CHROME_BROWSER_METRICS_VARIATIONS_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H_
7
8 #include "base/observer_list.h"
9 #include "net/base/network_change_notifier.h"
10
11 #if defined(OS_CHROMEOS)
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h"
14 #endif
15
16 // This class informs an interested observer when resource requests over the
17 // network are permitted.
18 //
19 // Currently, the criteria for allowing resource requests include:
20 // 1. The network is currently available.
21 // 2. The EULA was accepted by the user (ChromeOS only).
22 //
23 // Interested services should add themselves as an observer of
24 // ResourceRequestAllowedNotifier and check ResourceRequestsAllowed() to see if
25 // requests are permitted. If it returns true, they can go ahead and make their
26 // request. If it returns false, ResourceRequestAllowedNotifier will notify the
27 // service when the criteria is met.
28 //
29 // If ResourceRequestsAllowed returns true the first time,
30 // ResourceRequestAllowedNotifier will not notify the service in the future.
31 //
32 // Note that this class handles the criteria state for a single service, so
33 // services should keep their own instance of this class rather than sharing a
34 // global instance.
35 class ResourceRequestAllowedNotifier :
36 #if defined(OS_CHROMEOS)
37 public content::NotificationObserver,
38 #endif
39 public net::NetworkChangeNotifier::ConnectionTypeObserver {
40 public:
41 // Observes resource request allowed state changes.
42 class Observer {
43 public:
44 virtual void OnResourceRequestsAllowed() = 0;
45 };
46
47 ResourceRequestAllowedNotifier();
48 virtual ~ResourceRequestAllowedNotifier();
49
50 // Sets |observer| as the service to be notified by this instance, and
51 // performs initial checks on the criteria. |observer| may not be NULL.
52 // This is to be called immediately after construction of an instance of
53 // ResourceRequestAllowedNotifier to pass it the interested service.
54 void Init(Observer* observer);
55
56 // Returns true iff all resource request criteria are met. If not, this call
57 // will set some flags so it knows to notify the observer if the criteria
58 // changes. Note that the observer will never be notified unless it calls this
59 // method first. This is virtual so it can be overriden for tests.
60 virtual bool ResourceRequestsAllowed();
61
62 void SetObserverRequestedPermissionForTesting(bool requested);
Alexei Svitkine (slow) 2012/09/24 20:47:05 Instead of this method, can the test simply call R
SteveT 2012/09/24 23:30:37 Some refactoring done to make this happen. Please
63 void SetWasWaitingForNetworkForTesting(bool waiting);
64 #if defined(OS_CHROMEOS)
65 void SetWasWaitingForEulaForTesting(bool waiting);
66 #endif
67
68 protected:
69 // Notifies observers if all criteria needed for resource requests are met.
Alexei Svitkine (slow) 2012/09/24 20:47:05 Nit: "observers" -> "observer".
SteveT 2012/09/24 23:30:37 Done.
70 // This is protected so it can be called from subclasses for testing.
71 void MaybeNotifyObserver();
72
73 #if defined(OS_CHROMEOS)
74 // On official builds, returns true iff the EULA needs to be accepted. This
75 // always returns false on unofficial builds since there is no notion of a
76 // EULA.
77 //
78 // This is virtual so it can be overriden by test classes to avoid making them
79 // aware of the ChromeOS details. This is protected so it call be overriden in
80 // subclasses for testing.
81 virtual bool NeedsEulaAcceptance();
82 #endif
83
84 private:
85 // net::NetworkChangeNotifier::ConnectionTypeObserver overrides:
86 virtual void OnConnectionTypeChanged(
87 net::NetworkChangeNotifier::ConnectionType type) OVERRIDE;
88
89 #if defined(OS_CHROMEOS)
90 // content::NotificationObserver overrides:
91 virtual void Observe(int type,
92 const content::NotificationSource& source,
93 const content::NotificationDetails& details) OVERRIDE;
94 #endif
95
96 // Tracks whether or not the observer/service depending on this class actually
97 // requested permission to make a request or not. If it did not, then this
98 // class should not notify it even if the criteria is met.
99 bool observer_requested_permission_;
100
101 // Tracks network connectivity criteria.
102 bool was_waiting_for_network_;
103
104 #if defined(OS_CHROMEOS)
105 // Tracks EULA acceptance criteria.
106 bool was_waiting_for_user_to_accept_eula_;
107
108 content::NotificationRegistrar registrar_;
Alexei Svitkine (slow) 2012/09/24 20:47:05 Nit: Add a comment to mention its for the eula not
SteveT 2012/09/24 23:30:37 Done.
109 #endif
110
111 // Observing service interested in request permissions.
112 Observer* observer_;
113
114 DISALLOW_COPY_AND_ASSIGN(ResourceRequestAllowedNotifier);
115 };
116
117 #endif // CHROME_BROWSER_METRICS_VARIATIONS_RESOURCE_REQUEST_ALLOWED_NOTIFIER_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698