| OLD | NEW |
| 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 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/extensions/api/dial/device_description_fetcher.h" | 5 #include "chrome/browser/extensions/api/dial/device_description_fetcher.h" |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "chrome/browser/extensions/api/dial/dial_device_data.h" | 9 #include "chrome/browser/extensions/api/dial/dial_device_data.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "net/base/load_flags.h" | 12 #include "net/base/load_flags.h" |
| 13 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
| 14 #include "net/http/http_status_code.h" | 14 #include "net/http/http_status_code.h" |
| 15 #include "net/http/http_util.h" | 15 #include "net/http/http_util.h" |
| 16 #include "net/traffic_annotation/network_traffic_annotation.h" |
| 16 #include "net/url_request/url_fetcher.h" | 17 #include "net/url_request/url_fetcher.h" |
| 17 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
| 18 | 19 |
| 19 using content::BrowserThread; | 20 using content::BrowserThread; |
| 20 | 21 |
| 21 constexpr char kApplicationUrlHeaderName[] = "Application-URL"; | 22 constexpr char kApplicationUrlHeaderName[] = "Application-URL"; |
| 22 constexpr int kMaxRetries = 3; | 23 constexpr int kMaxRetries = 3; |
| 23 // DIAL devices are unlikely to expose uPnP functions other than DIAL, so 256kb | 24 // DIAL devices are unlikely to expose uPnP functions other than DIAL, so 256kb |
| 24 // should be more than sufficient. | 25 // should be more than sufficient. |
| 25 constexpr int kMaxDescriptionSizeBytes = 262144; | 26 constexpr int kMaxDescriptionSizeBytes = 262144; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 42 } | 43 } |
| 43 | 44 |
| 44 DeviceDescriptionFetcher::~DeviceDescriptionFetcher() { | 45 DeviceDescriptionFetcher::~DeviceDescriptionFetcher() { |
| 45 DCHECK(thread_checker_.CalledOnValidThread()); | 46 DCHECK(thread_checker_.CalledOnValidThread()); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void DeviceDescriptionFetcher::Start() { | 49 void DeviceDescriptionFetcher::Start() { |
| 49 DCHECK(thread_checker_.CalledOnValidThread()); | 50 DCHECK(thread_checker_.CalledOnValidThread()); |
| 50 DCHECK(!fetcher_); | 51 DCHECK(!fetcher_); |
| 51 | 52 |
| 53 net::NetworkTrafficAnnotationTag traffic_annotation = |
| 54 net::DefineNetworkTrafficAnnotation("dial_get_device_description", R"( |
| 55 semantics { |
| 56 sender: "DIAL" |
| 57 description: |
| 58 "Chromium sends a request to a device (such as a smart TV) " |
| 59 "discovered via the DIAL (Disovery and Launch) protocol to obtain " |
| 60 "its device description. Chromium then uses the device description " |
| 61 "to determine the capabilities of the device to be used as a " |
| 62 "target for casting media content." |
| 63 trigger: |
| 64 "A new or updated device has been discovered via DIAL in the local " |
| 65 "network." |
| 66 data: "An HTTP GET request." |
| 67 destination: OTHER |
| 68 destination_other: |
| 69 "A device in the local network." |
| 70 } |
| 71 policy { |
| 72 cookies_allowed: false |
| 73 setting: |
| 74 "This feature cannot be disabled by settings and can only be " |
| 75 "disabled by media-router flag." |
| 76 chrome_policy { |
| 77 EnableMediaRouter { |
| 78 policy_options {mode: MANDATORY} |
| 79 EnableMediaRouter: false |
| 80 } |
| 81 } |
| 82 })"); |
| 52 // DIAL returns device descriptions via GET request. | 83 // DIAL returns device descriptions via GET request. |
| 53 fetcher_ = | 84 fetcher_ = |
| 54 net::URLFetcher::Create(kURLFetcherIDForTest, device_description_url_, | 85 net::URLFetcher::Create(kURLFetcherIDForTest, device_description_url_, |
| 55 net::URLFetcher::GET, this); | 86 net::URLFetcher::GET, this, traffic_annotation); |
| 56 | 87 |
| 57 // net::LOAD_BYPASS_PROXY: Proxies almost certainly hurt more cases than they | 88 // net::LOAD_BYPASS_PROXY: Proxies almost certainly hurt more cases than they |
| 58 // help. | 89 // help. |
| 59 // net::LOAD_DISABLE_CACHE: The request should not touch the cache. | 90 // net::LOAD_DISABLE_CACHE: The request should not touch the cache. |
| 60 // net::LOAD_DO_NOT_{SAVE,SEND}_COOKIES: The request should not touch cookies. | 91 // net::LOAD_DO_NOT_{SAVE,SEND}_COOKIES: The request should not touch cookies. |
| 61 // net::LOAD_DO_NOT_SEND_AUTH_DATA: The request should not send auth data. | 92 // net::LOAD_DO_NOT_SEND_AUTH_DATA: The request should not send auth data. |
| 62 fetcher_->SetLoadFlags(net::LOAD_BYPASS_PROXY | net::LOAD_DISABLE_CACHE | | 93 fetcher_->SetLoadFlags(net::LOAD_BYPASS_PROXY | net::LOAD_DISABLE_CACHE | |
| 63 net::LOAD_DO_NOT_SAVE_COOKIES | | 94 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 64 net::LOAD_DO_NOT_SEND_COOKIES | | 95 net::LOAD_DO_NOT_SEND_COOKIES | |
| 65 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 96 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 int64_t current, | 173 int64_t current, |
| 143 int64_t total) {} | 174 int64_t total) {} |
| 144 | 175 |
| 145 void DeviceDescriptionFetcher::ReportError(const std::string& message) { | 176 void DeviceDescriptionFetcher::ReportError(const std::string& message) { |
| 146 std::move(error_cb_).Run(message); | 177 std::move(error_cb_).Run(message); |
| 147 } | 178 } |
| 148 | 179 |
| 149 } // namespace dial | 180 } // namespace dial |
| 150 } // namespace api | 181 } // namespace api |
| 151 } // namespace extensions | 182 } // namespace extensions |
| OLD | NEW |