OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "content/browser/download/base_file.h" | 13 #include "content/browser/download/base_file.h" |
| 14 #include "content/browser/download/download_id.h" |
14 #include "content/browser/download/download_request_handle.h" | 15 #include "content/browser/download/download_request_handle.h" |
15 #include "content/browser/download/download_types.h" | 16 #include "content/browser/download/download_types.h" |
16 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
17 | 18 |
18 struct DownloadCreateInfo; | 19 struct DownloadCreateInfo; |
19 class DownloadManager; | 20 class DownloadManager; |
20 class ResourceDispatcherHost; | 21 class ResourceDispatcherHost; |
21 | 22 |
22 // These objects live exclusively on the download thread and handle the writing | 23 // These objects live exclusively on the download thread and handle the writing |
23 // operations for one download. These objects live only for the duration that | 24 // operations for one download. These objects live only for the duration that |
24 // the download is 'in progress': once the download has been completed or | 25 // the download is 'in progress': once the download has been completed or |
25 // cancelled, the DownloadFile is destroyed. | 26 // cancelled, the DownloadFile is destroyed. |
26 class CONTENT_EXPORT DownloadFile : public BaseFile { | 27 class CONTENT_EXPORT DownloadFile : public BaseFile { |
27 public: | 28 public: |
28 DownloadFile(const DownloadCreateInfo* info, | 29 DownloadFile(const DownloadCreateInfo* info, |
29 DownloadManager* download_manager); | 30 DownloadManager* download_manager); |
30 virtual ~DownloadFile(); | 31 virtual ~DownloadFile(); |
31 | 32 |
32 // Cancels the download request associated with this file. | 33 // Cancels the download request associated with this file. |
33 void CancelDownloadRequest(); | 34 void CancelDownloadRequest(); |
34 | 35 |
35 int id() const { return id_; } | 36 int id() const { return id_.local(); } |
| 37 const DownloadId& global_id() const { return id_; } |
36 DownloadManager* GetDownloadManager(); | 38 DownloadManager* GetDownloadManager(); |
37 | 39 |
38 virtual std::string DebugString() const; | 40 virtual std::string DebugString() const; |
39 | 41 |
40 // Appends the passed the number between parenthesis the path before the | 42 // Appends the passed the number between parenthesis the path before the |
41 // extension. | 43 // extension. |
42 static void AppendNumberToPath(FilePath* path, int number); | 44 static void AppendNumberToPath(FilePath* path, int number); |
43 | 45 |
44 // Attempts to find a number that can be appended to that path to make it | 46 // Attempts to find a number that can be appended to that path to make it |
45 // unique. If |path| does not exist, 0 is returned. If it fails to find such | 47 // unique. If |path| does not exist, 0 is returned. If it fails to find such |
46 // a number, -1 is returned. | 48 // a number, -1 is returned. |
47 static int GetUniquePathNumber(const FilePath& path); | 49 static int GetUniquePathNumber(const FilePath& path); |
48 | 50 |
49 static FilePath AppendSuffixToPath(const FilePath& path, | 51 static FilePath AppendSuffixToPath(const FilePath& path, |
50 const FilePath::StringType& suffix); | 52 const FilePath::StringType& suffix); |
51 | 53 |
52 // Same as GetUniquePathNumber, except that it also checks the existence | 54 // Same as GetUniquePathNumber, except that it also checks the existence |
53 // of it with the given suffix. | 55 // of it with the given suffix. |
54 // If |path| does not exist, 0 is returned. If it fails to find such | 56 // If |path| does not exist, 0 is returned. If it fails to find such |
55 // a number, -1 is returned. | 57 // a number, -1 is returned. |
56 static int GetUniquePathNumberWithSuffix( | 58 static int GetUniquePathNumberWithSuffix( |
57 const FilePath& path, | 59 const FilePath& path, |
58 const FilePath::StringType& suffix); | 60 const FilePath::StringType& suffix); |
59 | 61 |
60 private: | 62 private: |
61 // The unique identifier for this download, assigned at creation by | 63 // The unique identifier for this download, assigned at creation by |
62 // the DownloadFileManager for its internal record keeping. | 64 // the DownloadFileManager for its internal record keeping. |
63 int id_; | 65 DownloadId id_; |
64 | 66 |
65 // The handle to the request information. Used for operations outside the | 67 // The handle to the request information. Used for operations outside the |
66 // download system, specifically canceling a download. | 68 // download system, specifically canceling a download. |
67 DownloadRequestHandle request_handle_; | 69 DownloadRequestHandle request_handle_; |
68 | 70 |
69 // DownloadManager this download belongs to. | 71 // DownloadManager this download belongs to. |
70 scoped_refptr<DownloadManager> download_manager_; | 72 scoped_refptr<DownloadManager> download_manager_; |
71 | 73 |
72 DISALLOW_COPY_AND_ASSIGN(DownloadFile); | 74 DISALLOW_COPY_AND_ASSIGN(DownloadFile); |
73 }; | 75 }; |
74 | 76 |
75 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ | 77 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_FILE_H_ |
OLD | NEW |