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

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

Issue 11673004: No need to pass DownloadItemModel ownership. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: DownloadShelfContextMenu class cleanup and require GetMenuModel() to return non-NULL Created 7 years, 11 months 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) 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 CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_ 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_ 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "content/public/browser/download_item.h"
12 #include "ui/base/models/simple_menu_model.h" 13 #include "ui/base/models/simple_menu_model.h"
13 14
14 class DownloadItemModel;
15
16 namespace content { 15 namespace content {
17 class DownloadItem;
18 class PageNavigator; 16 class PageNavigator;
19 } 17 }
20 18
21 // This class is responsible for the download shelf context menu. Platform 19 // This class is responsible for the download shelf context menu. Platform
22 // specific subclasses are responsible for creating and running the menu. 20 // specific subclasses are responsible for creating and running the menu.
23 class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate { 21 //
22 // The DownloadItem corresponding to the context menu is observed for removal or
23 // destruction.
24 class DownloadShelfContextMenu : public ui::SimpleMenuModel::Delegate,
25 public content::DownloadItem::Observer {
24 public: 26 public:
25 enum ContextMenuCommands { 27 enum ContextMenuCommands {
26 SHOW_IN_FOLDER = 1, // Open a folder view window with the item selected. 28 SHOW_IN_FOLDER = 1, // Open a folder view window with the item selected.
27 OPEN_WHEN_COMPLETE, // Open the download when it's finished. 29 OPEN_WHEN_COMPLETE, // Open the download when it's finished.
28 ALWAYS_OPEN_TYPE, // Default this file extension to always open. 30 ALWAYS_OPEN_TYPE, // Default this file extension to always open.
29 CANCEL, // Cancel the download. 31 CANCEL, // Cancel the download.
30 TOGGLE_PAUSE, // Temporarily pause a download. 32 TOGGLE_PAUSE, // Temporarily pause a download.
31 DISCARD, // Discard the malicious download. 33 DISCARD, // Discard the malicious download.
32 KEEP, // Keep the malicious download. 34 KEEP, // Keep the malicious download.
33 LEARN_MORE_SCANNING, // Show information about download scanning. 35 LEARN_MORE_SCANNING, // Show information about download scanning.
34 LEARN_MORE_INTERRUPTED,// Show information about interrupted downloads. 36 LEARN_MORE_INTERRUPTED,// Show information about interrupted downloads.
35 }; 37 };
36 38
37 virtual ~DownloadShelfContextMenu(); 39 virtual ~DownloadShelfContextMenu();
38 40
39 content::DownloadItem* download_item() const { return download_item_; } 41 content::DownloadItem* download_item() const { return download_item_; }
40 void set_download_item(content::DownloadItem* item) { download_item_ = item; }
41 42
42 protected: 43 protected:
43 DownloadShelfContextMenu(DownloadItemModel* download_model, 44 DownloadShelfContextMenu(content::DownloadItem* download_item,
44 content::PageNavigator* navigator); 45 content::PageNavigator* navigator);
45 46
46 // Returns the correct menu model depending whether the download item is 47 // Returns the correct menu model depending on the state of the download item.
47 // completed or not. 48 // Returns NULL if the download was destroyed.
48 ui::SimpleMenuModel* GetMenuModel(); 49 ui::SimpleMenuModel* GetMenuModel();
49 50
50 // ui::SimpleMenuModel::Delegate: 51 // ui::SimpleMenuModel::Delegate:
51 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; 52 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
52 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; 53 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
53 virtual void ExecuteCommand(int command_id) OVERRIDE; 54 virtual void ExecuteCommand(int command_id) OVERRIDE;
54 virtual bool GetAcceleratorForCommandId( 55 virtual bool GetAcceleratorForCommandId(
55 int command_id, 56 int command_id,
56 ui::Accelerator* accelerator) OVERRIDE; 57 ui::Accelerator* accelerator) OVERRIDE;
57 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE; 58 virtual bool IsItemForCommandIdDynamic(int command_id) const OVERRIDE;
58 virtual string16 GetLabelForCommandId(int command_id) const OVERRIDE; 59 virtual string16 GetLabelForCommandId(int command_id) const OVERRIDE;
59 60
60 private: 61 private:
62 // Detaches self from |download_item_|. Called when the DownloadItem is
63 // destroyed or when this object is being destroyed.
64 void DetachFromDownloadItem();
65
66 // content::DownloadItem::Observer
67 virtual void OnDownloadDestroyed(content::DownloadItem* download) OVERRIDE;
68
61 ui::SimpleMenuModel* GetInProgressMenuModel(); 69 ui::SimpleMenuModel* GetInProgressMenuModel();
62 ui::SimpleMenuModel* GetFinishedMenuModel(); 70 ui::SimpleMenuModel* GetFinishedMenuModel();
63 ui::SimpleMenuModel* GetInterruptedMenuModel(); 71 ui::SimpleMenuModel* GetInterruptedMenuModel();
64 ui::SimpleMenuModel* GetMaliciousMenuModel(); 72 ui::SimpleMenuModel* GetMaliciousMenuModel();
65 73
66 // We show slightly different menus if the download is in progress vs. if the 74 // We show slightly different menus if the download is in progress vs. if the
67 // download has finished. 75 // download has finished.
68 scoped_ptr<ui::SimpleMenuModel> in_progress_download_menu_model_; 76 scoped_ptr<ui::SimpleMenuModel> in_progress_download_menu_model_;
69 scoped_ptr<ui::SimpleMenuModel> finished_download_menu_model_; 77 scoped_ptr<ui::SimpleMenuModel> finished_download_menu_model_;
70 scoped_ptr<ui::SimpleMenuModel> interrupted_download_menu_model_; 78 scoped_ptr<ui::SimpleMenuModel> interrupted_download_menu_model_;
71 scoped_ptr<ui::SimpleMenuModel> malicious_download_menu_model_; 79 scoped_ptr<ui::SimpleMenuModel> malicious_download_menu_model_;
72 80
73 // A model to control the cancel behavior.
74 DownloadItemModel* download_model_;
75
76 // Information source. 81 // Information source.
77 content::DownloadItem* download_item_; 82 content::DownloadItem* download_item_;
78 83
79 // Used to open tabs. 84 // Used to open tabs.
80 content::PageNavigator* navigator_; 85 content::PageNavigator* navigator_;
81 86
82 DISALLOW_COPY_AND_ASSIGN(DownloadShelfContextMenu); 87 DISALLOW_COPY_AND_ASSIGN(DownloadShelfContextMenu);
83 }; 88 };
84 89
85 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_ 90 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_SHELF_CONTEXT_MENU_H_
OLDNEW
« no previous file with comments | « chrome/browser/download/download_shelf.cc ('k') | chrome/browser/download/download_shelf_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698