| 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 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 14 #include "base/win/win_util.h" | 15 #include "base/win/win_util.h" |
| 15 #include "base/win/windows_version.h" | 16 #include "base/win/windows_version.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 // Creates an IShellLink object. | 22 // Creates an IShellLink object. |
| 22 // An IShellLink object is almost the same as an application shortcut, and it | 23 // An IShellLink object is almost the same as an application shortcut, and it |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // static | 111 // static |
| 111 bool JumpListUpdater::IsEnabled() { | 112 bool JumpListUpdater::IsEnabled() { |
| 112 // JumpList is implemented only on Windows 7 or later. | 113 // JumpList is implemented only on Windows 7 or later. |
| 113 // Do not create custom JumpLists in tests. See http://crbug.com/389375. | 114 // Do not create custom JumpLists in tests. See http://crbug.com/389375. |
| 114 return base::win::GetVersion() >= base::win::VERSION_WIN7 && | 115 return base::win::GetVersion() >= base::win::VERSION_WIN7 && |
| 115 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 116 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 116 switches::kTestType); | 117 switches::kTestType); |
| 117 } | 118 } |
| 118 | 119 |
| 119 bool JumpListUpdater::BeginUpdate() { | 120 bool JumpListUpdater::BeginUpdate() { |
| 121 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
| 122 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.BeginUpdateDuration"); |
| 123 |
| 120 // This instance is expected to be one-time-use only. | 124 // This instance is expected to be one-time-use only. |
| 121 DCHECK(!destination_list_.get()); | 125 DCHECK(!destination_list_.get()); |
| 122 | 126 |
| 123 // Check preconditions. | 127 // Check preconditions. |
| 124 if (!JumpListUpdater::IsEnabled() || app_user_model_id_.empty()) | 128 if (!JumpListUpdater::IsEnabled() || app_user_model_id_.empty()) |
| 125 return false; | 129 return false; |
| 126 | 130 |
| 127 // Create an ICustomDestinationList object and attach it to our application. | 131 // Create an ICustomDestinationList object and attach it to our application. |
| 128 HRESULT result = destination_list_.CreateInstance(CLSID_DestinationList, NULL, | 132 HRESULT result = destination_list_.CreateInstance(CLSID_DestinationList, NULL, |
| 129 CLSCTX_INPROC_SERVER); | 133 CLSCTX_INPROC_SERVER); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 146 removed.ReceiveVoid()); | 150 removed.ReceiveVoid()); |
| 147 if (FAILED(result)) | 151 if (FAILED(result)) |
| 148 return false; | 152 return false; |
| 149 | 153 |
| 150 user_max_items_ = max_slots; | 154 user_max_items_ = max_slots; |
| 151 | 155 |
| 152 return true; | 156 return true; |
| 153 } | 157 } |
| 154 | 158 |
| 155 bool JumpListUpdater::CommitUpdate() { | 159 bool JumpListUpdater::CommitUpdate() { |
| 160 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
| 161 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.CommitUpdateDuration"); |
| 162 |
| 156 if (!destination_list_.get()) | 163 if (!destination_list_.get()) |
| 157 return false; | 164 return false; |
| 158 | 165 |
| 159 // Commit this transaction and send the updated JumpList to Windows. | 166 // Commit this transaction and send the updated JumpList to Windows. |
| 160 return SUCCEEDED(destination_list_->CommitList()); | 167 return SUCCEEDED(destination_list_->CommitList()); |
| 161 } | 168 } |
| 162 | 169 |
| 163 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. |
| 172 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.AddTasksDuration"); |
| 173 |
| 164 if (!destination_list_.get()) | 174 if (!destination_list_.get()) |
| 165 return false; | 175 return false; |
| 166 | 176 |
| 167 // Retrieve the absolute path to "chrome.exe". | 177 // Retrieve the absolute path to "chrome.exe". |
| 168 base::FilePath application_path; | 178 base::FilePath application_path; |
| 169 if (!PathService::Get(base::FILE_EXE, &application_path)) | 179 if (!PathService::Get(base::FILE_EXE, &application_path)) |
| 170 return false; | 180 return false; |
| 171 | 181 |
| 172 // Create an EnumerableObjectCollection object to be added items of the | 182 // Create an EnumerableObjectCollection object to be added items of the |
| 173 // "Task" category. | 183 // "Task" category. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 191 result = collection.QueryInterface(object_array.Receive()); | 201 result = collection.QueryInterface(object_array.Receive()); |
| 192 if (FAILED(result)) | 202 if (FAILED(result)) |
| 193 return false; | 203 return false; |
| 194 | 204 |
| 195 return SUCCEEDED(destination_list_->AddUserTasks(object_array.get())); | 205 return SUCCEEDED(destination_list_->AddUserTasks(object_array.get())); |
| 196 } | 206 } |
| 197 | 207 |
| 198 bool JumpListUpdater::AddCustomCategory(const std::wstring& category_name, | 208 bool JumpListUpdater::AddCustomCategory(const std::wstring& category_name, |
| 199 const ShellLinkItemList& link_items, | 209 const ShellLinkItemList& link_items, |
| 200 size_t max_items) { | 210 size_t max_items) { |
| 201 if (!destination_list_.get()) | 211 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
| 212 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.AddCustomCategoryDuration"); |
| 213 |
| 214 if (!destination_list_.get()) |
| 202 return false; | 215 return false; |
| 203 | 216 |
| 204 // Retrieve the absolute path to "chrome.exe". | 217 // Retrieve the absolute path to "chrome.exe". |
| 205 base::FilePath application_path; | 218 base::FilePath application_path; |
| 206 if (!PathService::Get(base::FILE_EXE, &application_path)) | 219 if (!PathService::Get(base::FILE_EXE, &application_path)) |
| 207 return false; | 220 return false; |
| 208 | 221 |
| 209 // 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 |
| 210 // because an ICustomDestinationList::AppendCategory() call fails in this | 223 // because an ICustomDestinationList::AppendCategory() call fails in this |
| 211 // case. | 224 // case. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 235 // It seems the ICustomDestinationList::AppendCategory() function just | 248 // It seems the ICustomDestinationList::AppendCategory() function just |
| 236 // 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. |
| 237 base::win::ScopedComPtr<IObjectArray> object_array; | 250 base::win::ScopedComPtr<IObjectArray> object_array; |
| 238 result = collection.QueryInterface(object_array.Receive()); | 251 result = collection.QueryInterface(object_array.Receive()); |
| 239 if (FAILED(result)) | 252 if (FAILED(result)) |
| 240 return false; | 253 return false; |
| 241 | 254 |
| 242 return SUCCEEDED(destination_list_->AppendCategory(category_name.c_str(), | 255 return SUCCEEDED(destination_list_->AppendCategory(category_name.c_str(), |
| 243 object_array.get())); | 256 object_array.get())); |
| 244 } | 257 } |
| OLD | NEW |