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

Side by Side Diff: chrome/browser/ui/views/status_icons/status_tray_win.cc

Issue 2909213002: Replace deprecated base::NonThreadSafe in chrome/browser/ui/views in favor of SequenceChecker. (Closed)
Patch Set: SequenceChecker => ThreadChecker for StatusTrayStateChangerWin Created 3 years, 6 months 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 | « chrome/browser/ui/views/status_icons/status_tray_state_changer_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 "chrome/browser/ui/views/status_icons/status_tray_win.h" 5 #include "chrome/browser/ui/views/status_icons/status_tray_win.h"
6 6
7 #include <commctrl.h> 7 #include <commctrl.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/sequence_checker.h"
15 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
16 #include "base/threading/non_thread_safe.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "base/win/wrapped_window_proc.h" 18 #include "base/win/wrapped_window_proc.h"
19 #include "chrome/browser/lifetime/application_lifetime.h" 19 #include "chrome/browser/lifetime/application_lifetime.h"
20 #include "chrome/browser/ui/views/status_icons/status_icon_win.h" 20 #include "chrome/browser/ui/views/status_icons/status_icon_win.h"
21 #include "chrome/browser/ui/views/status_icons/status_tray_state_changer_win.h" 21 #include "chrome/browser/ui/views/status_icons/status_tray_state_changer_win.h"
22 #include "chrome/common/chrome_constants.h" 22 #include "chrome/common/chrome_constants.h"
23 #include "ui/display/screen.h" 23 #include "ui/display/screen.h"
24 #include "ui/gfx/geometry/point.h" 24 #include "ui/gfx/geometry/point.h"
25 #include "ui/gfx/win/hwnd_util.h" 25 #include "ui/gfx/win/hwnd_util.h"
26 26
27 static const UINT kStatusIconMessage = WM_APP + 1; 27 static const UINT kStatusIconMessage = WM_APP + 1;
28 28
29 namespace { 29 namespace {
30 // |kBaseIconId| is 2 to avoid conflicts with plugins that hard-code id 1. 30 // |kBaseIconId| is 2 to avoid conflicts with plugins that hard-code id 1.
31 const UINT kBaseIconId = 2; 31 const UINT kBaseIconId = 2;
32 32
33 UINT ReservedIconId(StatusTray::StatusIconType type) { 33 UINT ReservedIconId(StatusTray::StatusIconType type) {
34 return kBaseIconId + static_cast<UINT>(type); 34 return kBaseIconId + static_cast<UINT>(type);
35 } 35 }
36 36
37 } // namespace 37 } // namespace
38 38
39 // Default implementation for StatusTrayStateChanger that communicates to 39 // Default implementation for StatusTrayStateChanger that communicates to
40 // Exporer.exe via COM. It spawns a background thread with a fresh COM 40 // Exporer.exe via COM. It spawns a background thread with a fresh COM
41 // apartment and requests that the visibility be increased unless the user 41 // apartment and requests that the visibility be increased unless the user
42 // has explicitly set the icon to be hidden. 42 // has explicitly set the icon to be hidden.
43 class StatusTrayStateChangerProxyImpl : public StatusTrayStateChangerProxy, 43 class StatusTrayStateChangerProxyImpl : public StatusTrayStateChangerProxy {
44 public base::NonThreadSafe {
45 public: 44 public:
46 StatusTrayStateChangerProxyImpl() 45 StatusTrayStateChangerProxyImpl()
47 : pending_requests_(0), 46 : pending_requests_(0),
48 worker_thread_("StatusIconCOMWorkerThread"), 47 worker_thread_("StatusIconCOMWorkerThread"),
49 weak_factory_(this) { 48 weak_factory_(this) {
50 worker_thread_.init_com_with_mta(false); 49 worker_thread_.init_com_with_mta(false);
51 } 50 }
52 51
52 ~StatusTrayStateChangerProxyImpl() override {
53 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
54 }
55
53 void EnqueueChange(UINT icon_id, HWND window) override { 56 void EnqueueChange(UINT icon_id, HWND window) override {
54 DCHECK(CalledOnValidThread()); 57 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
55 if (pending_requests_ == 0) 58 if (pending_requests_ == 0)
56 worker_thread_.Start(); 59 worker_thread_.Start();
57 60
58 ++pending_requests_; 61 ++pending_requests_;
59 worker_thread_.task_runner()->PostTaskAndReply( 62 worker_thread_.task_runner()->PostTaskAndReply(
60 FROM_HERE, 63 FROM_HERE,
61 base::Bind( 64 base::Bind(
62 &StatusTrayStateChangerProxyImpl::EnqueueChangeOnWorkerThread, 65 &StatusTrayStateChangerProxyImpl::EnqueueChangeOnWorkerThread,
63 icon_id, window), 66 icon_id, window),
64 base::Bind(&StatusTrayStateChangerProxyImpl::ChangeDone, 67 base::Bind(&StatusTrayStateChangerProxyImpl::ChangeDone,
65 weak_factory_.GetWeakPtr())); 68 weak_factory_.GetWeakPtr()));
66 } 69 }
67 70
68 private: 71 private:
69 // Must be called only on |worker_thread_|, to ensure the correct COM 72 // Must be called only on |worker_thread_|, to ensure the correct COM
70 // apartment. 73 // apartment.
71 static void EnqueueChangeOnWorkerThread(UINT icon_id, HWND window) { 74 static void EnqueueChangeOnWorkerThread(UINT icon_id, HWND window) {
72 // It appears that IUnknowns are coincidentally compatible with 75 // It appears that IUnknowns are coincidentally compatible with
73 // scoped_refptr. Normally I wouldn't depend on that but it seems that 76 // scoped_refptr. Normally I wouldn't depend on that but it seems that
74 // base::win::IUnknownImpl itself depends on that coincidence so it's 77 // base::win::IUnknownImpl itself depends on that coincidence so it's
75 // already being assumed elsewhere. 78 // already being assumed elsewhere.
76 scoped_refptr<StatusTrayStateChangerWin> status_tray_state_changer( 79 scoped_refptr<StatusTrayStateChangerWin> status_tray_state_changer(
77 new StatusTrayStateChangerWin(icon_id, window)); 80 new StatusTrayStateChangerWin(icon_id, window));
78 status_tray_state_changer->EnsureTrayIconVisible(); 81 status_tray_state_changer->EnsureTrayIconVisible();
79 } 82 }
80 83
81 // Called on UI thread. 84 // Called on UI thread.
82 void ChangeDone() { 85 void ChangeDone() {
83 DCHECK(CalledOnValidThread()); 86 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
84 DCHECK_GT(pending_requests_, 0); 87 DCHECK_GT(pending_requests_, 0);
85 88
86 if (--pending_requests_ == 0) 89 if (--pending_requests_ == 0)
87 worker_thread_.Stop(); 90 worker_thread_.Stop();
88 } 91 }
89 92
90 private: 93 private:
91 int pending_requests_; 94 int pending_requests_;
92 base::Thread worker_thread_; 95 base::Thread worker_thread_;
96
97 SEQUENCE_CHECKER(sequence_checker_);
98
93 base::WeakPtrFactory<StatusTrayStateChangerProxyImpl> weak_factory_; 99 base::WeakPtrFactory<StatusTrayStateChangerProxyImpl> weak_factory_;
94 100
95 DISALLOW_COPY_AND_ASSIGN(StatusTrayStateChangerProxyImpl); 101 DISALLOW_COPY_AND_ASSIGN(StatusTrayStateChangerProxyImpl);
96 }; 102 };
97 103
98 StatusTrayWin::StatusTrayWin() 104 StatusTrayWin::StatusTrayWin()
99 : next_icon_id_(1), 105 : next_icon_id_(1),
100 atom_(0), 106 atom_(0),
101 instance_(NULL), 107 instance_(NULL),
102 window_(NULL) { 108 window_(NULL) {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 240 }
235 241
236 void StatusTrayWin::SetStatusTrayStateChangerProxyForTest( 242 void StatusTrayWin::SetStatusTrayStateChangerProxyForTest(
237 std::unique_ptr<StatusTrayStateChangerProxy> proxy) { 243 std::unique_ptr<StatusTrayStateChangerProxy> proxy) {
238 state_changer_proxy_ = std::move(proxy); 244 state_changer_proxy_ = std::move(proxy);
239 } 245 }
240 246
241 StatusTray* StatusTray::Create() { 247 StatusTray* StatusTray::Create() {
242 return new StatusTrayWin(); 248 return new StatusTrayWin();
243 } 249 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/status_icons/status_tray_state_changer_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698