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

Side by Side Diff: components/test_runner/spell_check_client.cc

Issue 1852603002: Replacing most of web_task.h with base::Closure + base::WeakPtrFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move-mocks-to-test-runner
Patch Set: Rebasing... Created 4 years, 8 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 | « components/test_runner/spell_check_client.h ('k') | components/test_runner/test_runner.h » ('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 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 "components/test_runner/spell_check_client.h" 5 #include "components/test_runner/spell_check_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind.h"
10 #include "base/bind_helpers.h"
9 #include "base/logging.h" 11 #include "base/logging.h"
10 #include "base/macros.h" 12 #include "base/macros.h"
11 #include "components/test_runner/mock_grammar_check.h" 13 #include "components/test_runner/mock_grammar_check.h"
12 #include "components/test_runner/test_runner.h" 14 #include "components/test_runner/test_runner.h"
15 #include "components/test_runner/web_task.h"
13 #include "components/test_runner/web_test_delegate.h" 16 #include "components/test_runner/web_test_delegate.h"
14 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h" 17 #include "third_party/WebKit/public/web/WebTextCheckingCompletion.h"
15 #include "third_party/WebKit/public/web/WebTextCheckingResult.h" 18 #include "third_party/WebKit/public/web/WebTextCheckingResult.h"
16 19
17 namespace test_runner { 20 namespace test_runner {
18 21
19 namespace {
20
21 class HostMethodTask : public WebMethodTask<SpellCheckClient> {
22 public:
23 typedef void (SpellCheckClient::*CallbackMethodType)();
24 HostMethodTask(SpellCheckClient* object, CallbackMethodType callback)
25 : WebMethodTask<SpellCheckClient>(object), callback_(callback) {}
26
27 ~HostMethodTask() override {}
28
29 void RunIfValid() override { (object_->*callback_)(); }
30
31 private:
32 CallbackMethodType callback_;
33
34 DISALLOW_COPY_AND_ASSIGN(HostMethodTask);
35 };
36
37 } // namespace
38
39 SpellCheckClient::SpellCheckClient(TestRunner* test_runner) 22 SpellCheckClient::SpellCheckClient(TestRunner* test_runner)
40 : last_requested_text_checking_completion_(nullptr), 23 : last_requested_text_checking_completion_(nullptr),
41 test_runner_(test_runner) { 24 test_runner_(test_runner),
25 weak_factory_(this) {
42 DCHECK(test_runner); 26 DCHECK(test_runner);
43 } 27 }
44 28
45 SpellCheckClient::~SpellCheckClient() { 29 SpellCheckClient::~SpellCheckClient() {
46 } 30 }
47 31
48 void SpellCheckClient::SetDelegate(WebTestDelegate* delegate) { 32 void SpellCheckClient::SetDelegate(WebTestDelegate* delegate) {
49 delegate_ = delegate; 33 delegate_ = delegate;
50 } 34 }
51 35
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 84
101 if (last_requested_text_checking_completion_) 85 if (last_requested_text_checking_completion_)
102 last_requested_text_checking_completion_->didCancelCheckingText(); 86 last_requested_text_checking_completion_->didCancelCheckingText();
103 87
104 last_requested_text_checking_completion_ = completion; 88 last_requested_text_checking_completion_ = completion;
105 last_requested_text_check_string_ = text; 89 last_requested_text_check_string_ = text;
106 if (spell_check_.HasInCache(text)) 90 if (spell_check_.HasInCache(text))
107 FinishLastTextCheck(); 91 FinishLastTextCheck();
108 else 92 else
109 delegate_->PostDelayedTask( 93 delegate_->PostDelayedTask(
110 new HostMethodTask(this, &SpellCheckClient::FinishLastTextCheck), 0); 94 new WebCallbackTask(base::Bind(&SpellCheckClient::FinishLastTextCheck,
95 weak_factory_.GetWeakPtr())),
96 0);
111 } 97 }
112 98
113 void SpellCheckClient::FinishLastTextCheck() { 99 void SpellCheckClient::FinishLastTextCheck() {
114 if (!last_requested_text_checking_completion_) 100 if (!last_requested_text_checking_completion_)
115 return; 101 return;
116 std::vector<blink::WebTextCheckingResult> results; 102 std::vector<blink::WebTextCheckingResult> results;
117 int offset = 0; 103 int offset = 0;
118 base::string16 text = last_requested_text_check_string_; 104 base::string16 text = last_requested_text_check_string_;
119 if (!spell_check_.IsMultiWordMisspelling(blink::WebString(text), &results)) { 105 if (!spell_check_.IsMultiWordMisspelling(blink::WebString(text), &results)) {
120 while (text.length()) { 106 while (text.length()) {
(...skipping 19 matching lines...) Expand all
140 &results); 126 &results);
141 } 127 }
142 last_requested_text_checking_completion_->didFinishCheckingText(results); 128 last_requested_text_checking_completion_->didFinishCheckingText(results);
143 last_requested_text_checking_completion_ = 0; 129 last_requested_text_checking_completion_ = 0;
144 130
145 if (test_runner_->shouldDumpSpellCheckCallbacks()) 131 if (test_runner_->shouldDumpSpellCheckCallbacks())
146 delegate_->PrintMessage("SpellCheckEvent: FinishLastTextCheck\n"); 132 delegate_->PrintMessage("SpellCheckEvent: FinishLastTextCheck\n");
147 } 133 }
148 134
149 } // namespace test_runner 135 } // namespace test_runner
OLDNEW
« no previous file with comments | « components/test_runner/spell_check_client.h ('k') | components/test_runner/test_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698