OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/win/jumplist_updater.h" | 5 #include "chrome/browser/win/jumplist_updater.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <propkey.h> | 8 #include <propkey.h> |
9 #include <shobjidl.h> | 9 #include <shobjidl.h> |
10 | 10 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // The IShellLink interface does not have any functions which update its | 61 // The IShellLink interface does not have any functions which update its |
62 // title because this interface is originally for creating an application | 62 // title because this interface is originally for creating an application |
63 // shortcut which doesn't have titles. | 63 // shortcut which doesn't have titles. |
64 // So, we should use the IPropertyStore interface to set its title. | 64 // So, we should use the IPropertyStore interface to set its title. |
65 base::win::ScopedComPtr<IPropertyStore> property_store; | 65 base::win::ScopedComPtr<IPropertyStore> property_store; |
66 result = link.QueryInterface(property_store.Receive()); | 66 result = link.QueryInterface(property_store.Receive()); |
67 if (FAILED(result)) | 67 if (FAILED(result)) |
68 return false; | 68 return false; |
69 | 69 |
70 if (!base::win::SetStringValueForPropertyStore( | 70 if (!base::win::SetStringValueForPropertyStore( |
71 property_store.get(), | 71 property_store.Get(), |
72 PKEY_Title, | 72 PKEY_Title, |
73 item->title().c_str())) { | 73 item->title().c_str())) { |
74 return false; | 74 return false; |
75 } | 75 } |
76 | 76 |
77 // Add this IShellLink object to the given collection. | 77 // Add this IShellLink object to the given collection. |
78 return SUCCEEDED(collection->AddObject(link.get())); | 78 return SUCCEEDED(collection->AddObject(link.Get())); |
79 } | 79 } |
80 | 80 |
81 } // namespace | 81 } // namespace |
82 | 82 |
83 | 83 |
84 // ShellLinkItem | 84 // ShellLinkItem |
85 | 85 |
86 ShellLinkItem::ShellLinkItem() | 86 ShellLinkItem::ShellLinkItem() |
87 : command_line_(base::CommandLine::NO_PROGRAM), icon_index_(0) { | 87 : command_line_(base::CommandLine::NO_PROGRAM), icon_index_(0) { |
88 } | 88 } |
(...skipping 26 matching lines...) Expand all Loading... |
115 return base::win::GetVersion() >= base::win::VERSION_WIN7 && | 115 return base::win::GetVersion() >= base::win::VERSION_WIN7 && |
116 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 116 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
117 switches::kTestType); | 117 switches::kTestType); |
118 } | 118 } |
119 | 119 |
120 bool JumpListUpdater::BeginUpdate() { | 120 bool JumpListUpdater::BeginUpdate() { |
121 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 121 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
122 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.BeginUpdateDuration"); | 122 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.BeginUpdateDuration"); |
123 | 123 |
124 // This instance is expected to be one-time-use only. | 124 // This instance is expected to be one-time-use only. |
125 DCHECK(!destination_list_.get()); | 125 DCHECK(!destination_list_.Get()); |
126 | 126 |
127 // Check preconditions. | 127 // Check preconditions. |
128 if (!JumpListUpdater::IsEnabled() || app_user_model_id_.empty()) | 128 if (!JumpListUpdater::IsEnabled() || app_user_model_id_.empty()) |
129 return false; | 129 return false; |
130 | 130 |
131 // Create an ICustomDestinationList object and attach it to our application. | 131 // Create an ICustomDestinationList object and attach it to our application. |
132 HRESULT result = destination_list_.CreateInstance(CLSID_DestinationList, NULL, | 132 HRESULT result = destination_list_.CreateInstance(CLSID_DestinationList, NULL, |
133 CLSCTX_INPROC_SERVER); | 133 CLSCTX_INPROC_SERVER); |
134 if (FAILED(result)) | 134 if (FAILED(result)) |
135 return false; | 135 return false; |
(...skipping 17 matching lines...) Expand all Loading... |
153 | 153 |
154 user_max_items_ = max_slots; | 154 user_max_items_ = max_slots; |
155 | 155 |
156 return true; | 156 return true; |
157 } | 157 } |
158 | 158 |
159 bool JumpListUpdater::CommitUpdate() { | 159 bool JumpListUpdater::CommitUpdate() { |
160 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 160 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
161 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.CommitUpdateDuration"); | 161 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.CommitUpdateDuration"); |
162 | 162 |
163 if (!destination_list_.get()) | 163 if (!destination_list_.Get()) |
164 return false; | 164 return false; |
165 | 165 |
166 // Commit this transaction and send the updated JumpList to Windows. | 166 // Commit this transaction and send the updated JumpList to Windows. |
167 return SUCCEEDED(destination_list_->CommitList()); | 167 return SUCCEEDED(destination_list_->CommitList()); |
168 } | 168 } |
169 | 169 |
170 bool JumpListUpdater::AddTasks(const ShellLinkItemList& link_items) { | 170 bool JumpListUpdater::AddTasks(const ShellLinkItemList& link_items) { |
171 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 171 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
172 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.AddTasksDuration"); | 172 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.AddTasksDuration"); |
173 | 173 |
174 if (!destination_list_.get()) | 174 if (!destination_list_.Get()) |
175 return false; | 175 return false; |
176 | 176 |
177 // Retrieve the absolute path to "chrome.exe". | 177 // Retrieve the absolute path to "chrome.exe". |
178 base::FilePath application_path; | 178 base::FilePath application_path; |
179 if (!PathService::Get(base::FILE_EXE, &application_path)) | 179 if (!PathService::Get(base::FILE_EXE, &application_path)) |
180 return false; | 180 return false; |
181 | 181 |
182 // Create an EnumerableObjectCollection object to be added items of the | 182 // Create an EnumerableObjectCollection object to be added items of the |
183 // "Task" category. | 183 // "Task" category. |
184 base::win::ScopedComPtr<IObjectCollection> collection; | 184 base::win::ScopedComPtr<IObjectCollection> collection; |
(...skipping 10 matching lines...) Expand all Loading... |
195 | 195 |
196 // We can now add the new list to the JumpList. | 196 // We can now add the new list to the JumpList. |
197 // ICustomDestinationList::AddUserTasks() also uses the IObjectArray | 197 // ICustomDestinationList::AddUserTasks() also uses the IObjectArray |
198 // interface to retrieve each item in the list. So, we retrieve the | 198 // interface to retrieve each item in the list. So, we retrieve the |
199 // IObjectArray interface from the EnumerableObjectCollection object. | 199 // IObjectArray interface from the EnumerableObjectCollection object. |
200 base::win::ScopedComPtr<IObjectArray> object_array; | 200 base::win::ScopedComPtr<IObjectArray> object_array; |
201 result = collection.QueryInterface(object_array.Receive()); | 201 result = collection.QueryInterface(object_array.Receive()); |
202 if (FAILED(result)) | 202 if (FAILED(result)) |
203 return false; | 203 return false; |
204 | 204 |
205 return SUCCEEDED(destination_list_->AddUserTasks(object_array.get())); | 205 return SUCCEEDED(destination_list_->AddUserTasks(object_array.Get())); |
206 } | 206 } |
207 | 207 |
208 bool JumpListUpdater::AddCustomCategory(const std::wstring& category_name, | 208 bool JumpListUpdater::AddCustomCategory(const std::wstring& category_name, |
209 const ShellLinkItemList& link_items, | 209 const ShellLinkItemList& link_items, |
210 size_t max_items) { | 210 size_t max_items) { |
211 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 211 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
212 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.AddCustomCategoryDuration"); | 212 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.AddCustomCategoryDuration"); |
213 | 213 |
214 if (!destination_list_.get()) | 214 if (!destination_list_.Get()) |
215 return false; | 215 return false; |
216 | 216 |
217 // Retrieve the absolute path to "chrome.exe". | 217 // Retrieve the absolute path to "chrome.exe". |
218 base::FilePath application_path; | 218 base::FilePath application_path; |
219 if (!PathService::Get(base::FILE_EXE, &application_path)) | 219 if (!PathService::Get(base::FILE_EXE, &application_path)) |
220 return false; | 220 return false; |
221 | 221 |
222 // Exit this function when the given vector does not contain any items | 222 // Exit this function when the given vector does not contain any items |
223 // because an ICustomDestinationList::AppendCategory() call fails in this | 223 // because an ICustomDestinationList::AppendCategory() call fails in this |
224 // case. | 224 // case. |
(...skipping 21 matching lines...) Expand all Loading... |
246 // the IObjectArray interface from the IEnumerableObjectCollection object | 246 // the IObjectArray interface from the IEnumerableObjectCollection object |
247 // and use it. | 247 // and use it. |
248 // It seems the ICustomDestinationList::AppendCategory() function just | 248 // It seems the ICustomDestinationList::AppendCategory() function just |
249 // replaces all items in the given category with the ones in the new list. | 249 // replaces all items in the given category with the ones in the new list. |
250 base::win::ScopedComPtr<IObjectArray> object_array; | 250 base::win::ScopedComPtr<IObjectArray> object_array; |
251 result = collection.QueryInterface(object_array.Receive()); | 251 result = collection.QueryInterface(object_array.Receive()); |
252 if (FAILED(result)) | 252 if (FAILED(result)) |
253 return false; | 253 return false; |
254 | 254 |
255 return SUCCEEDED(destination_list_->AppendCategory(category_name.c_str(), | 255 return SUCCEEDED(destination_list_->AppendCategory(category_name.c_str(), |
256 object_array.get())); | 256 object_array.Get())); |
257 } | 257 } |
OLD | NEW |