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

Side by Side Diff: base/win/shortcut.cc

Issue 750063002: Remove implicit conversions from scoped_refptr to T* in base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 | « base/test/test_shortcut_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/win/shortcut.h" 5 #include "base/win/shortcut.h"
6 6
7 #include <shellapi.h> 7 #include <shellapi.h>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <propkey.h> 9 #include <propkey.h>
10 10
(...skipping 15 matching lines...) Expand all
26 // If any of the above steps fail, both |i_shell_link| and |i_persist_file| will 26 // If any of the above steps fail, both |i_shell_link| and |i_persist_file| will
27 // be released. 27 // be released.
28 void InitializeShortcutInterfaces( 28 void InitializeShortcutInterfaces(
29 const wchar_t* shortcut, 29 const wchar_t* shortcut,
30 ScopedComPtr<IShellLink>* i_shell_link, 30 ScopedComPtr<IShellLink>* i_shell_link,
31 ScopedComPtr<IPersistFile>* i_persist_file) { 31 ScopedComPtr<IPersistFile>* i_persist_file) {
32 i_shell_link->Release(); 32 i_shell_link->Release();
33 i_persist_file->Release(); 33 i_persist_file->Release();
34 if (FAILED(i_shell_link->CreateInstance(CLSID_ShellLink, NULL, 34 if (FAILED(i_shell_link->CreateInstance(CLSID_ShellLink, NULL,
35 CLSCTX_INPROC_SERVER)) || 35 CLSCTX_INPROC_SERVER)) ||
36 FAILED(i_persist_file->QueryFrom(*i_shell_link)) || 36 FAILED(i_persist_file->QueryFrom(i_shell_link->get())) ||
37 (shortcut && FAILED((*i_persist_file)->Load(shortcut, STGM_READWRITE)))) { 37 (shortcut && FAILED((*i_persist_file)->Load(shortcut, STGM_READWRITE)))) {
38 i_shell_link->Release(); 38 i_shell_link->Release();
39 i_persist_file->Release(); 39 i_persist_file->Release();
40 } 40 }
41 } 41 }
42 42
43 } // namespace 43 } // namespace
44 44
45 bool CreateOrUpdateShortcutLink(const FilePath& shortcut_path, 45 bool CreateOrUpdateShortcutLink(const FilePath& shortcut_path,
46 const ShortcutProperties& properties, 46 const ShortcutProperties& properties,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 return false; 122 return false;
123 } 123 }
124 124
125 bool has_app_id = 125 bool has_app_id =
126 (properties.options & ShortcutProperties::PROPERTIES_APP_ID) != 0; 126 (properties.options & ShortcutProperties::PROPERTIES_APP_ID) != 0;
127 bool has_dual_mode = 127 bool has_dual_mode =
128 (properties.options & ShortcutProperties::PROPERTIES_DUAL_MODE) != 0; 128 (properties.options & ShortcutProperties::PROPERTIES_DUAL_MODE) != 0;
129 if ((has_app_id || has_dual_mode) && 129 if ((has_app_id || has_dual_mode) &&
130 GetVersion() >= VERSION_WIN7) { 130 GetVersion() >= VERSION_WIN7) {
131 ScopedComPtr<IPropertyStore> property_store; 131 ScopedComPtr<IPropertyStore> property_store;
132 if (FAILED(property_store.QueryFrom(i_shell_link)) || !property_store.get()) 132 if (FAILED(property_store.QueryFrom(i_shell_link.get())) ||
133 !property_store.get())
133 return false; 134 return false;
134 135
135 if (has_app_id && 136 if (has_app_id &&
136 !SetAppIdForPropertyStore(property_store, properties.app_id.c_str())) { 137 !SetAppIdForPropertyStore(property_store.get(),
138 properties.app_id.c_str())) {
137 return false; 139 return false;
138 } 140 }
139 if (has_dual_mode && 141 if (has_dual_mode &&
140 !SetBooleanValueForPropertyStore(property_store, 142 !SetBooleanValueForPropertyStore(property_store.get(),
141 PKEY_AppUserModel_IsDualMode, 143 PKEY_AppUserModel_IsDualMode,
142 properties.dual_mode)) { 144 properties.dual_mode)) {
143 return false; 145 return false;
144 } 146 }
145 } 147 }
146 148
147 // Release the interfaces to the old shortcut to make sure it doesn't prevent 149 // Release the interfaces to the old shortcut to make sure it doesn't prevent
148 // overwriting it if needed. 150 // overwriting it if needed.
149 old_i_persist_file.Release(); 151 old_i_persist_file.Release();
150 old_i_shell_link.Release(); 152 old_i_shell_link.Release();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 ScopedComPtr<IShellLink> i_shell_link; 187 ScopedComPtr<IShellLink> i_shell_link;
186 188
187 // Get pointer to the IShellLink interface. 189 // Get pointer to the IShellLink interface.
188 if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL, 190 if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
189 CLSCTX_INPROC_SERVER))) { 191 CLSCTX_INPROC_SERVER))) {
190 return false; 192 return false;
191 } 193 }
192 194
193 ScopedComPtr<IPersistFile> persist; 195 ScopedComPtr<IPersistFile> persist;
194 // Query IShellLink for the IPersistFile interface. 196 // Query IShellLink for the IPersistFile interface.
195 if (FAILED(persist.QueryFrom(i_shell_link))) 197 if (FAILED(persist.QueryFrom(i_shell_link.get())))
196 return false; 198 return false;
197 199
198 // Load the shell link. 200 // Load the shell link.
199 if (FAILED(persist->Load(shortcut_path.value().c_str(), STGM_READ))) 201 if (FAILED(persist->Load(shortcut_path.value().c_str(), STGM_READ)))
200 return false; 202 return false;
201 203
202 // Reset |properties|. 204 // Reset |properties|.
203 properties->options = 0; 205 properties->options = 0;
204 206
205 wchar_t temp[MAX_PATH]; 207 wchar_t temp[MAX_PATH];
(...skipping 26 matching lines...) Expand all
232 int temp_index; 234 int temp_index;
233 if (FAILED(i_shell_link->GetIconLocation(temp, MAX_PATH, &temp_index))) 235 if (FAILED(i_shell_link->GetIconLocation(temp, MAX_PATH, &temp_index)))
234 return false; 236 return false;
235 properties->set_icon(FilePath(temp), temp_index); 237 properties->set_icon(FilePath(temp), temp_index);
236 } 238 }
237 239
238 // Windows 7+ options, avoiding unnecessary work. 240 // Windows 7+ options, avoiding unnecessary work.
239 if ((options & ShortcutProperties::PROPERTIES_WIN7) && 241 if ((options & ShortcutProperties::PROPERTIES_WIN7) &&
240 GetVersion() >= VERSION_WIN7) { 242 GetVersion() >= VERSION_WIN7) {
241 ScopedComPtr<IPropertyStore> property_store; 243 ScopedComPtr<IPropertyStore> property_store;
242 if (FAILED(property_store.QueryFrom(i_shell_link))) 244 if (FAILED(property_store.QueryFrom(i_shell_link.get())))
243 return false; 245 return false;
244 246
245 if (options & ShortcutProperties::PROPERTIES_APP_ID) { 247 if (options & ShortcutProperties::PROPERTIES_APP_ID) {
246 ScopedPropVariant pv_app_id; 248 ScopedPropVariant pv_app_id;
247 if (property_store->GetValue(PKEY_AppUserModel_ID, 249 if (property_store->GetValue(PKEY_AppUserModel_ID,
248 pv_app_id.Receive()) != S_OK) { 250 pv_app_id.Receive()) != S_OK) {
249 return false; 251 return false;
250 } 252 }
251 switch (pv_app_id.get().vt) { 253 switch (pv_app_id.get().vt) {
252 case VT_EMPTY: 254 case VT_EMPTY:
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 if (GetVersion() < VERSION_WIN7) 326 if (GetVersion() < VERSION_WIN7)
325 return false; 327 return false;
326 328
327 int result = reinterpret_cast<int>(ShellExecute(NULL, L"taskbarunpin", 329 int result = reinterpret_cast<int>(ShellExecute(NULL, L"taskbarunpin",
328 shortcut, NULL, NULL, 0)); 330 shortcut, NULL, NULL, 0));
329 return result > 32; 331 return result > 32;
330 } 332 }
331 333
332 } // namespace win 334 } // namespace win
333 } // namespace base 335 } // namespace base
OLDNEW
« no previous file with comments | « base/test/test_shortcut_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698