OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ | 5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ |
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ | 6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
| 10 #include "base/file_util.h" |
10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "net/url_request/url_fetcher.h" | 13 #include "net/url_request/url_fetcher.h" |
13 #include "net/url_request/url_fetcher_delegate.h" | 14 #include "net/url_request/url_fetcher_delegate.h" |
14 #include "net/url_request/url_request_context_getter.h" | 15 #include "net/url_request/url_request_context_getter.h" |
15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
16 | 17 |
| 18 namespace base { |
| 19 class FilePath; |
| 20 } |
| 21 |
17 namespace local_discovery { | 22 namespace local_discovery { |
18 | 23 |
19 const int kPrivetHTTPCodeInternalFailure = -1; | 24 const int kPrivetHTTPCodeInternalFailure = -1; |
20 | 25 |
21 // Privet-specific URLFetcher adapter. Currently supports only the subset | 26 // Privet-specific URLFetcher adapter. Currently supports only the subset |
22 // of HTTP features required by Privet for GCP 1.5 | 27 // of HTTP features required by Privet for GCP 1.5 |
23 // (/privet/info and /privet/register). | 28 // (/privet/info and /privet/register). |
24 class PrivetURLFetcher : public net::URLFetcherDelegate { | 29 class PrivetURLFetcher : public net::URLFetcherDelegate { |
25 public: | 30 public: |
26 enum ErrorType { | 31 enum ErrorType { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 63 |
59 void DoNotRetryOnTransientError(); | 64 void DoNotRetryOnTransientError(); |
60 | 65 |
61 void AllowEmptyPrivetToken(); | 66 void AllowEmptyPrivetToken(); |
62 | 67 |
63 void Start(); | 68 void Start(); |
64 | 69 |
65 void SetUploadData(const std::string& upload_content_type, | 70 void SetUploadData(const std::string& upload_content_type, |
66 const std::string& upload_data); | 71 const std::string& upload_data); |
67 | 72 |
| 73 void SetUploadFilePath(const std::string& upload_content_type, |
| 74 const base::FilePath& upload_file_path); |
| 75 |
68 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 76 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
69 | 77 |
70 const GURL& url() const { return url_fetcher_->GetOriginalURL(); } | 78 const GURL& url() const { return url_fetcher_->GetOriginalURL(); } |
71 int response_code() const { return url_fetcher_->GetResponseCode(); } | 79 int response_code() const { return url_fetcher_->GetResponseCode(); } |
72 | 80 |
73 private: | 81 private: |
74 void Try(); | 82 void Try(); |
75 void ScheduleRetry(int timeout_seconds); | 83 void ScheduleRetry(int timeout_seconds); |
76 bool PrivetErrorTransient(const std::string& error); | 84 bool PrivetErrorTransient(const std::string& error); |
77 void RequestTokenRefresh(); | 85 void RequestTokenRefresh(); |
78 void RefreshToken(const std::string& token); | 86 void RefreshToken(const std::string& token); |
79 | 87 |
80 std::string privet_access_token_; | 88 std::string privet_access_token_; |
81 GURL url_; | 89 GURL url_; |
82 net::URLFetcher::RequestType request_type_; | 90 net::URLFetcher::RequestType request_type_; |
83 scoped_refptr<net::URLRequestContextGetter> request_context_; | 91 scoped_refptr<net::URLRequestContextGetter> request_context_; |
84 Delegate* delegate_; | 92 Delegate* delegate_; |
85 | 93 |
86 bool do_not_retry_on_transient_error_; | 94 bool do_not_retry_on_transient_error_; |
87 bool allow_empty_privet_token_; | 95 bool allow_empty_privet_token_; |
88 | 96 |
89 int tries_; | 97 int tries_; |
90 std::string upload_data_; | 98 std::string upload_data_; |
91 std::string upload_content_type_; | 99 std::string upload_content_type_; |
| 100 base::FilePath upload_file_path_; |
92 scoped_ptr<net::URLFetcher> url_fetcher_; | 101 scoped_ptr<net::URLFetcher> url_fetcher_; |
93 | 102 |
94 base::WeakPtrFactory<PrivetURLFetcher> weak_factory_; | 103 base::WeakPtrFactory<PrivetURLFetcher> weak_factory_; |
95 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher); | 104 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher); |
96 }; | 105 }; |
97 | 106 |
98 class PrivetURLFetcherFactory { | 107 class PrivetURLFetcherFactory { |
99 public: | 108 public: |
100 explicit PrivetURLFetcherFactory( | 109 explicit PrivetURLFetcherFactory( |
101 net::URLRequestContextGetter* request_context); | 110 net::URLRequestContextGetter* request_context); |
(...skipping 10 matching lines...) Expand all Loading... |
112 private: | 121 private: |
113 scoped_refptr<net::URLRequestContextGetter> request_context_; | 122 scoped_refptr<net::URLRequestContextGetter> request_context_; |
114 std::string token_; | 123 std::string token_; |
115 | 124 |
116 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcherFactory); | 125 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcherFactory); |
117 }; | 126 }; |
118 | 127 |
119 } // namespace local_discovery | 128 } // namespace local_discovery |
120 | 129 |
121 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ | 130 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ |
OLD | NEW |