| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 NET_URL_REQUEST_URL_FETCHER_RESPONSE_WRITER_H_ | 5 #ifndef NET_URL_REQUEST_URL_FETCHER_RESPONSE_WRITER_H_ |
| 6 #define NET_URL_REQUEST_URL_FETCHER_RESPONSE_WRITER_H_ | 6 #define NET_URL_REQUEST_URL_FETCHER_RESPONSE_WRITER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 // URLFetcherResponseWriter implementation for std::string. | 59 // URLFetcherResponseWriter implementation for std::string. |
| 60 class NET_EXPORT URLFetcherStringWriter : public URLFetcherResponseWriter { | 60 class NET_EXPORT URLFetcherStringWriter : public URLFetcherResponseWriter { |
| 61 public: | 61 public: |
| 62 URLFetcherStringWriter(); | 62 URLFetcherStringWriter(); |
| 63 virtual ~URLFetcherStringWriter(); | 63 virtual ~URLFetcherStringWriter(); |
| 64 | 64 |
| 65 const std::string& data() const { return data_; } | 65 const std::string& data() const { return data_; } |
| 66 | 66 |
| 67 // URLFetcherResponseWriter overrides: | 67 // URLFetcherResponseWriter overrides: |
| 68 virtual int Initialize(const CompletionCallback& callback) OVERRIDE; | 68 virtual int Initialize(const CompletionCallback& callback) override; |
| 69 virtual int Write(IOBuffer* buffer, | 69 virtual int Write(IOBuffer* buffer, |
| 70 int num_bytes, | 70 int num_bytes, |
| 71 const CompletionCallback& callback) OVERRIDE; | 71 const CompletionCallback& callback) override; |
| 72 virtual int Finish(const CompletionCallback& callback) OVERRIDE; | 72 virtual int Finish(const CompletionCallback& callback) override; |
| 73 virtual URLFetcherStringWriter* AsStringWriter() OVERRIDE; | 73 virtual URLFetcherStringWriter* AsStringWriter() override; |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 std::string data_; | 76 std::string data_; |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(URLFetcherStringWriter); | 78 DISALLOW_COPY_AND_ASSIGN(URLFetcherStringWriter); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // URLFetcherResponseWriter implementation for files. | 81 // URLFetcherResponseWriter implementation for files. |
| 82 class NET_EXPORT URLFetcherFileWriter : public URLFetcherResponseWriter { | 82 class NET_EXPORT URLFetcherFileWriter : public URLFetcherResponseWriter { |
| 83 public: | 83 public: |
| 84 // |file_path| is used as the destination path. If |file_path| is empty, | 84 // |file_path| is used as the destination path. If |file_path| is empty, |
| 85 // Initialize() will create a temporary file. | 85 // Initialize() will create a temporary file. |
| 86 URLFetcherFileWriter( | 86 URLFetcherFileWriter( |
| 87 scoped_refptr<base::SequencedTaskRunner> file_task_runner, | 87 scoped_refptr<base::SequencedTaskRunner> file_task_runner, |
| 88 const base::FilePath& file_path); | 88 const base::FilePath& file_path); |
| 89 virtual ~URLFetcherFileWriter(); | 89 virtual ~URLFetcherFileWriter(); |
| 90 | 90 |
| 91 const base::FilePath& file_path() const { return file_path_; } | 91 const base::FilePath& file_path() const { return file_path_; } |
| 92 | 92 |
| 93 // URLFetcherResponseWriter overrides: | 93 // URLFetcherResponseWriter overrides: |
| 94 virtual int Initialize(const CompletionCallback& callback) OVERRIDE; | 94 virtual int Initialize(const CompletionCallback& callback) override; |
| 95 virtual int Write(IOBuffer* buffer, | 95 virtual int Write(IOBuffer* buffer, |
| 96 int num_bytes, | 96 int num_bytes, |
| 97 const CompletionCallback& callback) OVERRIDE; | 97 const CompletionCallback& callback) override; |
| 98 virtual int Finish(const CompletionCallback& callback) OVERRIDE; | 98 virtual int Finish(const CompletionCallback& callback) override; |
| 99 virtual URLFetcherFileWriter* AsFileWriter() OVERRIDE; | 99 virtual URLFetcherFileWriter* AsFileWriter() override; |
| 100 | 100 |
| 101 // Drops ownership of the file at |file_path_|. | 101 // Drops ownership of the file at |file_path_|. |
| 102 // This class will not delete it or write to it again. | 102 // This class will not delete it or write to it again. |
| 103 void DisownFile(); | 103 void DisownFile(); |
| 104 | 104 |
| 105 private: | 105 private: |
| 106 // Called when a write has been done. | 106 // Called when a write has been done. |
| 107 void DidWrite(const CompletionCallback& callback, int result); | 107 void DidWrite(const CompletionCallback& callback, int result); |
| 108 | 108 |
| 109 // Closes the file if it is open and then delete it. | 109 // Closes the file if it is open and then delete it. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 135 | 135 |
| 136 // Callbacks are created for use with base::FileUtilProxy. | 136 // Callbacks are created for use with base::FileUtilProxy. |
| 137 base::WeakPtrFactory<URLFetcherFileWriter> weak_factory_; | 137 base::WeakPtrFactory<URLFetcherFileWriter> weak_factory_; |
| 138 | 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(URLFetcherFileWriter); | 139 DISALLOW_COPY_AND_ASSIGN(URLFetcherFileWriter); |
| 140 }; | 140 }; |
| 141 | 141 |
| 142 } // namespace net | 142 } // namespace net |
| 143 | 143 |
| 144 #endif // NET_URL_REQUEST_URL_FETCHER_RESPONSE_WRITER_H_ | 144 #endif // NET_URL_REQUEST_URL_FETCHER_RESPONSE_WRITER_H_ |
| OLD | NEW |