Chromium Code Reviews| 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 "base/strings/string_util.h" | 5 #include "base/strings/string_util.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "chrome/browser/extensions/api/dial/device_description_fetcher.h" | 7 #include "chrome/browser/extensions/api/dial/device_description_fetcher.h" |
| 8 #include "chrome/browser/extensions/api/dial/dial_device_data.h" | 8 #include "chrome/browser/extensions/api/dial/dial_device_data.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 // DIAL devices are unlikely to expose uPnP functions other than DIAL, so 256kb | 21 // DIAL devices are unlikely to expose uPnP functions other than DIAL, so 256kb |
| 22 // should be more than sufficient. | 22 // should be more than sufficient. |
| 23 constexpr int kMaxDescriptionSizeBytes = 262144; | 23 constexpr int kMaxDescriptionSizeBytes = 262144; |
| 24 | 24 |
| 25 namespace extensions { | 25 namespace extensions { |
| 26 namespace api { | 26 namespace api { |
| 27 namespace dial { | 27 namespace dial { |
| 28 | 28 |
| 29 DeviceDescriptionFetcher::DeviceDescriptionFetcher( | 29 DeviceDescriptionFetcher::DeviceDescriptionFetcher( |
| 30 const GURL& device_description_url, | 30 const GURL& device_description_url, |
| 31 Profile* profile, | 31 net::URLRequestContextGetter* request_context, |
| 32 BrowserThread::ID thread_id, | |
|
imcheng
2017/03/06 20:56:30
thread_id can be removed now.
zhaobin
2017/03/07 00:13:18
Done.
| |
| 32 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb, | 33 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb, |
| 33 base::OnceCallback<void(const std::string&)> error_cb) | 34 base::OnceCallback<void(const std::string&)> error_cb) |
| 34 : device_description_url_(device_description_url), | 35 : device_description_url_(device_description_url), |
| 35 profile_(profile), | 36 request_context_(request_context), |
| 36 success_cb_(std::move(success_cb)), | 37 success_cb_(std::move(success_cb)), |
| 37 error_cb_(std::move(error_cb)) { | 38 error_cb_(std::move(error_cb)) { |
| 38 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 39 DCHECK(thread_checker_.CalledOnValidThread()); |
|
imcheng
2017/03/06 20:56:30
this DCHECK is not necessary since it's just been
zhaobin
2017/03/07 00:13:18
Done.
| |
| 39 DCHECK(profile_); | 40 DCHECK(request_context_); |
| 40 DCHECK(device_description_url_.is_valid()); | 41 DCHECK(device_description_url_.is_valid()); |
| 41 } | 42 } |
| 42 | 43 |
| 43 DeviceDescriptionFetcher::~DeviceDescriptionFetcher() { | 44 DeviceDescriptionFetcher::~DeviceDescriptionFetcher() { |
| 44 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 45 DCHECK(thread_checker_.CalledOnValidThread()); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void DeviceDescriptionFetcher::Start() { | 48 void DeviceDescriptionFetcher::Start() { |
| 48 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 49 DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 DCHECK(!fetcher_); | 50 DCHECK(!fetcher_); |
| 50 | 51 |
| 51 // DIAL returns device descriptions via GET request. | 52 // DIAL returns device descriptions via GET request. |
| 52 fetcher_ = | 53 fetcher_ = |
| 53 net::URLFetcher::Create(kURLFetcherIDForTest, device_description_url_, | 54 net::URLFetcher::Create(kURLFetcherIDForTest, device_description_url_, |
| 54 net::URLFetcher::GET, this); | 55 net::URLFetcher::GET, this); |
| 55 | 56 |
| 56 // net::LOAD_BYPASS_PROXY: Proxies almost certainly hurt more cases than they | 57 // net::LOAD_BYPASS_PROXY: Proxies almost certainly hurt more cases than they |
| 57 // help. | 58 // help. |
| 58 // net::LOAD_DISABLE_CACHE: The request should not touch the cache. | 59 // net::LOAD_DISABLE_CACHE: The request should not touch the cache. |
| 59 // net::LOAD_DO_NOT_{SAVE,SEND}_COOKIES: The request should not touch cookies. | 60 // net::LOAD_DO_NOT_{SAVE,SEND}_COOKIES: The request should not touch cookies. |
| 60 // net::LOAD_DO_NOT_SEND_AUTH_DATA: The request should not send auth data. | 61 // net::LOAD_DO_NOT_SEND_AUTH_DATA: The request should not send auth data. |
| 61 fetcher_->SetLoadFlags(net::LOAD_BYPASS_PROXY | net::LOAD_DISABLE_CACHE | | 62 fetcher_->SetLoadFlags(net::LOAD_BYPASS_PROXY | net::LOAD_DISABLE_CACHE | |
| 62 net::LOAD_DO_NOT_SAVE_COOKIES | | 63 net::LOAD_DO_NOT_SAVE_COOKIES | |
| 63 net::LOAD_DO_NOT_SEND_COOKIES | | 64 net::LOAD_DO_NOT_SEND_COOKIES | |
| 64 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 65 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
| 65 | 66 |
| 66 // Section 5.4 of the DIAL spec prohibits redirects. | 67 // Section 5.4 of the DIAL spec prohibits redirects. |
| 67 fetcher_->SetStopOnRedirect(true); | 68 fetcher_->SetStopOnRedirect(true); |
| 68 | 69 |
| 69 // Allow the fetcher to retry on 5XX responses and ERR_NETWORK_CHANGED. | 70 // Allow the fetcher to retry on 5XX responses and ERR_NETWORK_CHANGED. |
| 70 fetcher_->SetMaxRetriesOn5xx(kMaxRetries); | 71 fetcher_->SetMaxRetriesOn5xx(kMaxRetries); |
| 71 fetcher_->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); | 72 fetcher_->SetAutomaticallyRetryOnNetworkChanges(kMaxRetries); |
| 72 | 73 |
| 73 fetcher_->SetRequestContext(profile_->GetRequestContext()); | 74 fetcher_->SetRequestContext(request_context_); |
| 74 fetcher_->Start(); | 75 fetcher_->Start(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 void DeviceDescriptionFetcher::OnURLFetchComplete( | 78 void DeviceDescriptionFetcher::OnURLFetchComplete( |
| 78 const net::URLFetcher* source) { | 79 const net::URLFetcher* source) { |
| 79 DCHECK_EQ(fetcher_.get(), source); | 80 DCHECK_EQ(fetcher_.get(), source); |
| 80 | 81 |
| 81 if (source->GetResponseCode() != net::HTTP_OK) { | 82 if (source->GetResponseCode() != net::HTTP_OK) { |
| 82 ReportError( | 83 ReportError( |
| 83 base::StringPrintf("HTTP %d: Unable to fetch device description", | 84 base::StringPrintf("HTTP %d: Unable to fetch device description", |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 int64_t current, | 142 int64_t current, |
| 142 int64_t total) {} | 143 int64_t total) {} |
| 143 | 144 |
| 144 void DeviceDescriptionFetcher::ReportError(const std::string& message) { | 145 void DeviceDescriptionFetcher::ReportError(const std::string& message) { |
| 145 std::move(error_cb_).Run(message); | 146 std::move(error_cb_).Run(message); |
| 146 } | 147 } |
| 147 | 148 |
| 148 } // namespace dial | 149 } // namespace dial |
| 149 } // namespace api | 150 } // namespace api |
| 150 } // namespace extensions | 151 } // namespace extensions |
| OLD | NEW |