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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 VLOG(1) << "Unable to successfully run RegisterCallbackWin8."; | 163 VLOG(1) << "Unable to successfully run RegisterCallbackWin8."; |
162 break; | 164 break; |
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 return std::move(notify_item_); |
172 // to NULL. | |
173 scoped_ptr<NOTIFYITEM> rv(notify_item_.release()); | |
174 return rv.Pass(); | |
175 } | 174 } |
176 | 175 |
177 bool StatusTrayStateChangerWin::RegisterCallbackWin8() { | 176 bool StatusTrayStateChangerWin::RegisterCallbackWin8() { |
178 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify_win8; | 177 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify_win8; |
179 HRESULT hr = tray_notify_win8.QueryFrom(tray_notify_.get()); | 178 HRESULT hr = tray_notify_win8.QueryFrom(tray_notify_.get()); |
180 if (FAILED(hr)) | 179 if (FAILED(hr)) |
181 return false; | 180 return false; |
182 | 181 |
183 // The following two lines cause Windows Explorer to call us back with all the | 182 // 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 | 183 // 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()); | 225 HRESULT hr = tray_notify.QueryFrom(tray_notify_.get()); |
227 if (SUCCEEDED(hr)) | 226 if (SUCCEEDED(hr)) |
228 tray_notify->SetPreference(notify_item.get()); | 227 tray_notify->SetPreference(notify_item.get()); |
229 } else if (interface_version_ == INTERFACE_VERSION_WIN8) { | 228 } else if (interface_version_ == INTERFACE_VERSION_WIN8) { |
230 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify; | 229 base::win::ScopedComPtr<ITrayNotifyWin8> tray_notify; |
231 HRESULT hr = tray_notify.QueryFrom(tray_notify_.get()); | 230 HRESULT hr = tray_notify.QueryFrom(tray_notify_.get()); |
232 if (SUCCEEDED(hr)) | 231 if (SUCCEEDED(hr)) |
233 tray_notify->SetPreference(notify_item.get()); | 232 tray_notify->SetPreference(notify_item.get()); |
234 } | 233 } |
235 } | 234 } |
OLD | NEW |