| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_SAVE_FILE_H__ | |
| 6 #define CHROME_BROWSER_SAVE_FILE_H__ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/scoped_ptr.h" | |
| 12 #include "chrome/browser/save_types.h" | |
| 13 | |
| 14 // SaveFile ---------------------------------------------------------------- | |
| 15 | |
| 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 | |
| 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 | |
| 20 // in a save session. | |
| 21 class SaveFile { | |
| 22 public: | |
| 23 explicit SaveFile(const SaveFileCreateInfo* info); | |
| 24 ~SaveFile(); | |
| 25 | |
| 26 // Write a new chunk of data to the file. Returns true on success. | |
| 27 bool AppendDataToFile(const char* data, int data_len); | |
| 28 | |
| 29 // Abort the saving job and automatically close the file. | |
| 30 void Cancel(); | |
| 31 | |
| 32 // Rename the saved file. Returns 'true' if the rename was successful. | |
| 33 bool Rename(const std::wstring& full_path); | |
| 34 | |
| 35 void Finish(); | |
| 36 | |
| 37 // Accessors. | |
| 38 int save_id() const { return info_->save_id; } | |
| 39 int render_process_id() const { return info_->render_process_id; } | |
| 40 int render_view_id() const { return info_->render_view_id; } | |
| 41 int request_id() const { return info_->request_id; } | |
| 42 SaveFileCreateInfo::SaveFileSource save_source() const { | |
| 43 return info_->save_source; | |
| 44 } | |
| 45 | |
| 46 int64 bytes_so_far() const { return bytes_so_far_; } | |
| 47 std::wstring full_path() const { return full_path_; } | |
| 48 bool path_renamed() const { return path_renamed_; } | |
| 49 bool in_progress() const { return in_progress_; } | |
| 50 | |
| 51 private: | |
| 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 | |
| 54 // the destructor. | |
| 55 void Close(); | |
| 56 bool Open(const wchar_t* open_mode); | |
| 57 | |
| 58 scoped_ptr<const SaveFileCreateInfo> info_; | |
| 59 | |
| 60 // OS file handle for writing | |
| 61 FILE* file_; | |
| 62 | |
| 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. | |
| 65 int64 bytes_so_far_; | |
| 66 | |
| 67 // Full path to the saved file including the file name. | |
| 68 std::wstring full_path_; | |
| 69 | |
| 70 // Whether the saved file is still using its initial temporary path. | |
| 71 bool path_renamed_; | |
| 72 | |
| 73 // Whether the saved file is still receiving data. | |
| 74 bool in_progress_; | |
| 75 | |
| 76 DISALLOW_EVIL_CONSTRUCTORS(SaveFile); | |
| 77 }; | |
| 78 | |
| 79 #endif // CHROME_BROWSER_SAVE_FILE_H__ | |
| 80 | |
| OLD | NEW |