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 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/threading/thread_checker.h" | |
| 13 #include "content/public/browser/browser_thread.h" | |
| 12 #include "net/url_request/url_fetcher_delegate.h" | 14 #include "net/url_request/url_fetcher_delegate.h" |
| 13 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 14 | 16 |
| 15 class Profile; | |
| 16 | |
| 17 namespace net { | 17 namespace net { |
| 18 class URLFetcher; | 18 class URLFetcher; |
| 19 class URLRequestContextGetter; | |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace extensions { | 22 namespace extensions { |
| 22 namespace api { | 23 namespace api { |
| 23 namespace dial { | 24 namespace dial { |
| 24 | 25 |
| 25 struct DialDeviceDescriptionData; | 26 struct DialDeviceDescriptionData; |
| 26 | 27 |
| 27 // Used to make a single HTTP GET request with |device_description_url| to fetch | 28 // Used to make a single HTTP GET request with |device_description_url| to fetch |
| 28 // a uPnP device description from a DIAL device. If successful, |success_cb| is | 29 // a uPnP device description from a DIAL device. If successful, |success_cb| is |
| 29 // invoked with the result; otherwise, |error_cb| is invoked with an error | 30 // invoked with the result; otherwise, |error_cb| is invoked with an error |
| 30 // reason. This class is not thread safe and must be used on the UI thread. | 31 // reason. |
| 32 // This class is not thread safe. | |
| 31 class DeviceDescriptionFetcher : public net::URLFetcherDelegate { | 33 class DeviceDescriptionFetcher : public net::URLFetcherDelegate { |
| 32 public: | 34 public: |
| 33 // Used to identify the net::URLFetcher instance for tests. | 35 // Used to identify the net::URLFetcher instance for tests. |
| 34 static constexpr int kURLFetcherIDForTest = 1; | 36 static constexpr int kURLFetcherIDForTest = 1; |
| 35 | 37 |
| 36 // |profile| is unowned; the caller must ensure that this object does not | 38 // |request_context| is unowned; the caller must ensure that this object does |
| 37 // outlive it. | 39 // not outlive it. |
| 38 DeviceDescriptionFetcher( | 40 DeviceDescriptionFetcher( |
| 39 const GURL& device_description_url, | 41 const GURL& device_description_url, |
| 40 Profile* profile, | 42 net::URLRequestContextGetter* request_context, |
|
imcheng
2017/03/06 20:56:30
I believe this should be a scoped_refptr; this obj
zhaobin
2017/03/07 00:13:18
Pass in raw pointer (Profile::GetRequestContext()
imcheng
2017/03/07 20:32:58
Most likely you will pass in a scoped_refptr here,
| |
| 43 content::BrowserThread::ID thread_id, | |
| 41 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb, | 44 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb, |
| 42 base::OnceCallback<void(const std::string&)> error_cb); | 45 base::OnceCallback<void(const std::string&)> error_cb); |
| 43 | 46 |
| 44 ~DeviceDescriptionFetcher() override; | 47 ~DeviceDescriptionFetcher() override; |
| 45 | 48 |
| 46 void Start(); | 49 void Start(); |
| 47 | 50 |
| 48 private: | 51 private: |
| 49 // net::URLFetcherDelegate implementation. | 52 // net::URLFetcherDelegate implementation. |
| 50 void OnURLFetchComplete(const net::URLFetcher* source) override; | 53 void OnURLFetchComplete(const net::URLFetcher* source) override; |
| 51 void OnURLFetchDownloadProgress(const net::URLFetcher* source, | 54 void OnURLFetchDownloadProgress(const net::URLFetcher* source, |
| 52 int64_t current, | 55 int64_t current, |
| 53 int64_t total, | 56 int64_t total, |
| 54 int64_t current_network_bytes) override; | 57 int64_t current_network_bytes) override; |
| 55 void OnURLFetchUploadProgress(const net::URLFetcher* source, | 58 void OnURLFetchUploadProgress(const net::URLFetcher* source, |
| 56 int64_t current, | 59 int64_t current, |
| 57 int64_t total) override; | 60 int64_t total) override; |
| 58 | 61 |
| 59 // Runs |error_cb_| with |message| and clears it. | 62 // Runs |error_cb_| with |message| and clears it. |
| 60 void ReportError(const std::string& message); | 63 void ReportError(const std::string& message); |
| 61 | 64 |
| 62 const GURL device_description_url_; | 65 const GURL device_description_url_; |
| 63 Profile* const profile_; | 66 net::URLRequestContextGetter* const request_context_; |
| 67 base::ThreadChecker thread_checker_; | |
| 68 | |
| 64 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb_; | 69 base::OnceCallback<void(const DialDeviceDescriptionData&)> success_cb_; |
| 65 base::OnceCallback<void(const std::string&)> error_cb_; | 70 base::OnceCallback<void(const std::string&)> error_cb_; |
| 66 std::unique_ptr<net::URLFetcher> fetcher_; | 71 std::unique_ptr<net::URLFetcher> fetcher_; |
| 67 }; | 72 }; |
| 68 | 73 |
| 69 } // namespace dial | 74 } // namespace dial |
| 70 } // namespace api | 75 } // namespace api |
| 71 } // namespace extensions | 76 } // namespace extensions |
| 72 | 77 |
| 73 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ | 78 #endif // CHROME_BROWSER_EXTENSIONS_API_DIAL_DEVICE_DESCRIPTION_FETCHER_H_ |
| OLD | NEW |