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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/string16.h" | 17 #include "base/string16.h" |
18 #include "base/timer.h" | 18 #include "base/timer.h" |
19 #include "chrome/browser/profiles/profile_keyed_service.h" | 19 #include "chrome/browser/profiles/profile_keyed_service.h" |
20 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" | 20 #include "chrome/common/net/gaia/oauth2_access_token_consumer.h" |
21 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
23 #include "content/public/common/url_fetcher_delegate.h" | |
24 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 24 #include "net/url_request/url_fetcher_delegate.h" |
25 | 25 |
26 class OAuth2AccessTokenFetcher; | 26 class OAuth2AccessTokenFetcher; |
27 class CloudPrintURL; | 27 class CloudPrintURL; |
28 class MockChromeToMobileService; | 28 class MockChromeToMobileService; |
29 class Profile; | 29 class Profile; |
30 | 30 |
31 namespace base { | 31 namespace base { |
32 class DictionaryValue; | 32 class DictionaryValue; |
33 } | 33 } |
34 | 34 |
| 35 namespace net { |
| 36 class URLFetcher; |
| 37 } |
| 38 |
35 // ChromeToMobileService connects to the cloud print service to enumerate | 39 // ChromeToMobileService connects to the cloud print service to enumerate |
36 // compatible mobiles owned by its profile and send URLs and MHTML snapshots. | 40 // compatible mobiles owned by its profile and send URLs and MHTML snapshots. |
37 class ChromeToMobileService : public ProfileKeyedService, | 41 class ChromeToMobileService : public ProfileKeyedService, |
38 public content::URLFetcherDelegate, | 42 public net::URLFetcherDelegate, |
39 public content::NotificationObserver, | 43 public content::NotificationObserver, |
40 public OAuth2AccessTokenConsumer { | 44 public OAuth2AccessTokenConsumer { |
41 public: | 45 public: |
42 class Observer { | 46 class Observer { |
43 public: | 47 public: |
44 virtual ~Observer(); | 48 virtual ~Observer(); |
45 | 49 |
46 // Called on generation of the page's MHTML snapshot. | 50 // Called on generation of the page's MHTML snapshot. |
47 virtual void SnapshotGenerated(const FilePath& path, int64 bytes) = 0; | 51 virtual void SnapshotGenerated(const FilePath& path, int64 bytes) = 0; |
48 | 52 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 base::WeakPtr<Observer> observer); | 116 base::WeakPtr<Observer> observer); |
113 | 117 |
114 // Delete the snapshot file (should be called on observer destruction). | 118 // Delete the snapshot file (should be called on observer destruction). |
115 // Virtual for unit test mocking. | 119 // Virtual for unit test mocking. |
116 virtual void DeleteSnapshot(const FilePath& snapshot); | 120 virtual void DeleteSnapshot(const FilePath& snapshot); |
117 | 121 |
118 // Log a metric for the "ChromeToMobile.Service" histogram. | 122 // Log a metric for the "ChromeToMobile.Service" histogram. |
119 // Virtual for unit test mocking. | 123 // Virtual for unit test mocking. |
120 virtual void LogMetric(Metric metric); | 124 virtual void LogMetric(Metric metric); |
121 | 125 |
122 // content::URLFetcherDelegate method. | 126 // net::URLFetcherDelegate method. |
123 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 127 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
124 | 128 |
125 // content::NotificationObserver method. | 129 // content::NotificationObserver method. |
126 virtual void Observe(int type, | 130 virtual void Observe(int type, |
127 const content::NotificationSource& source, | 131 const content::NotificationSource& source, |
128 const content::NotificationDetails& details) OVERRIDE; | 132 const content::NotificationDetails& details) OVERRIDE; |
129 | 133 |
130 // OAuth2AccessTokenConsumer methods. | 134 // OAuth2AccessTokenConsumer methods. |
131 virtual void OnGetTokenSuccess(const std::string& access_token) OVERRIDE; | 135 virtual void OnGetTokenSuccess(const std::string& access_token) OVERRIDE; |
132 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; | 136 virtual void OnGetTokenFailure(const GoogleServiceAuthError& error) OVERRIDE; |
133 | 137 |
134 private: | 138 private: |
135 friend class MockChromeToMobileService; | 139 friend class MockChromeToMobileService; |
136 | 140 |
137 // Handle the attempted creation of a temporary file for snapshot generation. | 141 // Handle the attempted creation of a temporary file for snapshot generation. |
138 // Alert the observer of failure or generate MHTML with an observer callback. | 142 // Alert the observer of failure or generate MHTML with an observer callback. |
139 void SnapshotFileCreated(base::WeakPtr<Observer> observer, | 143 void SnapshotFileCreated(base::WeakPtr<Observer> observer, |
140 const FilePath& path, | 144 const FilePath& path, |
141 bool success); | 145 bool success); |
142 | 146 |
143 // Utility function to create URLFetcher requests. | 147 // Utility function to create URLFetcher requests. |
144 content::URLFetcher* CreateRequest(const RequestData& data); | 148 net::URLFetcher* CreateRequest(const RequestData& data); |
145 | 149 |
146 // Send the OAuth2AccessTokenFetcher request. | 150 // Send the OAuth2AccessTokenFetcher request. |
147 // Virtual for unit test mocking. | 151 // Virtual for unit test mocking. |
148 virtual void RefreshAccessToken(); | 152 virtual void RefreshAccessToken(); |
149 | 153 |
150 // Request account information to limit cloud print access to existing users. | 154 // Request account information to limit cloud print access to existing users. |
151 void RequestAccountInfo(); | 155 void RequestAccountInfo(); |
152 | 156 |
153 // Send the cloud print URLFetcher search request. | 157 // Send the cloud print URLFetcher search request. |
154 void RequestSearch(); | 158 void RequestSearch(); |
(...skipping 22 matching lines...) Expand all Loading... |
177 // Map URLFetchers to observers for reporting OnSendComplete. | 181 // Map URLFetchers to observers for reporting OnSendComplete. |
178 typedef std::map<const net::URLFetcher*, base::WeakPtr<Observer> > | 182 typedef std::map<const net::URLFetcher*, base::WeakPtr<Observer> > |
179 RequestObserverMap; | 183 RequestObserverMap; |
180 RequestObserverMap request_observer_map_; | 184 RequestObserverMap request_observer_map_; |
181 | 185 |
182 // The pending OAuth access token request and a timer for retrying on failure. | 186 // The pending OAuth access token request and a timer for retrying on failure. |
183 scoped_ptr<OAuth2AccessTokenFetcher> access_token_fetcher_; | 187 scoped_ptr<OAuth2AccessTokenFetcher> access_token_fetcher_; |
184 base::OneShotTimer<ChromeToMobileService> auth_retry_timer_; | 188 base::OneShotTimer<ChromeToMobileService> auth_retry_timer_; |
185 | 189 |
186 // The pending account information request and the cloud print access flag. | 190 // The pending account information request and the cloud print access flag. |
187 scoped_ptr<content::URLFetcher> account_info_request_; | 191 scoped_ptr<net::URLFetcher> account_info_request_; |
188 bool cloud_print_accessible_; | 192 bool cloud_print_accessible_; |
189 | 193 |
190 // The pending mobile device search request; and the time of the last request. | 194 // The pending mobile device search request; and the time of the last request. |
191 scoped_ptr<content::URLFetcher> search_request_; | 195 scoped_ptr<net::URLFetcher> search_request_; |
192 base::TimeTicks previous_search_time_; | 196 base::TimeTicks previous_search_time_; |
193 | 197 |
194 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileService); | 198 DISALLOW_COPY_AND_ASSIGN(ChromeToMobileService); |
195 }; | 199 }; |
196 | 200 |
197 #endif // CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_ | 201 #endif // CHROME_BROWSER_CHROME_TO_MOBILE_SERVICE_H_ |
OLD | NEW |