| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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_DOWNLOAD_SAVE_FILE_H__ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_SAVE_FILE_H__ |
| 6 #define CHROME_BROWSER_DOWNLOAD_SAVE_FILE_H__ | 6 #define CHROME_BROWSER_DOWNLOAD_SAVE_FILE_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "chrome/browser/download/save_types.h" | 12 #include "chrome/browser/download/save_types.h" |
| 13 | 13 |
| 14 // SaveFile ---------------------------------------------------------------- | 14 // SaveFile ---------------------------------------------------------------- |
| 15 | 15 |
| 16 // These objects live exclusively on the file thread and handle the writing | 16 // These objects live exclusively on the file thread and handle the writing |
| 17 // operations for one save item. These objects live only for the duration that | 17 // operations for one save item. These objects live only for the duration that |
| 18 // the saving job is 'in progress': once the saving job has been completed or | 18 // the saving job is 'in progress': once the saving job has been completed or |
| 19 // canceled, the SaveFile is destroyed. One SaveFile object represents one item | 19 // canceled, the SaveFile is destroyed. One SaveFile object represents one item |
| 20 // in a save session. | 20 // in a save session. |
| 21 class SaveFile { | 21 class SaveFile { |
| 22 public: | 22 public: |
| 23 explicit SaveFile(const SaveFileCreateInfo* info); | 23 explicit SaveFile(const SaveFileCreateInfo* info); |
| 24 ~SaveFile(); | 24 ~SaveFile(); |
| 25 | 25 |
| 26 // Write a new chunk of data to the file. Returns true on success. | 26 // Write a new chunk of data to the file. Returns true on success. |
| 27 bool AppendDataToFile(const char* data, int data_len); | 27 bool AppendDataToFile(const char* data, size_t data_len); |
| 28 | 28 |
| 29 // Abort the saving job and automatically close the file. | 29 // Abort the saving job and automatically close the file. |
| 30 void Cancel(); | 30 void Cancel(); |
| 31 | 31 |
| 32 // Rename the saved file. Returns 'true' if the rename was successful. | 32 // Rename the saved file. Returns 'true' if the rename was successful. |
| 33 bool Rename(const std::wstring& full_path); | 33 bool Rename(const std::wstring& full_path); |
| 34 | 34 |
| 35 void Finish(); | 35 void Finish(); |
| 36 | 36 |
| 37 // Accessors. | 37 // Accessors. |
| 38 int save_id() const { return info_->save_id; } | 38 int save_id() const { return info_->save_id; } |
| 39 int render_process_id() const { return info_->render_process_id; } | 39 int render_process_id() const { return info_->render_process_id; } |
| 40 int render_view_id() const { return info_->render_view_id; } | 40 int render_view_id() const { return info_->render_view_id; } |
| 41 int request_id() const { return info_->request_id; } | 41 int request_id() const { return info_->request_id; } |
| 42 SaveFileCreateInfo::SaveFileSource save_source() const { | 42 SaveFileCreateInfo::SaveFileSource save_source() const { |
| 43 return info_->save_source; | 43 return info_->save_source; |
| 44 } | 44 } |
| 45 | 45 |
| 46 int64 bytes_so_far() const { return bytes_so_far_; } | 46 int64 bytes_so_far() const { return bytes_so_far_; } |
| 47 std::wstring full_path() const { return full_path_; } | 47 std::wstring full_path() const { return full_path_; } |
| 48 bool path_renamed() const { return path_renamed_; } | 48 bool path_renamed() const { return path_renamed_; } |
| 49 bool in_progress() const { return in_progress_; } | 49 bool in_progress() const { return in_progress_; } |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 // Open or Close the OS file handle. The file is opened in the constructor | 52 // Open or Close the OS file handle. The file is opened in the constructor |
| 53 // based on creation information passed to it, and automatically closed in | 53 // based on creation information passed to it, and automatically closed in |
| 54 // the destructor. | 54 // the destructor. |
| 55 void Close(); | 55 void Close(); |
| 56 bool Open(const wchar_t* open_mode); | 56 bool Open(const char* open_mode); |
| 57 | 57 |
| 58 scoped_ptr<const SaveFileCreateInfo> info_; | 58 scoped_ptr<const SaveFileCreateInfo> info_; |
| 59 | 59 |
| 60 // OS file handle for writing | 60 // OS file handle for writing |
| 61 FILE* file_; | 61 FILE* file_; |
| 62 | 62 |
| 63 // Amount of data received up to this point. We may not know in advance how | 63 // Amount of data received up to this point. We may not know in advance how |
| 64 // much data to expect since some servers don't provide that information. | 64 // much data to expect since some servers don't provide that information. |
| 65 int64 bytes_so_far_; | 65 int64 bytes_so_far_; |
| 66 | 66 |
| 67 // Full path to the saved file including the file name. | 67 // Full path to the saved file including the file name. |
| 68 std::wstring full_path_; | 68 std::wstring full_path_; |
| 69 | 69 |
| 70 // Whether the saved file is still using its initial temporary path. | 70 // Whether the saved file is still using its initial temporary path. |
| 71 bool path_renamed_; | 71 bool path_renamed_; |
| 72 | 72 |
| 73 // Whether the saved file is still receiving data. | 73 // Whether the saved file is still receiving data. |
| 74 bool in_progress_; | 74 bool in_progress_; |
| 75 | 75 |
| 76 DISALLOW_EVIL_CONSTRUCTORS(SaveFile); | 76 DISALLOW_EVIL_CONSTRUCTORS(SaveFile); |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 #endif // CHROME_BROWSER_DOWNLOAD_SAVE_FILE_H__ | 79 #endif // CHROME_BROWSER_DOWNLOAD_SAVE_FILE_H__ |
| 80 | 80 |
| OLD | NEW |