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 CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ |
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ |
7 | 7 |
8 #include "content/browser/download/download_file.h" | 8 #include "content/browser/download/download_file.h" |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 virtual int64 CurrentSpeed() const OVERRIDE; | 61 virtual int64 CurrentSpeed() const OVERRIDE; |
62 virtual bool GetHash(std::string* hash) OVERRIDE; | 62 virtual bool GetHash(std::string* hash) OVERRIDE; |
63 virtual std::string GetHashState() OVERRIDE; | 63 virtual std::string GetHashState() OVERRIDE; |
64 virtual void SetClientGuid(const std::string& guid) OVERRIDE; | 64 virtual void SetClientGuid(const std::string& guid) OVERRIDE; |
65 | 65 |
66 protected: | 66 protected: |
67 // For test class overrides. | 67 // For test class overrides. |
68 virtual DownloadInterruptReason AppendDataToFile( | 68 virtual DownloadInterruptReason AppendDataToFile( |
69 const char* data, size_t data_len); | 69 const char* data, size_t data_len); |
70 | 70 |
71 virtual base::TimeDelta GetRetryDelayForFailedRename(int attempt_number); | |
72 | |
73 virtual bool ShouldRetryFailedRename(DownloadInterruptReason reason); | |
74 | |
75 private: | 71 private: |
76 friend class DownloadFileTest; | |
77 | |
78 // Options for RenameWithRetryInternal. | |
79 enum RenameOption { | |
80 UNIQUIFY = 1 << 0, // If there's already a file on disk that conflicts with | |
81 // |new_path|, try to create a unique file by appending | |
82 // a uniquifier. | |
83 ANNOTATE_WITH_SOURCE_INFORMATION = 1 << 1 | |
84 }; | |
85 | |
86 // Rename file_ to |new_path|. | |
87 // |option| specifies additional operations to be performed during the rename. | |
88 // See RenameOption above. | |
89 // |retries_left| indicates how many times to retry the operation if the | |
90 // rename fails with a transient error. | |
91 // |time_of_first_failure| Set to an empty base::TimeTicks during the first | |
92 // call. Once the first failure is seen, subsequent calls of | |
93 // RenameWithRetryInternal will have a non-empty value keeping track of | |
94 // the time of first observed failure. Used for UMA. | |
95 void RenameWithRetryInternal(const base::FilePath& new_path, | |
96 RenameOption option, | |
97 int retries_left, | |
98 base::TimeTicks time_of_first_failure, | |
99 const RenameCompletionCallback& callback); | |
100 | |
101 // Send an update on our progress. | 72 // Send an update on our progress. |
102 void SendUpdate(); | 73 void SendUpdate(); |
103 | 74 |
104 // Called when there's some activity on stream_reader_ that needs to be | 75 // Called when there's some activity on stream_reader_ that needs to be |
105 // handled. | 76 // handled. |
106 void StreamActive(); | 77 void StreamActive(); |
107 | 78 |
108 // The base file instance. | 79 // The base file instance. |
109 BaseFile file_; | 80 BaseFile file_; |
110 | 81 |
(...skipping 20 matching lines...) Expand all Loading... |
131 base::WeakPtr<DownloadDestinationObserver> observer_; | 102 base::WeakPtr<DownloadDestinationObserver> observer_; |
132 | 103 |
133 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; | 104 base::WeakPtrFactory<DownloadFileImpl> weak_factory_; |
134 | 105 |
135 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); | 106 DISALLOW_COPY_AND_ASSIGN(DownloadFileImpl); |
136 }; | 107 }; |
137 | 108 |
138 } // namespace content | 109 } // namespace content |
139 | 110 |
140 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ | 111 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_IMPL_H_ |
OLD | NEW |