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" |
(...skipping 24 matching lines...) Expand all Loading... |
35 RETRY_ERROR, | 35 RETRY_ERROR, |
36 TOKEN_ERROR | 36 TOKEN_ERROR |
37 }; | 37 }; |
38 | 38 |
39 typedef base::Callback<void(const std::string& /*token*/)> TokenCallback; | 39 typedef base::Callback<void(const std::string& /*token*/)> TokenCallback; |
40 | 40 |
41 class Delegate { | 41 class Delegate { |
42 public: | 42 public: |
43 virtual ~Delegate() {} | 43 virtual ~Delegate() {} |
44 | 44 |
45 // If you do not implement this method, you will always get a | 45 // If you do not implement this method for PrivetV1 callers, you will always |
46 // TOKEN_ERROR error when your token is invalid. | 46 // get a TOKEN_ERROR error when your token is invalid. |
47 virtual void OnNeedPrivetToken( | 47 virtual void OnNeedPrivetToken( |
48 PrivetURLFetcher* fetcher, | 48 PrivetURLFetcher* fetcher, |
49 const TokenCallback& callback); | 49 const TokenCallback& callback); |
| 50 |
| 51 // If this returns the empty string, will not send an auth token. |
| 52 virtual std::string GetAuthToken(); |
| 53 |
50 virtual void OnError(PrivetURLFetcher* fetcher, ErrorType error) = 0; | 54 virtual void OnError(PrivetURLFetcher* fetcher, ErrorType error) = 0; |
51 virtual void OnParsedJson(PrivetURLFetcher* fetcher, | 55 virtual void OnParsedJson(PrivetURLFetcher* fetcher, |
52 const base::DictionaryValue& value, | 56 const base::DictionaryValue& value, |
53 bool has_error) = 0; | 57 bool has_error) = 0; |
54 | 58 |
55 // If this method is returns true, the data will not be parsed as JSON, and | 59 // If this method is returns true, the data will not be parsed as JSON, and |
56 // |OnParsedJson| will not be called. Otherwise, |OnParsedJson| will be | 60 // |OnParsedJson| will not be called. Otherwise, |OnParsedJson| will be |
57 // called. | 61 // called. |
58 virtual bool OnRawData(PrivetURLFetcher* fetcher, | 62 virtual bool OnRawData(PrivetURLFetcher* fetcher, |
59 bool response_is_file, | 63 bool response_is_file, |
(...skipping 14 matching lines...) Expand all Loading... |
74 | 78 |
75 static void SetTokenForHost(const std::string& host, | 79 static void SetTokenForHost(const std::string& host, |
76 const std::string& token); | 80 const std::string& token); |
77 | 81 |
78 static void ResetTokenMapForTests(); | 82 static void ResetTokenMapForTests(); |
79 | 83 |
80 void DoNotRetryOnTransientError(); | 84 void DoNotRetryOnTransientError(); |
81 | 85 |
82 void SendEmptyPrivetToken(); | 86 void SendEmptyPrivetToken(); |
83 | 87 |
| 88 void V3Mode(); |
| 89 |
84 // Set the contents of the Range header. |OnRawData| must return true if this | 90 // Set the contents of the Range header. |OnRawData| must return true if this |
85 // is called. | 91 // is called. |
86 void SetByteRange(int start, int end); | 92 void SetByteRange(int start, int end); |
87 | 93 |
88 // Save the response to a file. |OnRawData| must return true if this is | 94 // Save the response to a file. |OnRawData| must return true if this is |
89 // called. | 95 // called. |
90 void SaveResponseToFile(); | 96 void SaveResponseToFile(); |
91 | 97 |
92 void Start(); | 98 void Start(); |
93 | 99 |
(...skipping 20 matching lines...) Expand all Loading... |
114 | 120 |
115 GURL url_; | 121 GURL url_; |
116 net::URLFetcher::RequestType request_type_; | 122 net::URLFetcher::RequestType request_type_; |
117 scoped_refptr<net::URLRequestContextGetter> request_context_; | 123 scoped_refptr<net::URLRequestContextGetter> request_context_; |
118 Delegate* delegate_; | 124 Delegate* delegate_; |
119 | 125 |
120 bool do_not_retry_on_transient_error_; | 126 bool do_not_retry_on_transient_error_; |
121 bool send_empty_privet_token_; | 127 bool send_empty_privet_token_; |
122 bool has_byte_range_; | 128 bool has_byte_range_; |
123 bool make_response_file_; | 129 bool make_response_file_; |
| 130 bool v3_mode_; |
124 | 131 |
125 int byte_range_start_; | 132 int byte_range_start_; |
126 int byte_range_end_; | 133 int byte_range_end_; |
127 | 134 |
128 int tries_; | 135 int tries_; |
129 std::string upload_data_; | 136 std::string upload_data_; |
130 std::string upload_content_type_; | 137 std::string upload_content_type_; |
131 base::FilePath upload_file_path_; | 138 base::FilePath upload_file_path_; |
132 scoped_ptr<net::URLFetcher> url_fetcher_; | 139 scoped_ptr<net::URLFetcher> url_fetcher_; |
133 | 140 |
134 base::WeakPtrFactory<PrivetURLFetcher> weak_factory_; | 141 base::WeakPtrFactory<PrivetURLFetcher> weak_factory_; |
135 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher); | 142 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher); |
136 }; | 143 }; |
137 | 144 |
138 } // namespace local_discovery | 145 } // namespace local_discovery |
139 | 146 |
140 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ | 147 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ |
OLD | NEW |