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

Side by Side Diff: chrome/browser/win/settings_app_monitor.cc

Issue 2065673002: Fix shutdown crash in settings app monitor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 | « no previous file | 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/settings_app_monitor.h" 5 #include "chrome/browser/win/settings_app_monitor.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <atlcom.h> 8 #include <atlcom.h>
9 #include <oleauto.h> 9 #include <oleauto.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // Deletes the instance. 47 // Deletes the instance.
48 void DeleteOnAutomationThread(); 48 void DeleteOnAutomationThread();
49 49
50 // Initializes the context, invoking the monitor's |OnInitialized| method via 50 // Initializes the context, invoking the monitor's |OnInitialized| method via
51 // |monitor_runner| when done. On success, the monitor's other On* methods 51 // |monitor_runner| when done. On success, the monitor's other On* methods
52 // will be invoked as events are observed. On failure, this instance 52 // will be invoked as events are observed. On failure, this instance
53 // self-destructs after posting |init_callback|. |task_runner| is the runner 53 // self-destructs after posting |init_callback|. |task_runner| is the runner
54 // for the dedicated thread on which the context lives (owned by its 54 // for the dedicated thread on which the context lives (owned by its
55 // UIAutomationClient). 55 // UIAutomationClient).
56 void Initialize(base::SingleThreadTaskRunner* task_runner, 56 void Initialize(base::SingleThreadTaskRunner* task_runner,
57 base::SequencedTaskRunner* monitor_runner, 57 scoped_refptr<base::SequencedTaskRunner> monitor_runner,
58 const base::WeakPtr<SettingsAppMonitor>& monitor); 58 const base::WeakPtr<SettingsAppMonitor>& monitor);
59 59
60 private: 60 private:
61 class EventHandler; 61 class EventHandler;
62 62
63 // The one and only method that may be called from outside of the automation 63 // The one and only method that may be called from outside of the automation
64 // thread. 64 // thread.
65 Context(); 65 Context();
66 ~Context(); 66 ~Context();
67 67
(...skipping 21 matching lines...) Expand all
89 base::win::ScopedComPtr<IUIAutomationFocusChangedEventHandler> 89 base::win::ScopedComPtr<IUIAutomationFocusChangedEventHandler>
90 GetFocusChangedEventHandler(); 90 GetFocusChangedEventHandler();
91 91
92 // Installs an event handler to observe events of interest. 92 // Installs an event handler to observe events of interest.
93 HRESULT InstallObservers(); 93 HRESULT InstallObservers();
94 94
95 // The task runner for the automation thread. 95 // The task runner for the automation thread.
96 base::SingleThreadTaskRunner* task_runner_ = nullptr; 96 base::SingleThreadTaskRunner* task_runner_ = nullptr;
97 97
98 // The task runner on which the owning monitor lives. 98 // The task runner on which the owning monitor lives.
99 base::SequencedTaskRunner* monitor_runner_ = nullptr; 99 scoped_refptr<base::SequencedTaskRunner> monitor_runner_ = nullptr;
100 100
101 // The monitor that owns this context. 101 // The monitor that owns this context.
102 base::WeakPtr<SettingsAppMonitor> monitor_; 102 base::WeakPtr<SettingsAppMonitor> monitor_;
103 103
104 // The automation client. 104 // The automation client.
105 base::win::ScopedComPtr<IUIAutomation> automation_; 105 base::win::ScopedComPtr<IUIAutomation> automation_;
106 106
107 // The event handler. 107 // The event handler.
108 base::win::ScopedComPtr<IUnknown> event_handler_; 108 base::win::ScopedComPtr<IUnknown> event_handler_;
109 109
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 return context->weak_ptr_factory_.GetWeakPtr(); 557 return context->weak_ptr_factory_.GetWeakPtr();
558 } 558 }
559 559
560 void SettingsAppMonitor::Context::DeleteOnAutomationThread() { 560 void SettingsAppMonitor::Context::DeleteOnAutomationThread() {
561 DCHECK(task_runner_->BelongsToCurrentThread()); 561 DCHECK(task_runner_->BelongsToCurrentThread());
562 delete this; 562 delete this;
563 } 563 }
564 564
565 void SettingsAppMonitor::Context::Initialize( 565 void SettingsAppMonitor::Context::Initialize(
566 base::SingleThreadTaskRunner* task_runner, 566 base::SingleThreadTaskRunner* task_runner,
567 base::SequencedTaskRunner* monitor_runner, 567 scoped_refptr<base::SequencedTaskRunner> monitor_runner,
568 const base::WeakPtr<SettingsAppMonitor>& monitor) { 568 const base::WeakPtr<SettingsAppMonitor>& monitor) {
569 // This and all other methods must be called on the automation thread. 569 // This and all other methods must be called on the automation thread.
570 DCHECK(task_runner->BelongsToCurrentThread()); 570 DCHECK(task_runner->BelongsToCurrentThread());
571 DCHECK(!monitor_runner->RunsTasksOnCurrentThread()); 571 DCHECK(!monitor_runner->RunsTasksOnCurrentThread());
572 572
573 task_runner_ = task_runner; 573 task_runner_ = task_runner;
574 monitor_runner_ = monitor_runner; 574 monitor_runner_ = monitor_runner;
575 monitor_ = monitor; 575 monitor_ = monitor;
576 576
577 HRESULT result = automation_.CreateInstance(CLSID_CUIAutomation, nullptr, 577 HRESULT result = automation_.CreateInstance(CLSID_CUIAutomation, nullptr,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 weak_ptr_factory_(this) { 698 weak_ptr_factory_(this) {
699 ui::win::CreateATLModuleIfNeeded(); 699 ui::win::CreateATLModuleIfNeeded();
700 // Start the automation thread and initialize the automation client on it. 700 // Start the automation thread and initialize the automation client on it.
701 context_ = Context::Create(); 701 context_ = Context::Create();
702 automation_thread_.init_com_with_mta(true); 702 automation_thread_.init_com_with_mta(true);
703 automation_thread_.Start(); 703 automation_thread_.Start();
704 automation_thread_.task_runner()->PostTask( 704 automation_thread_.task_runner()->PostTask(
705 FROM_HERE, 705 FROM_HERE,
706 base::Bind(&SettingsAppMonitor::Context::Initialize, context_, 706 base::Bind(&SettingsAppMonitor::Context::Initialize, context_,
707 base::Unretained(automation_thread_.task_runner().get()), 707 base::Unretained(automation_thread_.task_runner().get()),
708 base::Unretained(base::SequencedTaskRunnerHandle::Get().get()), 708 base::SequencedTaskRunnerHandle::Get(),
709 weak_ptr_factory_.GetWeakPtr())); 709 weak_ptr_factory_.GetWeakPtr()));
710 } 710 }
711 711
712 SettingsAppMonitor::~SettingsAppMonitor() { 712 SettingsAppMonitor::~SettingsAppMonitor() {
713 DCHECK(thread_checker_.CalledOnValidThread()); 713 DCHECK(thread_checker_.CalledOnValidThread());
714 714
715 // context_ is still valid when the caller destroys the instance before the 715 // context_ is still valid when the caller destroys the instance before the
716 // callback(s) have fired. In this case, delete the context on the automation 716 // callback(s) have fired. In this case, delete the context on the automation
717 // thread before joining with it. DeleteSoon is not used because the monitor 717 // thread before joining with it. DeleteSoon is not used because the monitor
718 // has only a WeakPtr to the context that is bound to the automation thread. 718 // has only a WeakPtr to the context that is bound to the automation thread.
(...skipping 18 matching lines...) Expand all
737 delegate_->OnChooserInvoked(); 737 delegate_->OnChooserInvoked();
738 } 738 }
739 739
740 void SettingsAppMonitor::OnBrowserChosen(const base::string16& browser_name) { 740 void SettingsAppMonitor::OnBrowserChosen(const base::string16& browser_name) {
741 DCHECK(thread_checker_.CalledOnValidThread()); 741 DCHECK(thread_checker_.CalledOnValidThread());
742 delegate_->OnBrowserChosen(browser_name); 742 delegate_->OnBrowserChosen(browser_name);
743 } 743 }
744 744
745 } // namespace win 745 } // namespace win
746 } // namespace shell_integration 746 } // namespace shell_integration
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698