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

Side by Side Diff: chrome/browser/jumplist_updater_win.h

Issue 168583011: Move Windows Jump List boilerplate out of jumplist_win for reuse (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Minor changes after self-review Created 6 years, 10 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
« no previous file with comments | « no previous file | chrome/browser/jumplist_updater_win.cc » ('j') | chrome/browser/jumplist_win.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
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 void AppendArgument(const std::wstring& value);
36 void AppendSwitch(const std::string& name, const std::wstring& value);
37 void CopySwitchesFrom(const CommandLine& source,
38 const char* const switches[],
39 size_t count);
40
41 void SetTitle(const std::wstring& title) {
42 title_ = title;
43 }
44
45 void SetIcon(const std::wstring& path, int index) {
46 icon_path_ = path;
47 icon_index_ = index;
48 }
49
50 void SetIconData(const SkBitmap& data) {
51 icon_data_ = data;
52 }
53
54 private:
55 friend class base::RefCountedThreadSafe<ShellLinkItem>;
56 ~ShellLinkItem();
57
58 // Used for storing and appending command-line arguments.
59 CommandLine command_line_;
60
61 // The string to be displayed in a JumpList.
62 std::wstring title_;
63
64 // The absolute path to an icon to be displayed in a JumpList.
65 std::wstring icon_path_;
66
67 // The icon index in the icon file. If an icon file consists of two or more
68 // icons, set this value to identify the icon. If an icon file consists of
69 // one icon, this value is 0.
70 int icon_index_;
71
72 // Icon bitmap. Used by the browser JumpList.
73 // Note that an icon path must be supplied to IShellLink, so users of this
74 // class must save icon data to disk.
75 SkBitmap icon_data_;
76
77 DISALLOW_COPY_AND_ASSIGN(ShellLinkItem);
78 };
79
80 typedef std::vector<scoped_refptr<ShellLinkItem> > ShellLinkItemList;
81
82
83 // A utility class that hides the boilerplate for updating Windows JumpLists.
84 // Note that JumpLists are available in Windows 7 and later only.
85 //
86 // Example of usage:
87 //
88 // JumpListUpdater updater(app_id);
89 // if (updater.BeginUpdate()) {
90 // updater.AddTasks(...);
91 // updater.AddCustomCategory(...);
92 // updater.CommitUpdate();
93 // }
94 //
95 // Note:
96 // - Each JumpListUpdater instance is expected to be used once only.
97 class JumpListUpdater {
98 public:
99 explicit JumpListUpdater(const std::wstring& app_user_model_id);
100 ~JumpListUpdater();
101
102 // Returns true if JumpLists are enabled on this OS.
103 static bool IsEnabled();
104
105 // The current user setting for the maximum number of items to display in
106 // JumpLists.
107 size_t user_max_items() const { return user_max_items_; }
108
109 // Start a transaction that updates the JumpList of this application.
110 // This must be called prior to updating the JumpList. If this function
111 // returns false, this instance should not be used.
112 bool BeginUpdate();
113
114 // Commit the update.
115 bool CommitUpdate();
116
117 // Update the predefined "Tasks" category of the JumpList.
118 bool AddTasks(const ShellLinkItemList& link_items);
119
120 // Update an unregistered category of the JumpList.
121 // This function cannot update registered categories (such as "Tasks")
122 // because special steps are required for updating them.
123 // |max_items| specifies the maximum number of items from |link_items| to add
124 // to the JumpList.
125 bool AddCustomCategory(const std::wstring& category_name,
126 const ShellLinkItemList& link_items,
127 size_t max_items);
128
129 private:
130 // The app ID.
131 std::wstring app_user_model_id_;
132
133 // The application (absolute path) target for each shell link in the JumpList.
134 // The current users of this class all use "chrome.exe".
135 base::FilePath application_path_;
136
137 // Windows API interface used to modify JumpLists.
138 base::win::ScopedComPtr<ICustomDestinationList> destination_list_;
139
140 // The current user setting for "Number of recent items to display in Jump
141 // Lists" option in the "Taskbar and Start Menu Properties".
142 size_t user_max_items_;
143
144 DISALLOW_COPY_AND_ASSIGN(JumpListUpdater);
145 };
146
147 #endif // CHROME_BROWSER_JUMPLIST_UPDATER_WIN_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/jumplist_updater_win.cc » ('j') | chrome/browser/jumplist_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698