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 CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H_ |
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | |
12 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
13 | 14 |
14 class SavePackage; | 15 class SavePackage; |
15 | 16 |
16 namespace content { | 17 namespace content { |
17 class DownloadItem; | 18 class DownloadItem; |
18 } | 19 } |
19 | 20 |
20 namespace gfx { | 21 namespace gfx { |
21 class FontList; | 22 class FontList; |
22 } | 23 } |
23 | 24 |
25 class DownloadAction { | |
asanka
2015/01/23 19:43:53
See DownloadShelfContextMenu::ContextMenuCommands.
yoshiki
2015/01/29 20:20:46
Thanks for guidance. I extracted DownloadCommands
| |
26 public: | |
27 enum Type { | |
28 OPEN = 0, | |
29 PAUSE, | |
30 RESUME, | |
31 VIEW_IN_FOLDER, | |
32 // ALWAYS_OPEN_FILES_OF_THIS_TYPE, | |
33 // NOT_ALWAYS_OPEN_FILES_OF_THIS_TYPE, | |
34 RETRY, | |
35 DISCARD | |
36 }; | |
37 | |
38 explicit DownloadAction(Type type); | |
39 virtual ~DownloadAction(); | |
40 | |
41 base::string16 text() { return text_; } | |
42 Type type() { return type_; } | |
43 private: | |
44 base::string16 text_; | |
45 const Type type_; | |
46 }; | |
47 | |
24 // This class is an abstraction for common UI tasks and properties associated | 48 // This class is an abstraction for common UI tasks and properties associated |
25 // with a DownloadItem. | 49 // with a DownloadItem. |
26 // | 50 // |
27 // It is intended to be used as a thin wrapper around a |DownloadItem*|. As | 51 // It is intended to be used as a thin wrapper around a |DownloadItem*|. As |
28 // such, the caller is expected to ensure that the |download| passed into the | 52 // such, the caller is expected to ensure that the |download| passed into the |
29 // constructor outlives this |DownloadItemModel|. In addition, multiple | 53 // constructor outlives this |DownloadItemModel|. In addition, multiple |
30 // DownloadItemModel objects could be wrapping the same DownloadItem. | 54 // DownloadItemModel objects could be wrapping the same DownloadItem. |
31 class DownloadItemModel { | 55 class DownloadItemModel { |
32 public: | 56 public: |
33 // Constructs a DownloadItemModel. The caller must ensure that |download| | 57 // Constructs a DownloadItemModel. The caller must ensure that |download| |
34 // outlives this object. | 58 // outlives this object. |
35 explicit DownloadItemModel(content::DownloadItem* download); | 59 explicit DownloadItemModel(content::DownloadItem* download); |
36 ~DownloadItemModel(); | 60 ~DownloadItemModel(); |
37 | 61 |
38 // Returns a long descriptive string for a download that's in the INTERRUPTED | 62 // Returns a long descriptive string for a download that's in the INTERRUPTED |
39 // state. For other downloads, the returned string will be empty. | 63 // state. For other downloads, the returned string will be empty. |
40 base::string16 GetInterruptReasonText() const; | 64 base::string16 GetInterruptReasonText() const; |
41 | 65 |
42 // Returns a short one-line status string for the download. | 66 // Returns a short one-line status string for the download. |
67 base::string16 GetTitle() const; | |
asanka
2015/01/23 19:43:53
DownloadItemModel is now used to back the download
yoshiki
2015/01/29 20:20:45
I agree that. I'll split this class into 3 (and ma
| |
68 | |
69 // Returns a short one-line status string for the download. | |
43 base::string16 GetStatusText() const; | 70 base::string16 GetStatusText() const; |
44 | 71 |
45 // Returns the localized status text for an in-progress download. This | 72 // Returns the localized status text for an in-progress download. This |
46 // is the progress status used in the WebUI interface. | 73 // is the progress status used in the WebUI interface. |
47 base::string16 GetTabProgressStatusText() const; | 74 base::string16 GetTabProgressStatusText() const; |
48 | 75 |
76 // Returns a short one-line status string for the download. | |
77 scoped_ptr<std::vector<DownloadAction> > GetPossibleActions() const; | |
78 | |
49 // Returns a string suitable for use as a tooltip. For a regular download, the | 79 // Returns a string suitable for use as a tooltip. For a regular download, the |
50 // tooltip is the filename. For an interrupted download, the string states the | 80 // tooltip is the filename. For an interrupted download, the string states the |
51 // filename and a short description of the reason for interruption. For | 81 // filename and a short description of the reason for interruption. For |
52 // example: | 82 // example: |
53 // Report.pdf | 83 // Report.pdf |
54 // Network disconnected | 84 // Network disconnected |
55 // |font_list| and |max_width| are used to elide the filename and/or interrupt | 85 // |font_list| and |max_width| are used to elide the filename and/or interrupt |
56 // reason as necessary to keep the width of the tooltip text under | 86 // reason as necessary to keep the width of the tooltip text under |
57 // |max_width|. The tooltip will be at most 2 lines. | 87 // |max_width|. The tooltip will be at most 2 lines. |
58 base::string16 GetTooltipText(const gfx::FontList& font_list, int max_width) c onst; | 88 base::string16 GetTooltipText(const gfx::FontList& font_list, int max_width) c onst; |
59 | 89 |
60 // Get the warning text to display for a dangerous download. The |base_width| | 90 // Get the warning text to display for a dangerous download. The |base_width| |
61 // is the maximum width of an embedded filename (if there is one). The metrics | 91 // is the maximum width of an embedded filename (if there is one). The metrics |
62 // for the filename will be based on |font_list|. Should only be called if | 92 // for the filename will be based on |font_list|. Should only be called if |
63 // IsDangerous() is true. | 93 // IsDangerous() is true. |
64 base::string16 GetWarningText(const gfx::FontList& font_list, int base_width) const; | 94 base::string16 GetWarningText(const gfx::FontList& font_list, int base_width) const; |
95 // Get the warning test to notify a dangerous download. Should only be called | |
96 // if IsDangerous() is true. | |
97 base::string16 GetWarningTextLong() const; | |
65 | 98 |
66 // Get the caption text for a button for confirming a dangerous download | 99 // Get the caption text for a button for confirming a dangerous download |
67 // warning. | 100 // warning. |
68 base::string16 GetWarningConfirmButtonText() const; | 101 base::string16 GetWarningConfirmButtonText() const; |
69 | 102 |
70 // Get the number of bytes that has completed so far. Virtual for testing. | 103 // Get the number of bytes that has completed so far. Virtual for testing. |
71 int64 GetCompletedBytes() const; | 104 int64 GetCompletedBytes() const; |
72 | 105 |
73 // Get the total number of bytes for this download. Should return 0 if the | 106 // Get the total number of bytes for this download. Should return 0 if the |
74 // total size of the download is not known. Virual for testing. | 107 // total size of the download is not known. Virual for testing. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 | 200 |
168 // The DownloadItem that this model represents. Note that DownloadItemModel | 201 // The DownloadItem that this model represents. Note that DownloadItemModel |
169 // itself shouldn't maintain any state since there can be more than one | 202 // itself shouldn't maintain any state since there can be more than one |
170 // DownloadItemModel in use with the same DownloadItem. | 203 // DownloadItemModel in use with the same DownloadItem. |
171 content::DownloadItem* download_; | 204 content::DownloadItem* download_; |
172 | 205 |
173 DISALLOW_COPY_AND_ASSIGN(DownloadItemModel); | 206 DISALLOW_COPY_AND_ASSIGN(DownloadItemModel); |
174 }; | 207 }; |
175 | 208 |
176 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H_ | 209 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H_ |
OLD | NEW |