| 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 27 matching lines...) Expand all Loading... |
| 38 #include "content/public/browser/notification_details.h" | 38 #include "content/public/browser/notification_details.h" |
| 39 #include "content/public/browser/notification_source.h" | 39 #include "content/public/browser/notification_source.h" |
| 40 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
| 41 #include "google/cacheinvalidation/include/types.h" | 41 #include "google/cacheinvalidation/include/types.h" |
| 42 #include "google/cacheinvalidation/types.pb.h" | 42 #include "google/cacheinvalidation/types.pb.h" |
| 43 #include "google_apis/gaia/gaia_constants.h" | 43 #include "google_apis/gaia/gaia_constants.h" |
| 44 #include "google_apis/gaia/gaia_urls.h" | 44 #include "google_apis/gaia/gaia_urls.h" |
| 45 #include "google_apis/gaia/oauth2_access_token_fetcher.h" | 45 #include "google_apis/gaia/oauth2_access_token_fetcher.h" |
| 46 #include "net/base/escape.h" | 46 #include "net/base/escape.h" |
| 47 #include "net/base/load_flags.h" | 47 #include "net/base/load_flags.h" |
| 48 #include "net/base/mime_util.h" |
| 48 #include "net/http/http_status_code.h" | 49 #include "net/http/http_status_code.h" |
| 49 #include "net/url_request/url_fetcher.h" | 50 #include "net/url_request/url_fetcher.h" |
| 50 #include "net/url_request/url_request_context_getter.h" | 51 #include "net/url_request/url_request_context_getter.h" |
| 51 #include "sync/notifier/invalidation_util.h" | 52 #include "sync/notifier/invalidation_util.h" |
| 52 | 53 |
| 53 namespace { | 54 namespace { |
| 54 | 55 |
| 55 enum Metric { | 56 enum Metric { |
| 56 DEVICES_REQUESTED = 0, // Cloud print was contacted to list devices. | 57 DEVICES_REQUESTED = 0, // Cloud print was contacted to list devices. |
| 57 DEVICES_AVAILABLE, // Cloud print returned 1+ compatible devices. | 58 DEVICES_AVAILABLE, // Cloud print returned 1+ compatible devices. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 base::JSONWriter::Write(&json, &json_string); | 131 base::JSONWriter::Write(&json, &json_string); |
| 131 return json_string; | 132 return json_string; |
| 132 } | 133 } |
| 133 | 134 |
| 134 // Get the POST content type for a cloud print job submission. | 135 // Get the POST content type for a cloud print job submission. |
| 135 std::string GetContentType(ChromeToMobileService::JobType type) { | 136 std::string GetContentType(ChromeToMobileService::JobType type) { |
| 136 return (type == ChromeToMobileService::SNAPSHOT) ? | 137 return (type == ChromeToMobileService::SNAPSHOT) ? |
| 137 "multipart/related" : "text/plain"; | 138 "multipart/related" : "text/plain"; |
| 138 } | 139 } |
| 139 | 140 |
| 140 // Utility function to call cloud_print::AddMultipartValueForUpload. | 141 // Utility function to call net::AddMultipartValueForUpload. |
| 141 void AddValue(const std::string& value_name, | 142 void AddValue(const std::string& value_name, |
| 142 const std::string& value, | 143 const std::string& value, |
| 143 const std::string& mime_boundary, | 144 const std::string& mime_boundary, |
| 144 std::string* post_data) { | 145 std::string* post_data) { |
| 145 cloud_print::AddMultipartValueForUpload(value_name, value, mime_boundary, | 146 net::AddMultipartValueForUpload(value_name, value, mime_boundary, |
| 146 std::string(), post_data); | 147 std::string(), post_data); |
| 147 } | 148 } |
| 148 | 149 |
| 149 // Append the Chrome To Mobile client query parameter, used by cloud print. | 150 // Append the Chrome To Mobile client query parameter, used by cloud print. |
| 150 GURL AppendClientQueryParam(const GURL& url) { | 151 GURL AppendClientQueryParam(const GURL& url) { |
| 151 GURL::Replacements replacements; | 152 GURL::Replacements replacements; |
| 152 std::string query("client=chrome-to-mobile"); | 153 std::string query("client=chrome-to-mobile"); |
| 153 replacements.SetQueryStr(query); | 154 replacements.SetQueryStr(query); |
| 154 return url.ReplaceComponents(replacements); | 155 return url.ReplaceComponents(replacements); |
| 155 } | 156 } |
| 156 | 157 |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 break; | 577 break; |
| 577 default: | 578 default: |
| 578 NOTREACHED() << "Unknown mobile_os " << data.mobile_os; | 579 NOTREACHED() << "Unknown mobile_os " << data.mobile_os; |
| 579 break; | 580 break; |
| 580 } | 581 } |
| 581 | 582 |
| 582 AddValue("title", UTF16ToUTF8(data.title), bound, &post); | 583 AddValue("title", UTF16ToUTF8(data.title), bound, &post); |
| 583 AddValue("contentType", GetContentType(data.type), bound, &post); | 584 AddValue("contentType", GetContentType(data.type), bound, &post); |
| 584 | 585 |
| 585 // Add the snapshot or use dummy content to workaround a URL submission error. | 586 // Add the snapshot or use dummy content to workaround a URL submission error. |
| 586 cloud_print::AddMultipartValueForUpload("content", | 587 net::AddMultipartValueForUpload("content", |
| 587 data.snapshot_content.empty() ? "content" : data.snapshot_content, | 588 data.snapshot_content.empty() ? "content" : data.snapshot_content, |
| 588 bound, "text/mhtml", &post); | 589 bound, "text/mhtml", &post); |
| 589 post.append("--" + bound + "--\r\n"); | 590 net::AddMultipartTerminateForUpload(bound, &post); |
| 590 | 591 |
| 591 LogMetric(data.type == SNAPSHOT ? SENDING_SNAPSHOT : SENDING_URL); | 592 LogMetric(data.type == SNAPSHOT ? SENDING_SNAPSHOT : SENDING_URL); |
| 592 net::URLFetcher* request = net::URLFetcher::Create( | 593 net::URLFetcher* request = net::URLFetcher::Create( |
| 593 GetSubmitURL(cloud_print_url_), net::URLFetcher::POST, this); | 594 GetSubmitURL(cloud_print_url_), net::URLFetcher::POST, this); |
| 594 url_fetchers_.push_back(request); | 595 url_fetchers_.push_back(request); |
| 595 InitRequest(request); | 596 InitRequest(request); |
| 596 request_observer_map_[request] = observer; | 597 request_observer_map_[request] = observer; |
| 597 request->SetUploadData("multipart/form-data; boundary=" + bound, post); | 598 request->SetUploadData("multipart/form-data; boundary=" + bound, post); |
| 598 request->Start(); | 599 request->Start(); |
| 599 } | 600 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 | 754 |
| 754 // Report failure below and ignore the second response. | 755 // Report failure below and ignore the second response. |
| 755 request_observer_map_.erase(other); | 756 request_observer_map_.erase(other); |
| 756 break; | 757 break; |
| 757 } | 758 } |
| 758 } | 759 } |
| 759 | 760 |
| 760 if (observer.get()) | 761 if (observer.get()) |
| 761 observer->OnSendComplete(success); | 762 observer->OnSendComplete(success); |
| 762 } | 763 } |
| OLD | NEW |