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/ui/views/status_icons/status_tray_state_changer_win.h" | 5 #include "chrome/browser/ui/views/status_icons/status_tray_state_changer_win.h" |
6 | 6 |
7 #include <utility> | |
8 | |
7 namespace { | 9 namespace { |
8 | 10 |
9 //////////////////////////////////////////////////////////////////////////////// | 11 //////////////////////////////////////////////////////////////////////////////// |
10 // Status Tray API | 12 // Status Tray API |
11 | 13 |
12 // The folowing describes the interface to the undocumented Windows Exporer APIs | 14 // The folowing describes the interface to the undocumented Windows Exporer APIs |
13 // for manipulating with the status tray area. This code should be used with | 15 // for manipulating with the status tray area. This code should be used with |
14 // care as it can change with versions (even minor versions) of Windows. | 16 // care as it can change with versions (even minor versions) of Windows. |
15 | 17 |
16 // ITrayNotify is an interface describing the API for manipulating the state of | 18 // ITrayNotify is an interface describing the API for manipulating the state of |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 // not changing anything. | 73 // not changing anything. |
72 if (notify_item->preference == PREFERENCE_SHOW_NEVER) | 74 if (notify_item->preference == PREFERENCE_SHOW_NEVER) |
73 return; | 75 return; |
74 | 76 |
75 // If we are already on the taskbar, return since nothing needs to be done. | 77 // If we are already on the taskbar, return since nothing needs to be done. |
76 if (notify_item->preference == PREFERENCE_SHOW_ALWAYS) | 78 if (notify_item->preference == PREFERENCE_SHOW_ALWAYS) |
77 return; | 79 return; |
78 | 80 |
79 notify_item->preference = PREFERENCE_SHOW_ALWAYS; | 81 notify_item->preference = PREFERENCE_SHOW_ALWAYS; |
80 | 82 |
81 SendNotifyItemUpdate(notify_item.Pass()); | 83 SendNotifyItemUpdate(std::move(notify_item)); |
82 } | 84 } |
83 | 85 |
84 STDMETHODIMP_(ULONG) StatusTrayStateChangerWin::AddRef() { | 86 STDMETHODIMP_(ULONG) StatusTrayStateChangerWin::AddRef() { |
85 DCHECK(CalledOnValidThread()); | 87 DCHECK(CalledOnValidThread()); |
86 return base::win::IUnknownImpl::AddRef(); | 88 return base::win::IUnknownImpl::AddRef(); |
87 } | 89 } |
88 | 90 |
89 STDMETHODIMP_(ULONG) StatusTrayStateChangerWin::Release() { | 91 STDMETHODIMP_(ULONG) StatusTrayStateChangerWin::Release() { |
90 DCHECK(CalledOnValidThread()); | 92 DCHECK(CalledOnValidThread()); |
91 return base::win::IUnknownImpl::Release(); | 93 return base::win::IUnknownImpl::Release(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 case INTERFACE_VERSION_LEGACY: | 165 case INTERFACE_VERSION_LEGACY: |
164 if (!RegisterCallbackLegacy()) | 166 if (!RegisterCallbackLegacy()) |
165 VLOG(1) << "Unable to successfully run RegisterCallbackLegacy."; | 167 VLOG(1) << "Unable to successfully run RegisterCallbackLegacy."; |
166 break; | 168 break; |
167 default: | 169 default: |
168 NOTREACHED(); | 170 NOTREACHED(); |
169 } | 171 } |
170 | 172 |
171 // Adding an intermediate scoped pointer here so that |notify_item_| is reset | 173 // Adding an intermediate scoped pointer here so that |notify_item_| is reset |
172 // to NULL. | 174 // to NULL. |
173 scoped_ptr<NOTIFYITEM> rv(notify_item_.release()); | 175 scoped_ptr<NOTIFYITEM> rv(std::move(notify_item_)); |
brettw
2016/03/02 19:09:08
This code is pretty suspicious.
With your change
mmenke
2016/03/02 19:13:25
Interesting...I was told this was fine for scoped_
dcheng
2016/03/02 19:38:31
In general, you're right: you can't depend on the
| |
174 return rv.Pass(); | 176 return rv; |
175 } | 177 } |
176 | 178 |
177 bool StatusTrayStateChangerWin::RegisterCallbackWin8() { | 179 bool StatusTrayStateChangerWin::RegisterCallbackWin8() { |
178 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify_win8; | 180 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify_win8; |
179 HRESULT hr = tray_notify_win8.QueryFrom(tray_notify_.get()); | 181 HRESULT hr = tray_notify_win8.QueryFrom(tray_notify_.get()); |
180 if (FAILED(hr)) | 182 if (FAILED(hr)) |
181 return false; | 183 return false; |
182 | 184 |
183 // The following two lines cause Windows Explorer to call us back with all the | 185 // The following two lines cause Windows Explorer to call us back with all the |
184 // existing tray icons and their preference. It would also presumably notify | 186 // existing tray icons and their preference. It would also presumably notify |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 HRESULT hr = tray_notify.QueryFrom(tray_notify_.get()); | 228 HRESULT hr = tray_notify.QueryFrom(tray_notify_.get()); |
227 if (SUCCEEDED(hr)) | 229 if (SUCCEEDED(hr)) |
228 tray_notify->SetPreference(notify_item.get()); | 230 tray_notify->SetPreference(notify_item.get()); |
229 } else if (interface_version_ == INTERFACE_VERSION_WIN8) { | 231 } else if (interface_version_ == INTERFACE_VERSION_WIN8) { |
230 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify; | 232 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify; |
231 HRESULT hr = tray_notify.QueryFrom(tray_notify_.get()); | 233 HRESULT hr = tray_notify.QueryFrom(tray_notify_.get()); |
232 if (SUCCEEDED(hr)) | 234 if (SUCCEEDED(hr)) |
233 tray_notify->SetPreference(notify_item.get()); | 235 tray_notify->SetPreference(notify_item.get()); |
234 } | 236 } |
235 } | 237 } |
OLD | NEW |