OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 EXAMPLES_GETURL_GETURL_HANDLER_H_ | 5 #ifndef EXAMPLES_GETURL_GETURL_HANDLER_H_ |
6 #define EXAMPLES_GETURL_GETURL_HANDLER_H_ | 6 #define EXAMPLES_GETURL_GETURL_HANDLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
10 #include "ppapi/cpp/url_loader.h" | 10 #include "ppapi/cpp/url_loader.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 // self-destroy when all data is in). | 36 // self-destroy when all data is in). |
37 static GetURLHandler* Create(pp::Instance* instance_, | 37 static GetURLHandler* Create(pp::Instance* instance_, |
38 const std::string& url); | 38 const std::string& url); |
39 // Initiates page (URL) download. | 39 // Initiates page (URL) download. |
40 void Start(); | 40 void Start(); |
41 | 41 |
42 private: | 42 private: |
43 GetURLHandler(pp::Instance* instance_, const std::string& url); | 43 GetURLHandler(pp::Instance* instance_, const std::string& url); |
44 ~GetURLHandler(); | 44 ~GetURLHandler(); |
45 | 45 |
46 // Callback fo the pp::URLLoader::Open(). | 46 // Callback for the pp::URLLoader::Open(). |
47 // Called by pp::URLLoader when response headers are received or when an | 47 // Called by pp::URLLoader when response headers are received or when an |
48 // error occurs (in response to the call of pp::URLLoader::Open()). | 48 // error occurs (in response to the call of pp::URLLoader::Open()). |
49 // Look at <ppapi/c/ppb_url_loader.h> and | 49 // Look at <ppapi/c/ppb_url_loader.h> and |
50 // <ppapi/cpp/url_loader.h> for more information about pp::URLLoader. | 50 // <ppapi/cpp/url_loader.h> for more information about pp::URLLoader. |
51 void OnOpen(int32_t result); | 51 void OnOpen(int32_t result); |
52 | 52 |
53 // Callback fo the pp::URLLoader::ReadResponseBody(). | 53 // Callback for the pp::URLLoader::ReadResponseBody(). |
54 // |result| contains the number of bytes read or an error code. | 54 // |result| contains the number of bytes read or an error code. |
55 // Appends data from this->buffer_ to this->url_response_body_. | 55 // Appends data from this->buffer_ to this->url_response_body_. |
56 void OnRead(int32_t result); | 56 void OnRead(int32_t result); |
57 | 57 |
58 // Reads the response body (asynchronously) into this->buffer_. | 58 // Reads the response body (asynchronously) into this->buffer_. |
59 // OnRead() will be called when bytes are received or when an error occurs. | 59 // OnRead() will be called when bytes are received or when an error occurs. |
60 void ReadBody(); | 60 void ReadBody(); |
61 | 61 |
62 // Append data bytes read from the URL onto the internal buffer. Does | 62 // Append data bytes read from the URL onto the internal buffer. Does |
63 // nothing if |num_bytes| is 0. | 63 // nothing if |num_bytes| is 0. |
(...skipping 16 matching lines...) Expand all Loading... |
80 char* buffer_; // Temporary buffer for reads. | 80 char* buffer_; // Temporary buffer for reads. |
81 std::string url_response_body_; // Contains accumulated downloaded data. | 81 std::string url_response_body_; // Contains accumulated downloaded data. |
82 pp::CompletionCallbackFactory<GetURLHandler> cc_factory_; | 82 pp::CompletionCallbackFactory<GetURLHandler> cc_factory_; |
83 | 83 |
84 GetURLHandler(const GetURLHandler&); | 84 GetURLHandler(const GetURLHandler&); |
85 void operator=(const GetURLHandler&); | 85 void operator=(const GetURLHandler&); |
86 }; | 86 }; |
87 | 87 |
88 #endif // EXAMPLES_GETURL_GETURL_HANDLER_H_ | 88 #endif // EXAMPLES_GETURL_GETURL_HANDLER_H_ |
89 | 89 |
OLD | NEW |