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 <objbase.h> | 8 #include <objbase.h> |
9 #include <propkey.h> | 9 #include <propkey.h> |
10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/win/win_util.h" | 16 #include "base/win/win_util.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // Creates an IShellLink object. | 22 // Creates an IShellLink object. |
23 // 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 |
24 // requires three items: the absolute path to an application, an argument | 24 // requires three items: the absolute path to an application, an argument |
25 // string, and a title string. | 25 // string, and a title string. |
26 bool AddShellLink(base::win::ScopedComPtr<IObjectCollection> collection, | 26 bool AddShellLink(base::win::ScopedComPtr<IObjectCollection> collection, |
27 const std::wstring& application_path, | 27 const base::string16& application_path, |
28 scoped_refptr<ShellLinkItem> item) { | 28 scoped_refptr<ShellLinkItem> item) { |
29 // Create an IShellLink object. | 29 // Create an IShellLink object. |
30 base::win::ScopedComPtr<IShellLink> link; | 30 base::win::ScopedComPtr<IShellLink> link; |
31 HRESULT result = link.CreateInstance(CLSID_ShellLink, NULL, | 31 HRESULT result = link.CreateInstance(CLSID_ShellLink, NULL, |
32 CLSCTX_INPROC_SERVER); | 32 CLSCTX_INPROC_SERVER); |
33 if (FAILED(result)) | 33 if (FAILED(result)) |
34 return false; | 34 return false; |
35 | 35 |
36 // Set the application path. | 36 // Set the application path. |
37 // We should exit this function when this call fails because it doesn't make | 37 // We should exit this function when this call fails because it doesn't make |
38 // any sense to add a shortcut that we cannot execute. | 38 // any sense to add a shortcut that we cannot execute. |
39 result = link->SetPath(application_path.c_str()); | 39 result = link->SetPath(application_path.c_str()); |
40 if (FAILED(result)) | 40 if (FAILED(result)) |
41 return false; | 41 return false; |
42 | 42 |
43 // Attach the command-line switches of this process before the given | 43 // Attach the command-line switches of this process before the given |
44 // arguments and set it as the arguments of this IShellLink object. | 44 // arguments and set it as the arguments of this IShellLink object. |
45 // We also exit this function when this call fails because it isn't useful to | 45 // We also exit this function when this call fails because it isn't useful to |
46 // add a shortcut that cannot open the given page. | 46 // add a shortcut that cannot open the given page. |
47 std::wstring arguments(item->GetArguments()); | 47 base::string16 arguments(item->GetArguments()); |
48 if (!arguments.empty()) { | 48 if (!arguments.empty()) { |
49 result = link->SetArguments(arguments.c_str()); | 49 result = link->SetArguments(arguments.c_str()); |
50 if (FAILED(result)) | 50 if (FAILED(result)) |
51 return false; | 51 return false; |
52 } | 52 } |
53 | 53 |
54 // Attach the given icon path to this IShellLink object. | 54 // Attach the given icon path to this IShellLink object. |
55 // Since an icon is an optional item for an IShellLink object, so we don't | 55 // Since an icon is an optional item for an IShellLink object, so we don't |
56 // have to exit even when it fails. | 56 // have to exit even when it fails. |
57 if (!item->icon_path().empty()) | 57 if (!item->icon_path().empty()) |
(...skipping 24 matching lines...) Expand all Loading... |
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 } |
89 | 89 |
90 ShellLinkItem::~ShellLinkItem() {} | 90 ShellLinkItem::~ShellLinkItem() {} |
91 | 91 |
92 std::wstring ShellLinkItem::GetArguments() const { | 92 base::string16 ShellLinkItem::GetArguments() const { |
93 return command_line_.GetArgumentsString(); | 93 return command_line_.GetArgumentsString(); |
94 } | 94 } |
95 | 95 |
96 base::CommandLine* ShellLinkItem::GetCommandLine() { | 96 base::CommandLine* ShellLinkItem::GetCommandLine() { |
97 return &command_line_; | 97 return &command_line_; |
98 } | 98 } |
99 | 99 |
100 | 100 |
101 // JumpListUpdater | 101 // JumpListUpdater |
102 | 102 |
103 JumpListUpdater::JumpListUpdater(const std::wstring& app_user_model_id) | 103 JumpListUpdater::JumpListUpdater(const base::string16& app_user_model_id) |
104 : app_user_model_id_(app_user_model_id), | 104 : app_user_model_id_(app_user_model_id), user_max_items_(0) {} |
105 user_max_items_(0) { | |
106 } | |
107 | 105 |
108 JumpListUpdater::~JumpListUpdater() { | 106 JumpListUpdater::~JumpListUpdater() { |
109 } | 107 } |
110 | 108 |
111 // static | 109 // static |
112 bool JumpListUpdater::IsEnabled() { | 110 bool JumpListUpdater::IsEnabled() { |
113 // Do not create custom JumpLists in tests. See http://crbug.com/389375. | 111 // Do not create custom JumpLists in tests. See http://crbug.com/389375. |
114 return !base::CommandLine::ForCurrentProcess()->HasSwitch( | 112 return !base::CommandLine::ForCurrentProcess()->HasSwitch( |
115 switches::kTestType); | 113 switches::kTestType); |
116 } | 114 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 // interface to retrieve each item in the list. So, we retrieve the | 194 // interface to retrieve each item in the list. So, we retrieve the |
197 // IObjectArray interface from the EnumerableObjectCollection object. | 195 // IObjectArray interface from the EnumerableObjectCollection object. |
198 base::win::ScopedComPtr<IObjectArray> object_array; | 196 base::win::ScopedComPtr<IObjectArray> object_array; |
199 result = collection.CopyTo(object_array.Receive()); | 197 result = collection.CopyTo(object_array.Receive()); |
200 if (FAILED(result)) | 198 if (FAILED(result)) |
201 return false; | 199 return false; |
202 | 200 |
203 return SUCCEEDED(destination_list_->AddUserTasks(object_array.Get())); | 201 return SUCCEEDED(destination_list_->AddUserTasks(object_array.Get())); |
204 } | 202 } |
205 | 203 |
206 bool JumpListUpdater::AddCustomCategory(const std::wstring& category_name, | 204 bool JumpListUpdater::AddCustomCategory(const base::string16& category_name, |
207 const ShellLinkItemList& link_items, | 205 const ShellLinkItemList& link_items, |
208 size_t max_items) { | 206 size_t max_items) { |
209 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. | 207 // TODO(chengx): Remove the UMA histogram after fixing http://crbug.com/40407. |
210 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.AddCustomCategoryDuration"); | 208 SCOPED_UMA_HISTOGRAM_TIMER("WinJumplistUpdater.AddCustomCategoryDuration"); |
211 | 209 |
212 if (!destination_list_.Get()) | 210 if (!destination_list_.Get()) |
213 return false; | 211 return false; |
214 | 212 |
215 // Retrieve the absolute path to "chrome.exe". | 213 // Retrieve the absolute path to "chrome.exe". |
216 base::FilePath application_path; | 214 base::FilePath application_path; |
(...skipping 29 matching lines...) Expand all Loading... |
246 // It seems the ICustomDestinationList::AppendCategory() function just | 244 // It seems the ICustomDestinationList::AppendCategory() function just |
247 // replaces all items in the given category with the ones in the new list. | 245 // replaces all items in the given category with the ones in the new list. |
248 base::win::ScopedComPtr<IObjectArray> object_array; | 246 base::win::ScopedComPtr<IObjectArray> object_array; |
249 result = collection.CopyTo(object_array.Receive()); | 247 result = collection.CopyTo(object_array.Receive()); |
250 if (FAILED(result)) | 248 if (FAILED(result)) |
251 return false; | 249 return false; |
252 | 250 |
253 return SUCCEEDED(destination_list_->AppendCategory(category_name.c_str(), | 251 return SUCCEEDED(destination_list_->AppendCategory(category_name.c_str(), |
254 object_array.Get())); | 252 object_array.Get())); |
255 } | 253 } |
OLD | NEW |