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/file_util.h" |
Vitaly Buka (NO REVIEWS)
2014/02/07 19:47:39
one should be enough
Noam Samuel
2014/02/12 20:25:16
Done.
| |
11 #include "base/file_util.h" | |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "base/values.h" | 13 #include "base/values.h" |
13 #include "net/url_request/url_fetcher.h" | 14 #include "net/url_request/url_fetcher.h" |
14 #include "net/url_request/url_fetcher_delegate.h" | 15 #include "net/url_request/url_fetcher_delegate.h" |
15 #include "net/url_request/url_request_context_getter.h" | 16 #include "net/url_request/url_request_context_getter.h" |
16 #include "url/gurl.h" | 17 #include "url/gurl.h" |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 class FilePath; | 20 class FilePath; |
20 } | 21 } |
(...skipping 23 matching lines...) Expand all Loading... | |
44 | 45 |
45 // If you do not implement this method, you will always get a | 46 // If you do not implement this method, you will always get a |
46 // TOKEN_ERROR error when your token is invalid. | 47 // TOKEN_ERROR error when your token is invalid. |
47 virtual void OnNeedPrivetToken( | 48 virtual void OnNeedPrivetToken( |
48 PrivetURLFetcher* fetcher, | 49 PrivetURLFetcher* fetcher, |
49 const TokenCallback& callback); | 50 const TokenCallback& callback); |
50 virtual void OnError(PrivetURLFetcher* fetcher, ErrorType error) = 0; | 51 virtual void OnError(PrivetURLFetcher* fetcher, ErrorType error) = 0; |
51 virtual void OnParsedJson(PrivetURLFetcher* fetcher, | 52 virtual void OnParsedJson(PrivetURLFetcher* fetcher, |
52 const base::DictionaryValue* value, | 53 const base::DictionaryValue* value, |
53 bool has_error) = 0; | 54 bool has_error) = 0; |
55 | |
56 virtual void OnRawData(PrivetURLFetcher* fetcher, | |
57 bool response_is_file, | |
58 const std::string& data_string, | |
59 const base::FilePath& data_file) {} | |
54 }; | 60 }; |
55 | 61 |
56 PrivetURLFetcher( | 62 PrivetURLFetcher( |
57 const std::string& token, | 63 const std::string& token, |
58 const GURL& url, | 64 const GURL& url, |
59 net::URLFetcher::RequestType request_type, | 65 net::URLFetcher::RequestType request_type, |
60 net::URLRequestContextGetter* request_context, | 66 net::URLRequestContextGetter* request_context, |
61 Delegate* delegate); | 67 Delegate* delegate); |
62 virtual ~PrivetURLFetcher(); | 68 virtual ~PrivetURLFetcher(); |
63 | 69 |
64 void DoNotRetryOnTransientError(); | 70 void DoNotRetryOnTransientError(); |
65 | 71 |
66 void AllowEmptyPrivetToken(); | 72 void AllowEmptyPrivetToken(); |
67 | 73 |
74 // If this method is called, the data will not be parsed as JSON, and | |
75 // |OnRawData| will be called instead of |OnParsedJson|. In addition, | |
76 // HTTP code 418 will be treated as an invalid_x_privet_token error. | |
77 void DoNotParseData(); | |
78 | |
79 // Set the contents of the Range header. This is only valid for requests that | |
80 // call |DoNotParseData|. | |
81 void SetByteRange(int start, int end); | |
82 | |
83 // Save the response to a file. Only valid when used with |DoNotParseData|. | |
84 void SaveResponseToFile(); | |
85 | |
68 void Start(); | 86 void Start(); |
69 | 87 |
70 void SetUploadData(const std::string& upload_content_type, | 88 void SetUploadData(const std::string& upload_content_type, |
71 const std::string& upload_data); | 89 const std::string& upload_data); |
72 | 90 |
73 void SetUploadFilePath(const std::string& upload_content_type, | 91 void SetUploadFilePath(const std::string& upload_content_type, |
74 const base::FilePath& upload_file_path); | 92 const base::FilePath& upload_file_path); |
75 | 93 |
76 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; | 94 virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; |
95 void OnURLFetchCompleteParseData(const net::URLFetcher* source); | |
96 void OnURLFetchCompleteDoNotParseData(const net::URLFetcher* source); | |
77 | 97 |
78 const GURL& url() const { return url_fetcher_->GetOriginalURL(); } | 98 const GURL& url() const { return url_fetcher_->GetOriginalURL(); } |
79 int response_code() const { return url_fetcher_->GetResponseCode(); } | 99 int response_code() const { return url_fetcher_->GetResponseCode(); } |
80 | 100 |
81 private: | 101 private: |
82 void Try(); | 102 void Try(); |
83 void ScheduleRetry(int timeout_seconds); | 103 void ScheduleRetry(int timeout_seconds); |
84 bool PrivetErrorTransient(const std::string& error); | 104 bool PrivetErrorTransient(const std::string& error); |
85 void RequestTokenRefresh(); | 105 void RequestTokenRefresh(); |
86 void RefreshToken(const std::string& token); | 106 void RefreshToken(const std::string& token); |
87 | 107 |
88 std::string privet_access_token_; | 108 std::string privet_access_token_; |
89 GURL url_; | 109 GURL url_; |
90 net::URLFetcher::RequestType request_type_; | 110 net::URLFetcher::RequestType request_type_; |
91 scoped_refptr<net::URLRequestContextGetter> request_context_; | 111 scoped_refptr<net::URLRequestContextGetter> request_context_; |
92 Delegate* delegate_; | 112 Delegate* delegate_; |
93 | 113 |
94 bool do_not_retry_on_transient_error_; | 114 bool do_not_retry_on_transient_error_; |
95 bool allow_empty_privet_token_; | 115 bool allow_empty_privet_token_; |
116 bool do_not_parse_data_; | |
117 bool has_byte_range_; | |
118 bool make_response_file_; | |
119 | |
120 int byte_range_start_; | |
121 int byte_range_end_; | |
96 | 122 |
97 int tries_; | 123 int tries_; |
98 std::string upload_data_; | 124 std::string upload_data_; |
99 std::string upload_content_type_; | 125 std::string upload_content_type_; |
100 base::FilePath upload_file_path_; | 126 base::FilePath upload_file_path_; |
101 scoped_ptr<net::URLFetcher> url_fetcher_; | 127 scoped_ptr<net::URLFetcher> url_fetcher_; |
102 | 128 |
103 base::WeakPtrFactory<PrivetURLFetcher> weak_factory_; | 129 base::WeakPtrFactory<PrivetURLFetcher> weak_factory_; |
104 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher); | 130 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher); |
105 }; | 131 }; |
(...skipping 15 matching lines...) Expand all Loading... | |
121 private: | 147 private: |
122 scoped_refptr<net::URLRequestContextGetter> request_context_; | 148 scoped_refptr<net::URLRequestContextGetter> request_context_; |
123 std::string token_; | 149 std::string token_; |
124 | 150 |
125 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcherFactory); | 151 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcherFactory); |
126 }; | 152 }; |
127 | 153 |
128 } // namespace local_discovery | 154 } // namespace local_discovery |
129 | 155 |
130 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ | 156 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ |
OLD | NEW |