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 #include "chrome/browser/chrome_to_mobile_service.h" | 5 #include "chrome/browser/chrome_to_mobile_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/guid.h" |
10 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
11 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
13 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 16 #include "base/values.h" |
16 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
17 #include "chrome/browser/content_settings/cookie_settings.h" | 18 #include "chrome/browser/content_settings/cookie_settings.h" |
18 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 19 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/signin/token_service.h" | 21 #include "chrome/browser/signin/token_service.h" |
21 #include "chrome/browser/signin/token_service_factory.h" | 22 #include "chrome/browser/signin/token_service_factory.h" |
22 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
24 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
25 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 27 #include "chrome/common/cloud_print/cloud_print_helpers.h" |
27 #include "chrome/common/guid.h" | |
28 #include "chrome/common/net/gaia/gaia_constants.h" | 28 #include "chrome/common/net/gaia/gaia_constants.h" |
29 #include "chrome/common/net/gaia/gaia_urls.h" | 29 #include "chrome/common/net/gaia/gaia_urls.h" |
30 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" | 30 #include "chrome/common/net/gaia/oauth2_access_token_fetcher.h" |
31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/notification_details.h" | 32 #include "content/public/browser/notification_details.h" |
33 #include "content/public/browser/notification_source.h" | 33 #include "content/public/browser/notification_source.h" |
34 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
35 #include "content/public/common/url_fetcher.h" | 35 #include "content/public/common/url_fetcher.h" |
36 #include "net/base/escape.h" | 36 #include "net/base/escape.h" |
37 #include "net/base/load_flags.h" | 37 #include "net/base/load_flags.h" |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 243 |
244 DCHECK(!access_token_.empty()); | 244 DCHECK(!access_token_.empty()); |
245 RequestData data; | 245 RequestData data; |
246 data.mobile_id = mobile_id; | 246 data.mobile_id = mobile_id; |
247 content::WebContents* web_contents = | 247 content::WebContents* web_contents = |
248 browser::FindLastActiveWithProfile(profile_)->GetActiveWebContents(); | 248 browser::FindLastActiveWithProfile(profile_)->GetActiveWebContents(); |
249 data.url = web_contents->GetURL(); | 249 data.url = web_contents->GetURL(); |
250 data.title = web_contents->GetTitle(); | 250 data.title = web_contents->GetTitle(); |
251 data.snapshot_path = snapshot; | 251 data.snapshot_path = snapshot; |
252 bool send_snapshot = !snapshot.empty(); | 252 bool send_snapshot = !snapshot.empty(); |
253 data.snapshot_id = send_snapshot ? guid::GenerateGUID() : std::string(); | 253 data.snapshot_id = send_snapshot ? base::GenerateGUID() : std::string(); |
254 data.type = send_snapshot ? DELAYED_SNAPSHOT : URL; | 254 data.type = send_snapshot ? DELAYED_SNAPSHOT : URL; |
255 | 255 |
256 net::URLFetcher* submit_url = CreateRequest(data); | 256 net::URLFetcher* submit_url = CreateRequest(data); |
257 request_observer_map_[submit_url] = observer; | 257 request_observer_map_[submit_url] = observer; |
258 submit_url->Start(); | 258 submit_url->Start(); |
259 | 259 |
260 if (send_snapshot) { | 260 if (send_snapshot) { |
261 LogMetric(SENDING_SNAPSHOT); | 261 LogMetric(SENDING_SNAPSHOT); |
262 | 262 |
263 data.type = SNAPSHOT; | 263 data.type = SNAPSHOT; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 access_token_fetcher_->Start(gaia_urls->oauth2_chrome_client_id(), | 376 access_token_fetcher_->Start(gaia_urls->oauth2_chrome_client_id(), |
377 gaia_urls->oauth2_chrome_client_secret(), token, scopes); | 377 gaia_urls->oauth2_chrome_client_secret(), token, scopes); |
378 } | 378 } |
379 | 379 |
380 void ChromeToMobileService::RequestAccountInfo() { | 380 void ChromeToMobileService::RequestAccountInfo() { |
381 // Deny concurrent requests. | 381 // Deny concurrent requests. |
382 if (account_info_request_.get()) | 382 if (account_info_request_.get()) |
383 return; | 383 return; |
384 | 384 |
385 std::string url_string = StringPrintf(kAccountInfoURL, | 385 std::string url_string = StringPrintf(kAccountInfoURL, |
386 guid::GenerateGUID().c_str(), kChromeToMobileRequestor); | 386 base::GenerateGUID().c_str(), kChromeToMobileRequestor); |
387 GURL url(url_string); | 387 GURL url(url_string); |
388 | 388 |
389 // Account information is read from the profile's cookie. If cookies are | 389 // Account information is read from the profile's cookie. If cookies are |
390 // blocked, access cloud print directly to list any potential devices. | 390 // blocked, access cloud print directly to list any potential devices. |
391 scoped_refptr<CookieSettings> cookie_settings = | 391 scoped_refptr<CookieSettings> cookie_settings = |
392 CookieSettings::Factory::GetForProfile(profile_); | 392 CookieSettings::Factory::GetForProfile(profile_); |
393 if (cookie_settings && !cookie_settings->IsReadingCookieAllowed(url, url)) { | 393 if (cookie_settings && !cookie_settings->IsReadingCookieAllowed(url, url)) { |
394 cloud_print_accessible_ = true; | 394 cloud_print_accessible_ = true; |
395 RequestMobileListUpdate(); | 395 RequestMobileListUpdate(); |
396 return; | 396 return; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 | 510 |
511 // Ensure a second response is not sent after reporting failure below. | 511 // Ensure a second response is not sent after reporting failure below. |
512 request_observer_map_.erase(other); | 512 request_observer_map_.erase(other); |
513 break; | 513 break; |
514 } | 514 } |
515 } | 515 } |
516 | 516 |
517 LogMetric(success ? SEND_SUCCESS : SEND_ERROR); | 517 LogMetric(success ? SEND_SUCCESS : SEND_ERROR); |
518 observer->OnSendComplete(success); | 518 observer->OnSendComplete(success); |
519 } | 519 } |
OLD | NEW |