Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(654)

Side by Side Diff: chrome/browser/local_discovery/privet_url_fetcher.h

Issue 1417363004: Verify certificate of Privet v3 device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 10 matching lines...) Expand all
21 21
22 namespace local_discovery { 22 namespace local_discovery {
23 23
24 // Privet-specific URLFetcher adapter. Currently supports only the subset 24 // Privet-specific URLFetcher adapter. Currently supports only the subset
25 // of HTTP features required by Privet for GCP 1.5 25 // of HTTP features required by Privet for GCP 1.5
26 // (/privet/info and /privet/register). 26 // (/privet/info and /privet/register).
27 class PrivetURLFetcher : public net::URLFetcherDelegate { 27 class PrivetURLFetcher : public net::URLFetcherDelegate {
28 public: 28 public:
29 enum ErrorType { 29 enum ErrorType {
30 JSON_PARSE_ERROR, 30 JSON_PARSE_ERROR,
31 URL_FETCH_ERROR, 31 REQUEST_CANCELED,
32 RESPONSE_CODE_ERROR, 32 RESPONSE_CODE_ERROR,
33 RETRY_ERROR, 33 TOKEN_ERROR,
34 TOKEN_ERROR 34 UNKNOWN_ERROR,
35 }; 35 };
36 36
37 typedef base::Callback<void(const std::string& /*token*/)> TokenCallback; 37 typedef base::Callback<void(const std::string& /*token*/)> TokenCallback;
38 38
39 class Delegate { 39 class Delegate {
40 public: 40 public:
41 virtual ~Delegate() {} 41 virtual ~Delegate() {}
42 42
43 // If you do not implement this method for PrivetV1 callers, you will always 43 // If you do not implement this method for PrivetV1 callers, you will always
44 // get a TOKEN_ERROR error when your token is invalid. 44 // get a TOKEN_ERROR error when your token is invalid.
(...skipping 14 matching lines...) Expand all
59 // called. 59 // called.
60 virtual bool OnRawData(PrivetURLFetcher* fetcher, 60 virtual bool OnRawData(PrivetURLFetcher* fetcher,
61 bool response_is_file, 61 bool response_is_file,
62 const std::string& data_string, 62 const std::string& data_string,
63 const base::FilePath& data_file); 63 const base::FilePath& data_file);
64 }; 64 };
65 65
66 PrivetURLFetcher( 66 PrivetURLFetcher(
67 const GURL& url, 67 const GURL& url,
68 net::URLFetcher::RequestType request_type, 68 net::URLFetcher::RequestType request_type,
69 net::URLRequestContextGetter* request_context, 69 const scoped_refptr<net::URLRequestContextGetter>& context_getter,
70 Delegate* delegate); 70 Delegate* delegate);
71 71
72 ~PrivetURLFetcher() override; 72 ~PrivetURLFetcher() override;
73 73
74 // net::URLFetcherDelegate methods. 74 // net::URLFetcherDelegate methods.
75 void OnURLFetchComplete(const net::URLFetcher* source) override; 75 void OnURLFetchComplete(const net::URLFetcher* source) override;
76 76
77 static void SetTokenForHost(const std::string& host, 77 static void SetTokenForHost(const std::string& host,
78 const std::string& token); 78 const std::string& token);
79 79
80 static void ResetTokenMapForTests(); 80 static void ResetTokenMapForTests();
81 81
82 void SetMaxRetries(int max_retries);
83
82 void DoNotRetryOnTransientError(); 84 void DoNotRetryOnTransientError();
83 85
84 void SendEmptyPrivetToken(); 86 void SendEmptyPrivetToken();
85 87
86 void V3Mode(); 88 void V3Mode();
87 89
88 // 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
89 // is called. 91 // is called.
90 void SetByteRange(int start, int end); 92 void SetByteRange(int start, int end);
91 93
(...skipping 19 matching lines...) Expand all
111 std::string GetHostString(); // Get string representing the host. 113 std::string GetHostString(); // Get string representing the host.
112 std::string GetPrivetAccessToken(); 114 std::string GetPrivetAccessToken();
113 void Try(); 115 void Try();
114 void ScheduleRetry(int timeout_seconds); 116 void ScheduleRetry(int timeout_seconds);
115 bool PrivetErrorTransient(const std::string& error); 117 bool PrivetErrorTransient(const std::string& error);
116 void RequestTokenRefresh(); 118 void RequestTokenRefresh();
117 void RefreshToken(const std::string& token); 119 void RefreshToken(const std::string& token);
118 120
119 GURL url_; 121 GURL url_;
120 net::URLFetcher::RequestType request_type_; 122 net::URLFetcher::RequestType request_type_;
121 scoped_refptr<net::URLRequestContextGetter> request_context_; 123 scoped_refptr<net::URLRequestContextGetter> context_getter_;
122 Delegate* delegate_; 124 Delegate* delegate_;
123 125
126 int max_retries_;
124 bool do_not_retry_on_transient_error_; 127 bool do_not_retry_on_transient_error_;
125 bool send_empty_privet_token_; 128 bool send_empty_privet_token_;
126 bool has_byte_range_; 129 bool has_byte_range_;
127 bool make_response_file_; 130 bool make_response_file_;
128 bool v3_mode_; 131 bool v3_mode_;
129 132
130 int byte_range_start_; 133 int byte_range_start_;
131 int byte_range_end_; 134 int byte_range_end_;
132 135
133 int tries_; 136 int tries_;
134 std::string upload_data_; 137 std::string upload_data_;
135 std::string upload_content_type_; 138 std::string upload_content_type_;
136 base::FilePath upload_file_path_; 139 base::FilePath upload_file_path_;
137 scoped_ptr<net::URLFetcher> url_fetcher_; 140 scoped_ptr<net::URLFetcher> url_fetcher_;
138 141
139 base::WeakPtrFactory<PrivetURLFetcher> weak_factory_; 142 base::WeakPtrFactory<PrivetURLFetcher> weak_factory_;
140 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher); 143 DISALLOW_COPY_AND_ASSIGN(PrivetURLFetcher);
141 }; 144 };
142 145
143 } // namespace local_discovery 146 } // namespace local_discovery
144 147
145 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_ 148 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_URL_FETCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698