Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_JUMPLIST_UPDATER_WIN_H_ | |
| 6 #define CHROME_BROWSER_JUMPLIST_UPDATER_WIN_H_ | |
| 7 | |
| 8 #include <windows.h> | |
| 9 #include <shobjidl.h> | |
| 10 | |
| 11 #include <string> | |
| 12 #include <vector> | |
| 13 | |
| 14 #include "base/command_line.h" | |
| 15 #include "base/files/file_path.h" | |
| 16 #include "base/memory/ref_counted.h" | |
| 17 #include "base/win/scoped_comptr.h" | |
| 18 #include "third_party/skia/include/core/SkBitmap.h" | |
| 19 | |
| 20 // Represents a class used for creating an IShellLink object. | |
| 21 // Even though an IShellLink also needs the absolute path to an application to | |
| 22 // be executed, this class does not have any variables for it because current | |
| 23 // users always use "chrome.exe" as the application. A custom application path | |
|
James Hawkins
2014/02/18 16:28:44
Optional nit: This last sentence is implied by the
tmdiep
2014/02/18 22:33:47
Removed.
| |
| 24 // should be added when required. | |
| 25 class ShellLinkItem : public base::RefCountedThreadSafe<ShellLinkItem> { | |
| 26 public: | |
| 27 ShellLinkItem(); | |
| 28 | |
| 29 const std::wstring& title() const { return title_; } | |
| 30 const std::wstring& icon_path() const { return icon_path_; } | |
| 31 int icon_index() const { return icon_index_; } | |
| 32 const SkBitmap& icon_data() const { return icon_data_; } | |
| 33 | |
| 34 std::wstring GetArguments() const; | |
| 35 CommandLine* GetCommandLine(); | |
| 36 | |
| 37 void SetTitle(const std::wstring& title) { | |
|
James Hawkins
2014/02/18 16:28:44
setters are like getters, i.e., set_title.
tmdiep
2014/02/18 22:33:47
Done.
| |
| 38 title_ = title; | |
| 39 } | |
| 40 | |
| 41 void SetIcon(const std::wstring& path, int index) { | |
| 42 icon_path_ = path; | |
| 43 icon_index_ = index; | |
| 44 } | |
| 45 | |
| 46 void SetIconData(const SkBitmap& data) { | |
| 47 icon_data_ = data; | |
| 48 } | |
| 49 | |
| 50 private: | |
| 51 friend class base::RefCountedThreadSafe<ShellLinkItem>; | |
| 52 ~ShellLinkItem(); | |
| 53 | |
| 54 // Used for storing and appending command-line arguments. | |
| 55 CommandLine command_line_; | |
| 56 | |
| 57 // The string to be displayed in a JumpList. | |
| 58 std::wstring title_; | |
| 59 | |
| 60 // The absolute path to an icon to be displayed in a JumpList. | |
| 61 std::wstring icon_path_; | |
| 62 | |
| 63 // The icon index in the icon file. If an icon file consists of two or more | |
| 64 // icons, set this value to identify the icon. If an icon file consists of | |
| 65 // one icon, this value is 0. | |
| 66 int icon_index_; | |
| 67 | |
| 68 // Icon bitmap. Used by the browser JumpList. | |
| 69 // Note that an icon path must be supplied to IShellLink, so users of this | |
| 70 // class must save icon data to disk. | |
| 71 SkBitmap icon_data_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(ShellLinkItem); | |
| 74 }; | |
| 75 | |
| 76 typedef std::vector<scoped_refptr<ShellLinkItem> > ShellLinkItemList; | |
| 77 | |
| 78 | |
| 79 // A utility class that hides the boilerplate for updating Windows JumpLists. | |
| 80 // Note that JumpLists are available in Windows 7 and later only. | |
| 81 // | |
| 82 // Example of usage: | |
| 83 // | |
| 84 // JumpListUpdater updater(app_id); | |
| 85 // if (updater.BeginUpdate()) { | |
| 86 // updater.AddTasks(...); | |
| 87 // updater.AddCustomCategory(...); | |
| 88 // updater.CommitUpdate(); | |
| 89 // } | |
| 90 // | |
| 91 // Note: | |
| 92 // - Each JumpListUpdater instance is expected to be used once only. | |
| 93 class JumpListUpdater { | |
| 94 public: | |
| 95 explicit JumpListUpdater(const std::wstring& app_user_model_id); | |
| 96 ~JumpListUpdater(); | |
| 97 | |
| 98 // Returns true if JumpLists are enabled on this OS. | |
| 99 static bool IsEnabled(); | |
| 100 | |
| 101 // The current user setting for the maximum number of items to display in | |
| 102 // JumpLists. | |
| 103 size_t user_max_items() const { return user_max_items_; } | |
| 104 | |
| 105 // Start a transaction that updates the JumpList of this application. | |
|
James Hawkins
2014/02/18 16:28:44
Starts
tmdiep
2014/02/18 22:33:47
Done. As well as similar comments below.
| |
| 106 // This must be called prior to updating the JumpList. If this function | |
| 107 // returns false, this instance should not be used. | |
| 108 bool BeginUpdate(); | |
| 109 | |
| 110 // Commit the update. | |
|
James Hawkins
2014/02/18 16:28:44
Commits
| |
| 111 bool CommitUpdate(); | |
| 112 | |
| 113 // Update the predefined "Tasks" category of the JumpList. | |
|
James Hawkins
2014/02/18 16:28:44
Updates
| |
| 114 bool AddTasks(const ShellLinkItemList& link_items); | |
| 115 | |
| 116 // Update an unregistered category of the JumpList. | |
|
James Hawkins
2014/02/18 16:28:44
Updates
| |
| 117 // This function cannot update registered categories (such as "Tasks") | |
| 118 // because special steps are required for updating them. | |
| 119 // |max_items| specifies the maximum number of items from |link_items| to add | |
| 120 // to the JumpList. | |
| 121 bool AddCustomCategory(const std::wstring& category_name, | |
| 122 const ShellLinkItemList& link_items, | |
| 123 size_t max_items); | |
| 124 | |
| 125 private: | |
| 126 // The app ID. | |
| 127 std::wstring app_user_model_id_; | |
| 128 | |
| 129 // The application (absolute path) target for each shell link in the JumpList. | |
| 130 // The current users of this class all use "chrome.exe". | |
| 131 base::FilePath application_path_; | |
|
James Hawkins
2014/02/18 16:28:44
Why store it as a member variable if it's a consta
tmdiep
2014/02/18 22:33:47
Just an optimization to avoid retrieving the value
| |
| 132 | |
| 133 // Windows API interface used to modify JumpLists. | |
| 134 base::win::ScopedComPtr<ICustomDestinationList> destination_list_; | |
| 135 | |
| 136 // The current user setting for "Number of recent items to display in Jump | |
| 137 // Lists" option in the "Taskbar and Start Menu Properties". | |
| 138 size_t user_max_items_; | |
| 139 | |
| 140 DISALLOW_COPY_AND_ASSIGN(JumpListUpdater); | |
| 141 }; | |
| 142 | |
| 143 #endif // CHROME_BROWSER_JUMPLIST_UPDATER_WIN_H_ | |
| OLD | NEW |