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/guid.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "chrome/common/chrome_notification_types.h" | 25 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/cloud_print/cloud_print_helpers.h" | 27 #include "chrome/common/cloud_print/cloud_print_helpers.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" | |
36 #include "net/base/escape.h" | 35 #include "net/base/escape.h" |
37 #include "net/base/load_flags.h" | 36 #include "net/base/load_flags.h" |
| 37 #include "net/url_request/url_fetcher.h" |
38 #include "net/url_request/url_request_context_getter.h" | 38 #include "net/url_request/url_request_context_getter.h" |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 // The default enabled/disabled state of the Chrome To Mobile feature. | 42 // The default enabled/disabled state of the Chrome To Mobile feature. |
43 const bool kChromeToMobileEnabled = false; | 43 const bool kChromeToMobileEnabled = false; |
44 | 44 |
45 // The maximum number of retries for the URLFetcher requests. | 45 // The maximum number of retries for the URLFetcher requests. |
46 const size_t kMaxRetries = 1; | 46 const size_t kMaxRetries = 1; |
47 | 47 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } else if (observer.get()) { | 339 } else if (observer.get()) { |
340 // Signal snapshot generation failure. | 340 // Signal snapshot generation failure. |
341 observer->SnapshotGenerated(FilePath(), 0); | 341 observer->SnapshotGenerated(FilePath(), 0); |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 net::URLFetcher* ChromeToMobileService::CreateRequest( | 345 net::URLFetcher* ChromeToMobileService::CreateRequest( |
346 const RequestData& data) { | 346 const RequestData& data) { |
347 bool get = data.type != SNAPSHOT; | 347 bool get = data.type != SNAPSHOT; |
348 GURL service_url(cloud_print_url_->GetCloudPrintServiceURL()); | 348 GURL service_url(cloud_print_url_->GetCloudPrintServiceURL()); |
349 net::URLFetcher* request = content::URLFetcher::Create( | 349 net::URLFetcher* request = net::URLFetcher::Create( |
350 data.type == SEARCH ? GetSearchURL(service_url) : | 350 data.type == SEARCH ? GetSearchURL(service_url) : |
351 GetSubmitURL(service_url, data), | 351 GetSubmitURL(service_url, data), |
352 get ? net::URLFetcher::GET : net::URLFetcher::POST, this); | 352 get ? net::URLFetcher::GET : net::URLFetcher::POST, this); |
353 request->SetRequestContext(profile_->GetRequestContext()); | 353 request->SetRequestContext(profile_->GetRequestContext()); |
354 request->SetMaxRetries(kMaxRetries); | 354 request->SetMaxRetries(kMaxRetries); |
355 request->SetExtraRequestHeaders("Authorization: OAuth " + | 355 request->SetExtraRequestHeaders("Authorization: OAuth " + |
356 access_token_ + "\r\n" + cloud_print::kChromeCloudPrintProxyHeader); | 356 access_token_ + "\r\n" + cloud_print::kChromeCloudPrintProxyHeader); |
357 request->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | | 357 request->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
358 net::LOAD_DO_NOT_SAVE_COOKIES); | 358 net::LOAD_DO_NOT_SAVE_COOKIES); |
359 return request; | 359 return request; |
(...skipping 30 matching lines...) Expand all Loading... |
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; |
397 } | 397 } |
398 | 398 |
399 account_info_request_.reset( | 399 account_info_request_.reset( |
400 content::URLFetcher::Create(url, net::URLFetcher::GET, this)); | 400 net::URLFetcher::Create(url, net::URLFetcher::GET, this)); |
401 account_info_request_->SetRequestContext(profile_->GetRequestContext()); | 401 account_info_request_->SetRequestContext(profile_->GetRequestContext()); |
402 account_info_request_->SetMaxRetries(kMaxRetries); | 402 account_info_request_->SetMaxRetries(kMaxRetries); |
403 // This request sends the user's cookie to check the cloud print service flag. | 403 // This request sends the user's cookie to check the cloud print service flag. |
404 account_info_request_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); | 404 account_info_request_->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
405 account_info_request_->Start(); | 405 account_info_request_->Start(); |
406 } | 406 } |
407 | 407 |
408 void ChromeToMobileService::RequestSearch() { | 408 void ChromeToMobileService::RequestSearch() { |
409 DCHECK(!access_token_.empty()); | 409 DCHECK(!access_token_.empty()); |
410 | 410 |
(...skipping 99 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 |