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" | |
15 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
16 #include "base/string16.h" | 15 #include "base/string16.h" |
17 #include "base/timer.h" | 16 #include "base/timer.h" |
18 #include "base/values.h" | 17 #include "base/values.h" |
19 #include "chrome/browser/profiles/profile_keyed_service.h" | 18 #include "chrome/browser/profiles/profile_keyed_service.h" |
20 #include "chrome/browser/sessions/session_id.h" | 19 #include "chrome/browser/sessions/session_id.h" |
21 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" | 20 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" |
22 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
23 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
24 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 // 'enable' command line switches, otherwise relay the default enabled state. | 97 // 'enable' command line switches, otherwise relay the default enabled state. |
99 static bool IsChromeToMobileEnabled(); | 98 static bool IsChromeToMobileEnabled(); |
100 | 99 |
101 // Register the user prefs associated with this service. | 100 // Register the user prefs associated with this service. |
102 static void RegisterUserPrefs(PrefService* prefs); | 101 static void RegisterUserPrefs(PrefService* prefs); |
103 | 102 |
104 explicit ChromeToMobileService(Profile* profile); | 103 explicit ChromeToMobileService(Profile* profile); |
105 virtual ~ChromeToMobileService(); | 104 virtual ~ChromeToMobileService(); |
106 | 105 |
107 // Returns true if the service has found any registered mobile devices. | 106 // Returns true if the service has found any registered mobile devices. |
108 bool HasMobiles(); | 107 bool HasMobiles() const; |
109 | 108 |
110 // Get the non-NULL ListValue of mobile devices from the cloud print service. | 109 // Get the non-NULL ListValue of mobile devices from the cloud print service. |
111 // The list is owned by PrefService, which outlives ChromeToMobileService. | 110 // The list is owned by PrefService, which outlives ChromeToMobileService. |
112 // Each device DictionaryValue contains strings "type", "name", and "id". | 111 // Each device DictionaryValue contains strings "type", "name", and "id". |
113 // Virtual for unit test mocking. | 112 // Virtual for unit test mocking. |
114 virtual const base::ListValue* GetMobiles() const; | 113 virtual const base::ListValue* GetMobiles() const; |
115 | 114 |
116 // Request an updated mobile device list, request auth first if needed. | 115 // Request an updated mobile device list, request auth first if needed. |
117 // Virtual for unit test mocking. | 116 // Virtual for unit test mocking. |
118 virtual void RequestMobileListUpdate(); | 117 virtual void RequestMobileListUpdate(); |
(...skipping 30 matching lines...) Expand all Loading... |
149 const content::NotificationDetails& details) OVERRIDE; | 148 const content::NotificationDetails& details) OVERRIDE; |
150 | 149 |
151 // OAuth2AccessTokenConsumer methods. | 150 // OAuth2AccessTokenConsumer methods. |
152 virtual void OnGetTokenSuccess(const std::string& access_token, | 151 virtual void OnGetTokenSuccess(const std::string& access_token, |
153 const base::Time& expiration_time) OVERRIDE; | 152 const base::Time& expiration_time) OVERRIDE; |
154 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | 153 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; |
155 | 154 |
156 private: | 155 private: |
157 friend class MockChromeToMobileService; | 156 friend class MockChromeToMobileService; |
158 | 157 |
| 158 // Enable or disable Chrome To Mobile with the browsers' command controllers. |
| 159 // The feature state is automatically derived from internal conditions. |
| 160 void UpdateCommandState() const; |
| 161 |
159 // Handle the attempted creation of a temporary file for snapshot generation. | 162 // Handle the attempted creation of a temporary file for snapshot generation. |
160 // Alert the observer of failure or generate MHTML with an observer callback. | 163 // Alert the observer of failure or generate MHTML with an observer callback. |
161 void SnapshotFileCreated(base::WeakPtr<Observer> observer, | 164 void SnapshotFileCreated(base::WeakPtr<Observer> observer, |
162 SessionID::id_type browser_id, | 165 SessionID::id_type browser_id, |
163 const FilePath& path, | 166 const FilePath& path, |
164 bool success); | 167 bool success); |
165 | 168 |
166 // Create a cloud print job submission request for a URL or snapshot. | 169 // Create a cloud print job submission request for a URL or snapshot. |
167 net::URLFetcher* CreateRequest(const JobData& data); | 170 net::URLFetcher* CreateRequest(const JobData& data); |
168 | 171 |
169 // Initialize URLFetcher requests (search and jobs submit). | 172 // Initialize cloud print URLFetcher requests. |
170 void InitRequest(net::URLFetcher* request); | 173 void InitRequest(net::URLFetcher* request); |
171 | 174 |
172 // Submit a cloud print job request with the requisite data. | 175 // Submit a cloud print job request with the requisite data. |
173 void SendRequest(net::URLFetcher* request, const JobData& data); | 176 void SendRequest(net::URLFetcher* request, const JobData& data); |
174 | 177 |
175 // Send the OAuth2AccessTokenFetcher request. | 178 // Send the OAuth2AccessTokenFetcher request. |
176 // Virtual for unit test mocking. | 179 // Virtual for unit test mocking. |
177 virtual void RefreshAccessToken(); | 180 virtual void RequestAccessToken(); |
178 | 181 |
179 // Request account information to limit cloud print access to existing users. | 182 // Request account information to limit cloud print access to existing users. |
180 void RequestAccountInfo(); | 183 void RequestAccountInfo(); |
181 | 184 |
182 // Send the cloud print URLFetcher search request. | 185 // Send the cloud print URLFetcher device search request. |
183 void RequestSearch(); | 186 void RequestDeviceSearch(); |
184 | 187 |
185 void HandleAccountInfoResponse(); | 188 void HandleAccountInfoResponse(); |
186 void HandleSearchResponse(); | 189 void HandleSearchResponse(); |
187 void HandleSubmitResponse(const net::URLFetcher* source); | 190 void HandleSubmitResponse(const net::URLFetcher* source); |
188 | 191 |
189 base::WeakPtrFactory<ChromeToMobileService> weak_ptr_factory_; | 192 base::WeakPtrFactory<ChromeToMobileService> weak_ptr_factory_; |
190 | 193 |
191 Profile* profile_; | 194 Profile* profile_; |
192 | 195 |
193 // Used to recieve TokenService notifications for GaiaOAuth2LoginRefreshToken. | 196 // Used to recieve TokenService notifications for GaiaOAuth2LoginRefreshToken. |
(...skipping 19 matching lines...) Expand all Loading... |
213 scoped_ptr<net::URLFetcher> account_info_request_; | 216 scoped_ptr<net::URLFetcher> account_info_request_; |
214 bool cloud_print_accessible_; | 217 bool cloud_print_accessible_; |
215 | 218 |
216 // The pending mobile device search request. | 219 // The pending mobile device search request. |
217 scoped_ptr<net::URLFetcher> search_request_; | 220 scoped_ptr<net::URLFetcher> search_request_; |
218 | 221 |
219 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileService); | 222 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileService); |
220 }; | 223 }; |
221 | 224 |
222 #endif // CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_ | 225 #endif // CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_ |
OLD | NEW |