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

Side by Side Diff: http_fetcher.h

Issue 3106038: AU: Expose the server's HTTP response code in HttpFetcher. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: rebase and add redirect response code checks Created 10 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | http_fetcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium OS 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 CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__ 5 #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__
6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__ 6 #define CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 #include <glib.h> 10 #include <glib.h>
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 12
13 // This class is a simple wrapper around an HTTP library (libcurl). We can 13 // This class is a simple wrapper around an HTTP library (libcurl). We can
14 // easily mock out this interface for testing. 14 // easily mock out this interface for testing.
15 15
16 // Implementations of this class should use asynchronous i/o. They can access 16 // Implementations of this class should use asynchronous i/o. They can access
17 // the glib main loop to request callbacks when timers or file descriptors 17 // the glib main loop to request callbacks when timers or file descriptors
18 // change. 18 // change.
19 19
20 namespace chromeos_update_engine { 20 namespace chromeos_update_engine {
21 21
22 class HttpFetcherDelegate; 22 class HttpFetcherDelegate;
23 23
24 class HttpFetcher { 24 class HttpFetcher {
25 public: 25 public:
26 HttpFetcher() : post_data_set_(false), delegate_(NULL) {} 26 HttpFetcher()
27 : post_data_set_(false),
28 http_response_code_(0),
29 delegate_(NULL) {}
27 virtual ~HttpFetcher() {} 30 virtual ~HttpFetcher() {}
28 void set_delegate(HttpFetcherDelegate* delegate) { 31
29 delegate_ = delegate; 32 void set_delegate(HttpFetcherDelegate* delegate) { delegate_ = delegate; }
30 } 33 HttpFetcherDelegate* delegate() const { return delegate_; }
31 HttpFetcherDelegate* delegate() const { 34 int http_response_code() const { return http_response_code_; }
32 return delegate_;
33 }
34 35
35 // Optional: Post data to the server. The HttpFetcher should make a copy 36 // Optional: Post data to the server. The HttpFetcher should make a copy
36 // of this data and upload it via HTTP POST during the transfer. 37 // of this data and upload it via HTTP POST during the transfer.
37 void SetPostData(const void* data, size_t size) { 38 void SetPostData(const void* data, size_t size) {
38 post_data_set_ = true; 39 post_data_set_ = true;
39 post_data_.clear(); 40 post_data_.clear();
40 const char *char_data = reinterpret_cast<const char*>(data); 41 const char *char_data = reinterpret_cast<const char*>(data);
41 post_data_.insert(post_data_.end(), char_data, char_data + size); 42 post_data_.insert(post_data_.end(), char_data, char_data + size);
42 } 43 }
43 44
(...skipping 15 matching lines...) Expand all
59 virtual void Unpause() = 0; 60 virtual void Unpause() = 0;
60 61
61 protected: 62 protected:
62 // The URL we're actively fetching from 63 // The URL we're actively fetching from
63 std::string url_; 64 std::string url_;
64 65
65 // POST data for the transfer, and whether or not it was ever set 66 // POST data for the transfer, and whether or not it was ever set
66 bool post_data_set_; 67 bool post_data_set_;
67 std::vector<char> post_data_; 68 std::vector<char> post_data_;
68 69
70 // The server's HTTP response code from the last transfer. This
71 // field should be set to 0 when a new transfer is initiated, and
72 // set to the response code when the transfer is complete.
73 int http_response_code_;
74
69 // The delegate; may be NULL. 75 // The delegate; may be NULL.
70 HttpFetcherDelegate* delegate_; 76 HttpFetcherDelegate* delegate_;
71 private: 77 private:
72 DISALLOW_COPY_AND_ASSIGN(HttpFetcher); 78 DISALLOW_COPY_AND_ASSIGN(HttpFetcher);
73 }; 79 };
74 80
75 // Interface for delegates 81 // Interface for delegates
76 class HttpFetcherDelegate { 82 class HttpFetcherDelegate {
77 public: 83 public:
78 // Called every time bytes are received, even if they are automatically 84 // Called every time bytes are received, even if they are automatically
79 // delivered to an output file. 85 // delivered to an output file.
80 virtual void ReceivedBytes(HttpFetcher* fetcher, 86 virtual void ReceivedBytes(HttpFetcher* fetcher,
81 const char* bytes, 87 const char* bytes,
82 int length) = 0; 88 int length) = 0;
83 89
84 // Called when the transfer has completed successfully or been somehow 90 // Called when the transfer has completed successfully or been somehow
85 // aborted. 91 // aborted.
86 virtual void TransferComplete(HttpFetcher* fetcher, bool successful) = 0; 92 virtual void TransferComplete(HttpFetcher* fetcher, bool successful) = 0;
87 }; 93 };
88 94
89 } // namespace chromeos_update_engine 95 } // namespace chromeos_update_engine
90 96
91 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__ 97 #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_HTTP_FETCHER_H__
OLDNEW
« no previous file with comments | « no previous file | http_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698