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 // Download utility implementation | 5 // Download utility implementation |
6 | 6 |
7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
8 | 8 |
9 #include "chrome/browser/download/download_util.h" | 9 #include "chrome/browser/download/download_util.h" |
10 | 10 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 #endif | 68 #endif |
69 | 69 |
70 #if defined(USE_AURA) | 70 #if defined(USE_AURA) |
71 #include "ui/aura/client/drag_drop_client.h" | 71 #include "ui/aura/client/drag_drop_client.h" |
72 #include "ui/aura/root_window.h" | 72 #include "ui/aura/root_window.h" |
73 #include "ui/aura/window.h" | 73 #include "ui/aura/window.h" |
74 #endif | 74 #endif |
75 | 75 |
76 namespace { | 76 namespace { |
77 | 77 |
78 // Key used to attach ShowInShelfData to a DownloadItem. | |
79 const char kShowInShelfKey[] = "chrome.download_util.show_in_shelf"; | |
80 | |
81 // Class that tracks the "show in download shelf" setting for a download item. | |
82 class ShowInShelfData : public base::SupportsUserData::Data { | |
83 public: | |
84 explicit ShowInShelfData(bool should_show) : should_show_(should_show) { | |
85 } | |
86 | |
87 bool should_show() const { return should_show_; } | |
88 | |
89 private: | |
90 const bool should_show_; | |
91 }; | |
92 | |
93 // Get the opacity based on |animation_progress|, with values in [0.0, 1.0]. | 78 // Get the opacity based on |animation_progress|, with values in [0.0, 1.0]. |
94 // Range of return value is [0, 255]. | 79 // Range of return value is [0, 255]. |
95 int GetOpacity(double animation_progress) { | 80 int GetOpacity(double animation_progress) { |
96 DCHECK(animation_progress >= 0 && animation_progress <= 1); | 81 DCHECK(animation_progress >= 0 && animation_progress <= 1); |
97 | 82 |
98 // How many times to cycle the complete animation. This should be an odd | 83 // How many times to cycle the complete animation. This should be an odd |
99 // number so that the animation ends faded out. | 84 // number so that the animation ends faded out. |
100 static const int kCompleteAnimationCycles = 5; | 85 static const int kCompleteAnimationCycles = 5; |
101 double temp = animation_progress * kCompleteAnimationCycles * M_PI + M_PI_2; | 86 double temp = animation_progress * kCompleteAnimationCycles * M_PI + M_PI_2; |
102 temp = sin(temp) / 2 + 0.5; | 87 temp = sin(temp) / 2 + 0.5; |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 void RecordDownloadCount(ChromeDownloadCountTypes type) { | 494 void RecordDownloadCount(ChromeDownloadCountTypes type) { |
510 UMA_HISTOGRAM_ENUMERATION( | 495 UMA_HISTOGRAM_ENUMERATION( |
511 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY); | 496 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY); |
512 } | 497 } |
513 | 498 |
514 void RecordDownloadSource(ChromeDownloadSource source) { | 499 void RecordDownloadSource(ChromeDownloadSource source) { |
515 UMA_HISTOGRAM_ENUMERATION( | 500 UMA_HISTOGRAM_ENUMERATION( |
516 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY); | 501 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY); |
517 } | 502 } |
518 | 503 |
519 bool ShouldShowInShelf(content::DownloadItem* item) { | |
520 ShowInShelfData* data = | |
521 static_cast<ShowInShelfData*>(item->GetUserData(kShowInShelfKey)); | |
522 return !data || data->should_show(); | |
523 } | |
524 | |
525 void SetShouldShowInShelf(content::DownloadItem* item, bool should_show) { | |
526 item->SetUserData(kShowInShelfKey, new ShowInShelfData(should_show)); | |
527 } | |
528 | |
529 } // namespace download_util | 504 } // namespace download_util |
OLD | NEW |