OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_ |
6 #define CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_ | 6 #define CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/string16.h" | 16 #include "base/string16.h" |
17 #include "base/timer.h" | 17 #include "base/timer.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/profiles/profile_keyed_service.h" | 19 #include "chrome/browser/profiles/profile_keyed_service.h" |
20 #include "chrome/browser/sessions/session_id.h" | 20 #include "chrome/browser/sessions/session_id.h" |
21 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" | 21 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" |
22 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
23 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
24 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
25 #include "net/url_request/url_fetcher_delegate.h" | 25 #include "net/url_request/url_fetcher_delegate.h" |
26 #include "sync/notifier/invalidation_util.h" | |
akalin
2012/08/13 22:23:58
i think IWYU has the exception that you don't have
msw
2012/08/16 02:41:51
Done.
| |
27 #include "sync/notifier/notifications_disabled_reason.h" | |
28 #include "sync/notifier/sync_notifier_observer.h" | |
26 | 29 |
27 class OAuth2AccessTokenFetcher; | 30 class OAuth2AccessTokenFetcher; |
28 class Browser; | 31 class Browser; |
29 class CloudPrintURL; | 32 class CloudPrintURL; |
30 class MockChromeToMobileService; | 33 class MockChromeToMobileService; |
31 class PrefService; | 34 class PrefService; |
32 class Profile; | 35 class Profile; |
33 | 36 |
34 namespace net { | 37 namespace net { |
35 class URLFetcher; | 38 class URLFetcher; |
36 } | 39 } |
37 | 40 |
38 // ChromeToMobileService connects to the cloud print service to enumerate | 41 // ChromeToMobileService connects to the cloud print service to enumerate |
39 // compatible mobiles owned by its profile and send URLs and MHTML snapshots. | 42 // compatible mobiles owned by its profile and send URLs and MHTML snapshots. |
40 class ChromeToMobileService : public ProfileKeyedService, | 43 class ChromeToMobileService : public ProfileKeyedService, |
41 public net::URLFetcherDelegate, | 44 public net::URLFetcherDelegate, |
42 public content::NotificationObserver, | 45 public content::NotificationObserver, |
43 public OAuth2AccessTokenConsumer { | 46 public OAuth2AccessTokenConsumer, |
47 public syncer::SyncNotifierObserver { | |
44 public: | 48 public: |
45 class Observer { | 49 class Observer { |
46 public: | 50 public: |
47 virtual ~Observer(); | 51 virtual ~Observer(); |
48 | 52 |
49 // Called on generation of the page's MHTML snapshot. | 53 // Called on generation of the page's MHTML snapshot. |
50 virtual void SnapshotGenerated(const FilePath& path, int64 bytes) = 0; | 54 virtual void SnapshotGenerated(const FilePath& path, int64 bytes) = 0; |
51 | 55 |
52 // Called after URLFetcher responses from sending the URL (and snapshot). | 56 // Called after URLFetcher responses from sending the URL (and snapshot). |
53 virtual void OnSendComplete(bool success) = 0; | 57 virtual void OnSendComplete(bool success) = 0; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 // 'enable' command line switches, otherwise relay the default enabled state. | 102 // 'enable' command line switches, otherwise relay the default enabled state. |
99 static bool IsChromeToMobileEnabled(); | 103 static bool IsChromeToMobileEnabled(); |
100 | 104 |
101 // Register the user prefs associated with this service. | 105 // Register the user prefs associated with this service. |
102 static void RegisterUserPrefs(PrefService* prefs); | 106 static void RegisterUserPrefs(PrefService* prefs); |
103 | 107 |
104 explicit ChromeToMobileService(Profile* profile); | 108 explicit ChromeToMobileService(Profile* profile); |
105 virtual ~ChromeToMobileService(); | 109 virtual ~ChromeToMobileService(); |
106 | 110 |
107 // Returns true if the service has found any registered mobile devices. | 111 // Returns true if the service has found any registered mobile devices. |
108 bool HasMobiles(); | 112 bool HasMobiles() const; |
109 | 113 |
110 // Get the non-NULL ListValue of mobile devices from the cloud print service. | 114 // Get the non-NULL ListValue of mobile devices from the cloud print service. |
111 // The list is owned by PrefService, which outlives ChromeToMobileService. | 115 // The list is owned by PrefService, which outlives ChromeToMobileService. |
112 // Each device DictionaryValue contains strings "type", "name", and "id". | 116 // Each device DictionaryValue contains strings "type", "name", and "id". |
113 // Virtual for unit test mocking. | 117 // Virtual for unit test mocking. |
114 virtual const base::ListValue* GetMobiles() const; | 118 virtual const base::ListValue* GetMobiles() const; |
115 | 119 |
116 // Request an updated mobile device list, request auth first if needed. | 120 // Request an updated mobile device list, request auth first if needed. |
117 // Virtual for unit test mocking. | 121 // Virtual for unit test mocking. |
118 virtual void RequestMobileListUpdate(); | 122 virtual void RequestMobileListUpdate(); |
(...skipping 27 matching lines...) Expand all Loading... | |
146 // content::NotificationObserver method. | 150 // content::NotificationObserver method. |
147 virtual void Observe(int type, | 151 virtual void Observe(int type, |
148 const content::NotificationSource& source, | 152 const content::NotificationSource& source, |
149 const content::NotificationDetails& details) OVERRIDE; | 153 const content::NotificationDetails& details) OVERRIDE; |
150 | 154 |
151 // OAuth2AccessTokenConsumer methods. | 155 // OAuth2AccessTokenConsumer methods. |
152 virtual void OnGetTokenSuccess(const std::string& access_token, | 156 virtual void OnGetTokenSuccess(const std::string& access_token, |
153 const base::Time& expiration_time) OVERRIDE; | 157 const base::Time& expiration_time) OVERRIDE; |
154 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | 158 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; |
155 | 159 |
160 // syncer::SyncNotifierObserver implementation. | |
161 virtual void OnNotificationsEnabled() OVERRIDE; | |
162 virtual void OnNotificationsDisabled( | |
163 syncer::NotificationsDisabledReason reason) OVERRIDE; | |
164 virtual void OnIncomingNotification( | |
165 const syncer::ObjectIdPayloadMap& id_payloads, | |
166 syncer::IncomingNotificationSource source) OVERRIDE; | |
167 | |
156 private: | 168 private: |
157 friend class MockChromeToMobileService; | 169 friend class MockChromeToMobileService; |
158 | 170 |
171 // Enable or disable Chrome To Mobile with the browsers' command controllers. | |
172 // The feature state is automatically derived from internal conditions. | |
173 void UpdateCommandState() const; | |
174 | |
159 // Handle the attempted creation of a temporary file for snapshot generation. | 175 // Handle the attempted creation of a temporary file for snapshot generation. |
160 // Alert the observer of failure or generate MHTML with an observer callback. | 176 // Alert the observer of failure or generate MHTML with an observer callback. |
161 void SnapshotFileCreated(base::WeakPtr<Observer> observer, | 177 void SnapshotFileCreated(base::WeakPtr<Observer> observer, |
162 SessionID::id_type browser_id, | 178 SessionID::id_type browser_id, |
163 const FilePath& path, | 179 const FilePath& path, |
164 bool success); | 180 bool success); |
165 | 181 |
166 // Create a cloud print job submission request for a URL or snapshot. | 182 // Create a cloud print job submission request for a URL or snapshot. |
167 net::URLFetcher* CreateRequest(const JobData& data); | 183 net::URLFetcher* CreateRequest(const JobData& data); |
168 | 184 |
169 // Initialize URLFetcher requests (search and jobs submit). | 185 // Initialize URLFetcher requests for listing devices and sending pages. |
170 void InitRequest(net::URLFetcher* request); | 186 void InitRequest(net::URLFetcher* request); |
171 | 187 |
172 // Submit a cloud print job request with the requisite data. | 188 // Submit a cloud print job request with the requisite data. |
173 void SendRequest(net::URLFetcher* request, const JobData& data); | 189 void SendRequest(net::URLFetcher* request, const JobData& data); |
174 | 190 |
175 // Send the OAuth2AccessTokenFetcher request. | 191 // Send the OAuth2AccessTokenFetcher request. |
176 // Virtual for unit test mocking. | 192 // Virtual for unit test mocking. |
177 virtual void RefreshAccessToken(); | 193 virtual void RefreshAccessToken(); |
178 | 194 |
179 // Request account information to limit cloud print access to existing users. | |
180 void RequestAccountInfo(); | |
181 | |
182 // Send the cloud print URLFetcher search request. | 195 // Send the cloud print URLFetcher search request. |
183 void RequestSearch(); | 196 void RequestSearch(); |
184 | 197 |
185 void HandleAccountInfoResponse(); | |
186 void HandleSearchResponse(); | 198 void HandleSearchResponse(); |
187 void HandleSubmitResponse(const net::URLFetcher* source); | 199 void HandleSubmitResponse(const net::URLFetcher* source); |
188 | 200 |
189 base::WeakPtrFactory<ChromeToMobileService> weak_ptr_factory_; | 201 base::WeakPtrFactory<ChromeToMobileService> weak_ptr_factory_; |
190 | 202 |
191 Profile* profile_; | 203 Profile* profile_; |
192 | 204 |
205 // The sync invalidation service enabled/disabled state. | |
206 bool sync_invalidation_enabled_; | |
207 | |
193 // Used to recieve TokenService notifications for GaiaOAuth2LoginRefreshToken. | 208 // Used to recieve TokenService notifications for GaiaOAuth2LoginRefreshToken. |
194 content::NotificationRegistrar registrar_; | 209 content::NotificationRegistrar registrar_; |
195 | 210 |
196 // Cloud print helper class and auth token. | 211 // Cloud print helper class and auth token. |
197 scoped_ptr<CloudPrintURL> cloud_print_url_; | 212 scoped_ptr<CloudPrintURL> cloud_print_url_; |
198 std::string access_token_; | 213 std::string access_token_; |
199 | 214 |
200 // The set of snapshots currently available. | 215 // The set of snapshots currently available. |
201 std::set<FilePath> snapshots_; | 216 std::set<FilePath> snapshots_; |
202 | 217 |
203 // Map URLFetchers to observers for reporting OnSendComplete. | 218 // Map URLFetchers to observers for reporting OnSendComplete. |
204 typedef std::map<const net::URLFetcher*, base::WeakPtr<Observer> > | 219 typedef std::map<const net::URLFetcher*, base::WeakPtr<Observer> > |
205 RequestObserverMap; | 220 RequestObserverMap; |
206 RequestObserverMap request_observer_map_; | 221 RequestObserverMap request_observer_map_; |
207 | 222 |
208 // The pending OAuth access token request and a timer for retrying on failure. | 223 // The pending OAuth access token request and a timer for retrying on failure. |
209 scoped_ptr<OAuth2AccessTokenFetcher> access_token_fetcher_; | 224 scoped_ptr<OAuth2AccessTokenFetcher> access_token_fetcher_; |
210 base::OneShotTimer<ChromeToMobileService> auth_retry_timer_; | 225 base::OneShotTimer<ChromeToMobileService> auth_retry_timer_; |
211 | 226 |
212 // The pending account information request and the cloud print access flag. | 227 // The pending mobile device search request and a flag to try once accessible. |
213 scoped_ptr<net::URLFetcher> account_info_request_; | |
214 bool cloud_print_accessible_; | |
215 | |
216 // The pending mobile device search request. | |
217 scoped_ptr<net::URLFetcher> search_request_; | 228 scoped_ptr<net::URLFetcher> search_request_; |
229 bool request_search_when_accessible_; | |
218 | 230 |
219 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileService); | 231 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileService); |
220 }; | 232 }; |
221 | 233 |
222 #endif // CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_ | 234 #endif // CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_ |
OLD | NEW |