Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: chrome/browser/download/download_item_model.h

Issue 11419169: Use DownloadItemModel for storing chrome/ specific UI data for DownloadItems. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 15 matching lines...) Expand all
26 // 26 //
27 // It is intended to be used as a thin wrapper around a |DownloadItem*|. As 27 // 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 28 // such, the caller is expected to ensure that the |download| passed into the
29 // constructor outlives this |DownloadItemModel|. In addition, multiple 29 // constructor outlives this |DownloadItemModel|. In addition, multiple
30 // DownloadItemModel objects could be wrapping the same DownloadItem. 30 // DownloadItemModel objects could be wrapping the same DownloadItem.
31 class DownloadItemModel { 31 class DownloadItemModel {
32 public: 32 public:
33 // Constructs a DownloadItemModel. The caller must ensure that |download| 33 // Constructs a DownloadItemModel. The caller must ensure that |download|
34 // outlives this object. 34 // outlives this object.
35 explicit DownloadItemModel(content::DownloadItem* download); 35 explicit DownloadItemModel(content::DownloadItem* download);
36 virtual ~DownloadItemModel(); 36 ~DownloadItemModel();
37 37
38 // Cancel the task corresponding to the item. 38 // Cancel the task corresponding to the item.
39 void CancelTask(); 39 void CancelTask();
40 40
41 // Returns a short one-line status string for the download.
42 string16 GetStatusText() const;
43
44 // Returns a long descriptive string for a download that's in the INTERRUPTED 41 // Returns a long descriptive string for a download that's in the INTERRUPTED
45 // state. For other downloads, the returned string will be empty. 42 // state. For other downloads, the returned string will be empty.
46 string16 GetInterruptReasonText() const; 43 string16 GetInterruptReasonText() const;
47 44
45 // Returns a short one-line status string for the download.
46 string16 GetStatusText() const;
47
48 // Returns a string suitable for use as a tooltip. For a regular download, the 48 // Returns a string suitable for use as a tooltip. For a regular download, the
49 // tooltip is the filename. For an interrupted download, the string states the 49 // tooltip is the filename. For an interrupted download, the string states the
50 // filename and a short description of the reason for interruption. For 50 // filename and a short description of the reason for interruption. For
51 // example: 51 // example:
52 // Report.pdf 52 // Report.pdf
53 // Network disconnected 53 // Network disconnected
54 // |font| and |max_width| are used to elide the filename and/or interrupt 54 // |font| and |max_width| are used to elide the filename and/or interrupt
55 // reason as necessary to keep the width of the tooltip text under 55 // reason as necessary to keep the width of the tooltip text under
56 // |max_width|. The tooltip will be at most 2 lines. 56 // |max_width|. The tooltip will be at most 2 lines.
57 string16 GetTooltipText(const gfx::Font& font, int max_width) const; 57 string16 GetTooltipText(const gfx::Font& font, int max_width) const;
58 58
59 // Rough percent complete. Returns -1 if the progress is unknown.
60 int PercentComplete() const;
61
62 // Get the warning text to display for a dangerous download. The |base_width| 59 // Get the warning text to display for a dangerous download. The |base_width|
63 // is the maximum width of an embedded filename (if there is one). The metrics 60 // is the maximum width of an embedded filename (if there is one). The metrics
64 // for the filename will be based on |font|. Should only be called if 61 // for the filename will be based on |font|. Should only be called if
65 // IsDangerous() is true. 62 // IsDangerous() is true.
66 string16 GetWarningText(const gfx::Font& font, int base_width) const; 63 string16 GetWarningText(const gfx::Font& font, int base_width) const;
67 64
68 // Get the caption text for a button for confirming a dangerous download 65 // Get the caption text for a button for confirming a dangerous download
69 // warning. 66 // warning.
70 string16 GetWarningConfirmButtonText() const; 67 string16 GetWarningConfirmButtonText() const;
71 68
69 // Get the number of bytes that has completed so far. Virtual for testing.
70 int64 GetCompletedBytes() const;
71
72 // Get the total number of bytes for this download. Should return 0 if the
73 // total size of the download is not known. Virual for testing.
74 int64 GetTotalBytes() const;
75
76 // Rough percent complete. Returns -1 if the progress is unknown.
77 int PercentComplete() const;
78
79 // Is this considered a dangerous download?
80 bool IsDangerous() const;
81
72 // Is this considered a malicious download? Implies IsDangerous(). 82 // Is this considered a malicious download? Implies IsDangerous().
73 bool IsMalicious() const; 83 bool IsMalicious() const;
74 84
75 // Is this considered a dangerous download? 85 // Returns |true| if this download should be displayed in the downloads shelf.
76 bool IsDangerous() const; 86 bool ShouldShowInShelf() const;
77 87
78 // Get the total number of bytes for this download. Should return 0 if the 88 // Change whether the download should be displayed on the downloads
79 // total size of the download is not known. Virual for testing. 89 // shelf. Setting this is only effective if the download hasn't already been
80 virtual int64 GetTotalBytes() const; 90 // displayed in the shelf.
81 91 void SetShouldShowInShelf(bool should_show);
82 // Get the number of bytes that has completed so far. Virtual for testing.
83 virtual int64 GetCompletedBytes() const;
84 92
85 content::DownloadItem* download() { return download_; } 93 content::DownloadItem* download() { return download_; }
86 94
87 private: 95 private:
88 // Returns a string representations of the current download progress sizes. If 96 // Returns a string representations of the current download progress sizes. If
89 // the total size of the download is known, this string looks like: "100/200 97 // the total size of the download is known, this string looks like: "100/200
90 // MB" where the numerator is the transferred size and the denominator is the 98 // MB" where the numerator is the transferred size and the denominator is the
91 // total size. If the total isn't known, returns the transferred size as a 99 // total size. If the total isn't known, returns the transferred size as a
92 // string (e.g.: "100 MB"). 100 // string (e.g.: "100 MB").
93 string16 GetProgressSizesString() const; 101 string16 GetProgressSizesString() const;
94 102
95 // Returns a string indicating the status of an in-progress download. 103 // Returns a string indicating the status of an in-progress download.
96 string16 GetInProgressStatusString() const; 104 string16 GetInProgressStatusString() const;
97 105
98 // The DownloadItem that this model represents. Note that DownloadItemModel 106 // The DownloadItem that this model represents. Note that DownloadItemModel
99 // itself shouldn't maintain any state since there can be more than one 107 // itself shouldn't maintain any state since there can be more than one
100 // DownloadItemModel in use with the same DownloadItem. 108 // DownloadItemModel in use with the same DownloadItem.
101 content::DownloadItem* download_; 109 content::DownloadItem* download_;
102 110
103 DISALLOW_COPY_AND_ASSIGN(DownloadItemModel); 111 DISALLOW_COPY_AND_ASSIGN(DownloadItemModel);
104 }; 112 };
105 113
106 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H_ 114 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_ITEM_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698