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

Side by Side Diff: win8/test/open_with_dialog_controller.cc

Issue 119733002: Add base:: to string16s in win8/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « win8/test/open_with_dialog_controller.h ('k') | win8/test/test_registrar.cc » ('j') | 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "win8/test/open_with_dialog_controller.h" 5 #include "win8/test/open_with_dialog_controller.h"
6 6
7 #include <shlobj.h> 7 #include <shlobj.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 13 matching lines...) Expand all
24 24
25 const int kControllerTimeoutSeconds = 5; 25 const int kControllerTimeoutSeconds = 5;
26 const wchar_t kShellFlyoutClassName[] = L"Shell_Flyout"; 26 const wchar_t kShellFlyoutClassName[] = L"Shell_Flyout";
27 27
28 // A callback invoked with the OpenWithDialogController's results. Said results 28 // A callback invoked with the OpenWithDialogController's results. Said results
29 // are copied to |result_out| and |choices_out| and then |closure| is invoked. 29 // are copied to |result_out| and |choices_out| and then |closure| is invoked.
30 // This function is in support of OpenWithDialogController::RunSynchronously. 30 // This function is in support of OpenWithDialogController::RunSynchronously.
31 void OnMakeDefaultComplete( 31 void OnMakeDefaultComplete(
32 const base::Closure& closure, 32 const base::Closure& closure,
33 HRESULT* result_out, 33 HRESULT* result_out,
34 std::vector<string16>* choices_out, 34 std::vector<base::string16>* choices_out,
35 HRESULT hr, 35 HRESULT hr,
36 std::vector<string16> choices) { 36 std::vector<base::string16> choices) {
37 *result_out = hr; 37 *result_out = hr;
38 *choices_out = choices; 38 *choices_out = choices;
39 closure.Run(); 39 closure.Run();
40 } 40 }
41 41
42 } // namespace 42 } // namespace
43 43
44 // Lives on the main thread and is owned by a controller. May outlive the 44 // Lives on the main thread and is owned by a controller. May outlive the
45 // controller (see Orphan). 45 // controller (see Orphan).
46 class OpenWithDialogController::Context { 46 class OpenWithDialogController::Context {
47 public: 47 public:
48 Context(); 48 Context();
49 ~Context(); 49 ~Context();
50 50
51 base::WeakPtr<Context> AsWeakPtr(); 51 base::WeakPtr<Context> AsWeakPtr();
52 52
53 void Orphan(); 53 void Orphan();
54 54
55 void Begin(HWND parent_window, 55 void Begin(HWND parent_window,
56 const string16& url_protocol, 56 const base::string16& url_protocol,
57 const string16& program_name, 57 const base::string16& program_name,
58 const OpenWithDialogController::SetDefaultCallback& callback); 58 const OpenWithDialogController::SetDefaultCallback& callback);
59 59
60 private: 60 private:
61 enum State { 61 enum State {
62 // The Context has been constructed. 62 // The Context has been constructed.
63 CONTEXT_INITIALIZED, 63 CONTEXT_INITIALIZED,
64 // The UI automation event handler is ready. 64 // The UI automation event handler is ready.
65 CONTEXT_AUTOMATION_READY, 65 CONTEXT_AUTOMATION_READY,
66 // The automation results came back before the call to SHOpenWithDialog. 66 // The automation results came back before the call to SHOpenWithDialog.
67 CONTEXT_WAITING_FOR_DIALOG, 67 CONTEXT_WAITING_FOR_DIALOG,
68 // The call to SHOpenWithDialog returned before automation results. 68 // The call to SHOpenWithDialog returned before automation results.
69 CONTEXT_WAITING_FOR_RESULTS, 69 CONTEXT_WAITING_FOR_RESULTS,
70 CONTEXT_FINISHED, 70 CONTEXT_FINISHED,
71 }; 71 };
72 72
73 // Invokes the client's callback and destroys this instance. 73 // Invokes the client's callback and destroys this instance.
74 void NotifyClientAndDie(); 74 void NotifyClientAndDie();
75 75
76 void OnTimeout(); 76 void OnTimeout();
77 void OnInitialized(HRESULT result); 77 void OnInitialized(HRESULT result);
78 void OnAutomationResult(HRESULT result, std::vector<string16> choices); 78 void OnAutomationResult(HRESULT result, std::vector<base::string16> choices);
79 void OnOpenWithComplete(HRESULT result); 79 void OnOpenWithComplete(HRESULT result);
80 80
81 base::ThreadChecker thread_checker_; 81 base::ThreadChecker thread_checker_;
82 State state_; 82 State state_;
83 internal::UIAutomationClient automation_client_; 83 internal::UIAutomationClient automation_client_;
84 HWND parent_window_; 84 HWND parent_window_;
85 string16 file_name_; 85 base::string16 file_name_;
86 string16 file_type_class_; 86 base::string16 file_type_class_;
87 int open_as_info_flags_; 87 int open_as_info_flags_;
88 OpenWithDialogController::SetDefaultCallback callback_; 88 OpenWithDialogController::SetDefaultCallback callback_;
89 HRESULT open_with_result_; 89 HRESULT open_with_result_;
90 HRESULT automation_result_; 90 HRESULT automation_result_;
91 std::vector<string16> automation_choices_; 91 std::vector<base::string16> automation_choices_;
92 base::WeakPtrFactory<Context> weak_ptr_factory_; 92 base::WeakPtrFactory<Context> weak_ptr_factory_;
93 DISALLOW_COPY_AND_ASSIGN(OpenWithDialogController::Context); 93 DISALLOW_COPY_AND_ASSIGN(OpenWithDialogController::Context);
94 }; 94 };
95 95
96 OpenWithDialogController::Context::Context() 96 OpenWithDialogController::Context::Context()
97 : state_(CONTEXT_INITIALIZED), 97 : state_(CONTEXT_INITIALIZED),
98 parent_window_(), 98 parent_window_(),
99 open_as_info_flags_(), 99 open_as_info_flags_(),
100 open_with_result_(E_FAIL), 100 open_with_result_(E_FAIL),
101 automation_result_(E_FAIL), 101 automation_result_(E_FAIL),
(...skipping 15 matching lines...) Expand all
117 // The controller is being destroyed. Its client is no longer interested in 117 // The controller is being destroyed. Its client is no longer interested in
118 // having the interaction continue. 118 // having the interaction continue.
119 DLOG_IF(WARNING, (state_ == CONTEXT_AUTOMATION_READY || 119 DLOG_IF(WARNING, (state_ == CONTEXT_AUTOMATION_READY ||
120 state_ == CONTEXT_WAITING_FOR_DIALOG)) 120 state_ == CONTEXT_WAITING_FOR_DIALOG))
121 << "Abandoning the OpenWithDialog."; 121 << "Abandoning the OpenWithDialog.";
122 delete this; 122 delete this;
123 } 123 }
124 124
125 void OpenWithDialogController::Context::Begin( 125 void OpenWithDialogController::Context::Begin(
126 HWND parent_window, 126 HWND parent_window,
127 const string16& url_protocol, 127 const base::string16& url_protocol,
128 const string16& program_name, 128 const base::string16& program_name,
129 const OpenWithDialogController::SetDefaultCallback& callback) { 129 const OpenWithDialogController::SetDefaultCallback& callback) {
130 DCHECK(thread_checker_.CalledOnValidThread()); 130 DCHECK(thread_checker_.CalledOnValidThread());
131 131
132 parent_window_ = parent_window; 132 parent_window_ = parent_window;
133 file_name_ = url_protocol; 133 file_name_ = url_protocol;
134 file_type_class_.clear(); 134 file_type_class_.clear();
135 open_as_info_flags_ = (OAIF_URL_PROTOCOL | OAIF_FORCE_REGISTRATION | 135 open_as_info_flags_ = (OAIF_URL_PROTOCOL | OAIF_FORCE_REGISTRATION |
136 OAIF_REGISTER_EXT); 136 OAIF_REGISTER_EXT);
137 callback_ = callback; 137 callback_ = callback;
138 138
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 184 }
185 state_ = CONTEXT_AUTOMATION_READY; 185 state_ = CONTEXT_AUTOMATION_READY;
186 OpenWithDialogAsync( 186 OpenWithDialogAsync(
187 parent_window_, file_name_, file_type_class_, open_as_info_flags_, 187 parent_window_, file_name_, file_type_class_, open_as_info_flags_,
188 base::Bind(&OpenWithDialogController::Context::OnOpenWithComplete, 188 base::Bind(&OpenWithDialogController::Context::OnOpenWithComplete,
189 weak_ptr_factory_.GetWeakPtr())); 189 weak_ptr_factory_.GetWeakPtr()));
190 } 190 }
191 191
192 void OpenWithDialogController::Context::OnAutomationResult( 192 void OpenWithDialogController::Context::OnAutomationResult(
193 HRESULT result, 193 HRESULT result,
194 std::vector<string16> choices) { 194 std::vector<base::string16> choices) {
195 DCHECK(thread_checker_.CalledOnValidThread()); 195 DCHECK(thread_checker_.CalledOnValidThread());
196 DCHECK_EQ(automation_result_, E_FAIL); 196 DCHECK_EQ(automation_result_, E_FAIL);
197 197
198 automation_result_ = result; 198 automation_result_ = result;
199 automation_choices_ = choices; 199 automation_choices_ = choices;
200 switch (state_) { 200 switch (state_) {
201 case CONTEXT_AUTOMATION_READY: 201 case CONTEXT_AUTOMATION_READY:
202 // The results of automation are in and we're waiting for 202 // The results of automation are in and we're waiting for
203 // SHOpenWithDialog to return. 203 // SHOpenWithDialog to return.
204 state_ = CONTEXT_WAITING_FOR_DIALOG; 204 state_ = CONTEXT_WAITING_FOR_DIALOG;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 237
238 OpenWithDialogController::~OpenWithDialogController() { 238 OpenWithDialogController::~OpenWithDialogController() {
239 // Orphan the context if this instance is being destroyed before the context 239 // Orphan the context if this instance is being destroyed before the context
240 // finishes its work. 240 // finishes its work.
241 if (context_) 241 if (context_)
242 context_->Orphan(); 242 context_->Orphan();
243 } 243 }
244 244
245 void OpenWithDialogController::Begin( 245 void OpenWithDialogController::Begin(
246 HWND parent_window, 246 HWND parent_window,
247 const string16& url_protocol, 247 const base::string16& url_protocol,
248 const string16& program, 248 const base::string16& program,
249 const SetDefaultCallback& callback) { 249 const SetDefaultCallback& callback) {
250 DCHECK_EQ(context_.get(), static_cast<Context*>(NULL)); 250 DCHECK_EQ(context_.get(), static_cast<Context*>(NULL));
251 if (base::win::GetVersion() < base::win::VERSION_WIN8) { 251 if (base::win::GetVersion() < base::win::VERSION_WIN8) {
252 NOTREACHED() << "Windows 8 is required."; 252 NOTREACHED() << "Windows 8 is required.";
253 // The callback may not properly handle being run from Begin, so post a task 253 // The callback may not properly handle being run from Begin, so post a task
254 // to this thread's task runner to call it. 254 // to this thread's task runner to call it.
255 base::ThreadTaskRunnerHandle::Get()->PostTask( 255 base::ThreadTaskRunnerHandle::Get()->PostTask(
256 FROM_HERE, 256 FROM_HERE,
257 base::Bind(callback, E_FAIL, std::vector<string16>())); 257 base::Bind(callback, E_FAIL, std::vector<base::string16>()));
258 return; 258 return;
259 } 259 }
260 260
261 context_ = (new Context())->AsWeakPtr(); 261 context_ = (new Context())->AsWeakPtr();
262 context_->Begin(parent_window, url_protocol, program, callback); 262 context_->Begin(parent_window, url_protocol, program, callback);
263 } 263 }
264 264
265 HRESULT OpenWithDialogController::RunSynchronously( 265 HRESULT OpenWithDialogController::RunSynchronously(
266 HWND parent_window, 266 HWND parent_window,
267 const string16& protocol, 267 const base::string16& protocol,
268 const string16& program, 268 const base::string16& program,
269 std::vector<string16>* choices) { 269 std::vector<base::string16>* choices) {
270 DCHECK_EQ(base::MessageLoop::current(), 270 DCHECK_EQ(base::MessageLoop::current(),
271 static_cast<base::MessageLoop*>(NULL)); 271 static_cast<base::MessageLoop*>(NULL));
272 if (base::win::GetVersion() < base::win::VERSION_WIN8) { 272 if (base::win::GetVersion() < base::win::VERSION_WIN8) {
273 NOTREACHED() << "Windows 8 is required."; 273 NOTREACHED() << "Windows 8 is required.";
274 return E_FAIL; 274 return E_FAIL;
275 } 275 }
276 276
277 HRESULT result = S_OK; 277 HRESULT result = S_OK;
278 base::MessageLoop message_loop; 278 base::MessageLoop message_loop;
279 base::RunLoop run_loop; 279 base::RunLoop run_loop;
280 280
281 message_loop.PostTask( 281 message_loop.PostTask(
282 FROM_HERE, 282 FROM_HERE,
283 base::Bind(&OpenWithDialogController::Begin, base::Unretained(this), 283 base::Bind(&OpenWithDialogController::Begin, base::Unretained(this),
284 parent_window, protocol, program, 284 parent_window, protocol, program,
285 Bind(&OnMakeDefaultComplete, run_loop.QuitClosure(), 285 Bind(&OnMakeDefaultComplete, run_loop.QuitClosure(),
286 &result, choices))); 286 &result, choices)));
287 287
288 run_loop.Run(); 288 run_loop.Run();
289 return result; 289 return result;
290 } 290 }
291 291
292 } // namespace win8 292 } // namespace win8
OLDNEW
« no previous file with comments | « win8/test/open_with_dialog_controller.h ('k') | win8/test/test_registrar.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698