Skip to content

Commit d77129e

Browse files
mlcui-corpChromium LUCI CQ
authored andcommitted
scanner: Remove unused command delegate from session
This is now unused as of https://crrev.com/c/6174827. Bug: b:390305029 Change-Id: I6a6a21003ae16a4f578b2d2d20099fd1ac869347 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6182423 Commit-Queue: Michael Cui <[email protected]> Reviewed-by: Jon Htin <[email protected]> Cr-Commit-Position: refs/heads/main@{#1408509}
1 parent 6f9896d commit d77129e

File tree

4 files changed

+21
-48
lines changed

4 files changed

+21
-48
lines changed

ash/scanner/scanner_controller.cc

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,8 @@ ScannerSession* ScannerController::StartNewSession() {
282282
// (to avoid subtle issues from having simultaneously existing sessions).
283283
scanner_session_ = nullptr;
284284
if (CanStartSession()) {
285-
ScannerProfileScopedDelegate* profile_scoped_delegate =
286-
delegate_->GetProfileScopedDelegate();
287-
// Keep the existing `command_delegate_` if there is one, to allow commands
288-
// from previous sessions to continue in the background if needed.
289-
if (command_delegate_ == nullptr) {
290-
command_delegate_ =
291-
std::make_unique<ScannerCommandDelegateImpl>(profile_scoped_delegate);
292-
}
293-
scanner_session_ = std::make_unique<ScannerSession>(
294-
profile_scoped_delegate, command_delegate_.get());
285+
scanner_session_ =
286+
std::make_unique<ScannerSession>(delegate_->GetProfileScopedDelegate());
295287
}
296288
return scanner_session_.get();
297289
}
@@ -315,11 +307,12 @@ void ScannerController::ExecuteAction(
315307
if (!scanner_session_) {
316308
return;
317309
}
318-
// During an active user session, the first successful `StartNewSession()`
319-
// call will create both the session and the command delegate. The command
320-
// delegate is never reset afterwards, so the command delegate should always
321-
// exist here.
322-
CHECK(command_delegate_);
310+
// Keep the existing `command_delegate_` if there is one, to allow commands
311+
// from previous sessions to continue in the background if needed.
312+
if (!command_delegate_) {
313+
command_delegate_ = std::make_unique<ScannerCommandDelegateImpl>(
314+
delegate_->GetProfileScopedDelegate());
315+
}
323316
const manta::proto::ScannerAction::ActionCase action_case =
324317
scanner_action.GetActionCase();
325318
scanner_session_->PopulateAction(

ash/scanner/scanner_session.cc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
#include "ash/public/cpp/scanner/scanner_profile_scoped_delegate.h"
1515
#include "ash/scanner/scanner_action_view_model.h"
16-
#include "ash/scanner/scanner_command_delegate.h"
1716
#include "ash/scanner/scanner_metrics.h"
1817
#include "base/functional/bind.h"
1918
#include "base/functional/callback.h"
@@ -168,9 +167,8 @@ void RecordAllDetectedActions(const manta::proto::ScannerOutput& output) {
168167

169168
} // namespace
170169

171-
ScannerSession::ScannerSession(ScannerProfileScopedDelegate* delegate,
172-
ScannerCommandDelegate* command_delegate)
173-
: delegate_(delegate), command_delegate_(command_delegate) {}
170+
ScannerSession::ScannerSession(ScannerProfileScopedDelegate* delegate)
171+
: delegate_(delegate) {}
174172

175173
ScannerSession::~ScannerSession() = default;
176174

ash/scanner/scanner_session.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
namespace ash {
2323

24-
class ScannerCommandDelegate;
2524
class ScannerProfileScopedDelegate;
2625

2726
// A ScannerSession represents a single "use" of the Scanner feature. A session
@@ -38,8 +37,7 @@ class ASH_EXPORT ScannerSession {
3837
using PopulateActionCallback =
3938
base::OnceCallback<void(manta::proto::ScannerAction action)>;
4039

41-
ScannerSession(ScannerProfileScopedDelegate* delegate,
42-
ScannerCommandDelegate* command_delegate);
40+
explicit ScannerSession(ScannerProfileScopedDelegate* delegate);
4341
ScannerSession(const ScannerSession&) = delete;
4442
ScannerSession& operator=(const ScannerSession&) = delete;
4543
~ScannerSession();
@@ -66,10 +64,6 @@ class ASH_EXPORT ScannerSession {
6664

6765
const raw_ptr<ScannerProfileScopedDelegate> delegate_;
6866

69-
// Delegate for performing relevant commands after an action is fetched.
70-
// Should outlive `this`.
71-
const raw_ptr<ScannerCommandDelegate> command_delegate_;
72-
7367
base::WeakPtrFactory<ScannerSession> weak_ptr_factory_{this};
7468
};
7569

ash/scanner/scanner_session_unittest.cc

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "ash/scanner/fake_scanner_profile_scoped_delegate.h"
1313
#include "ash/scanner/scanner_action_view_model.h"
14-
#include "ash/scanner/scanner_command_delegate_impl.h"
1514
#include "ash/scanner/scanner_metrics.h"
1615
#include "base/memory/ref_counted_memory.h"
1716
#include "base/memory/scoped_refptr.h"
@@ -59,8 +58,7 @@ TEST(ScannerSessionTest, FetchActionsForImageReturnsEmptyWhenDelegateErrors) {
5958
.WillOnce(RunOnceCallback<1>(
6059
nullptr, manta::MantaStatus{
6160
.status_code = manta::MantaStatusCode::kInvalidInput}));
62-
ScannerCommandDelegateImpl command_delegate(&delegate);
63-
ScannerSession session(&delegate, &command_delegate);
61+
ScannerSession session(&delegate);
6462

6563
base::test::TestFuture<std::vector<ScannerActionViewModel>> future;
6664
session.FetchActionsForImage(nullptr, future.GetCallback());
@@ -75,8 +73,7 @@ TEST(ScannerSessionTest,
7573
.WillOnce(RunOnceCallback<1>(
7674
std::make_unique<manta::proto::ScannerOutput>(),
7775
manta::MantaStatus{.status_code = manta::MantaStatusCode::kOk}));
78-
ScannerCommandDelegateImpl command_delegate(&delegate);
79-
ScannerSession session(&delegate, &command_delegate);
76+
ScannerSession session(&delegate);
8077

8178
base::test::TestFuture<std::vector<ScannerActionViewModel>> future;
8279
session.FetchActionsForImage(nullptr, future.GetCallback());
@@ -99,8 +96,7 @@ TEST(ScannerSessionTest, FetchActionsForImageRecordsNumberOfActionsMetrics) {
9996
.WillOnce(RunOnceCallback<1>(
10097
std::move(output),
10198
manta::MantaStatus{.status_code = manta::MantaStatusCode::kOk}));
102-
ScannerCommandDelegateImpl command_delegate(&delegate);
103-
ScannerSession session(&delegate, &command_delegate);
99+
ScannerSession session(&delegate);
104100
session.FetchActionsForImage(nullptr, base::DoNothing());
105101

106102
histogram_tester.ExpectBucketCount(
@@ -128,8 +124,7 @@ TEST(ScannerSessionTest, FetchActionsForImageNoActionRecordsMetrics) {
128124
.WillOnce(RunOnceCallback<1>(
129125
std::move(output),
130126
manta::MantaStatus{.status_code = manta::MantaStatusCode::kOk}));
131-
ScannerCommandDelegateImpl command_delegate(&delegate);
132-
ScannerSession session(&delegate, &command_delegate);
127+
ScannerSession session(&delegate);
133128
session.FetchActionsForImage(nullptr, base::DoNothing());
134129

135130
histogram_tester.ExpectBucketCount(
@@ -144,9 +139,7 @@ TEST(ScannerSessionTest, FetchActionsForImageRecordsTimerMetric) {
144139
FetchActionsForImageFuture future;
145140
FakeScannerProfileScopedDelegate delegate;
146141
EXPECT_CALL(delegate, FetchActionsForImage).WillOnce(InvokeFuture(future));
147-
148-
ScannerCommandDelegateImpl command_delegate(&delegate);
149-
ScannerSession session(&delegate, &command_delegate);
142+
ScannerSession session(&delegate);
150143
session.FetchActionsForImage(nullptr, base::DoNothing());
151144
task_environment.FastForwardBy(base::Milliseconds(500));
152145
auto output = std::make_unique<manta::proto::ScannerOutput>();
@@ -172,8 +165,7 @@ TEST(ScannerSessionTest,
172165
.WillOnce(RunOnceCallback<1>(
173166
std::move(output),
174167
manta::MantaStatus{.status_code = manta::MantaStatusCode::kOk}));
175-
ScannerCommandDelegateImpl command_delegate(&delegate);
176-
ScannerSession session(&delegate, &command_delegate);
168+
ScannerSession session(&delegate);
177169

178170
base::test::TestFuture<std::vector<ScannerActionViewModel>> future;
179171
session.FetchActionsForImage(nullptr, future.GetCallback());
@@ -185,8 +177,7 @@ TEST(ScannerSessionTest, ResizesImageHeightToMaxEdge) {
185177
FakeScannerProfileScopedDelegate delegate;
186178
FetchActionsForImageFuture future;
187179
EXPECT_CALL(delegate, FetchActionsForImage).WillOnce(InvokeFuture(future));
188-
ScannerCommandDelegateImpl command_delegate(&delegate);
189-
ScannerSession session(&delegate, &command_delegate);
180+
ScannerSession session(&delegate);
190181

191182
scoped_refptr<base::RefCountedMemory> bytes =
192183
MakeJpegBytes(/*width=*/2300, /*height=*/23000);
@@ -204,8 +195,7 @@ TEST(ScannerSessionTest, ResizesImageWidthToMaxEdge) {
204195
FakeScannerProfileScopedDelegate delegate;
205196
FetchActionsForImageFuture future;
206197
EXPECT_CALL(delegate, FetchActionsForImage).WillOnce(InvokeFuture(future));
207-
ScannerCommandDelegateImpl command_delegate(&delegate);
208-
ScannerSession session(&delegate, &command_delegate);
198+
ScannerSession session(&delegate);
209199

210200
scoped_refptr<base::RefCountedMemory> bytes =
211201
MakeJpegBytes(/*width=*/23000, /*height=*/2300);
@@ -223,8 +213,7 @@ TEST(ScannerSessionTest, NoResizeIfWithinLimit) {
223213
FakeScannerProfileScopedDelegate delegate;
224214
FetchActionsForImageFuture future;
225215
EXPECT_CALL(delegate, FetchActionsForImage).WillOnce(InvokeFuture(future));
226-
ScannerCommandDelegateImpl command_delegate(&delegate);
227-
ScannerSession session(&delegate, &command_delegate);
216+
ScannerSession session(&delegate);
228217

229218
scoped_refptr<base::RefCountedMemory> bytes =
230219
MakeJpegBytes(/*width=*/1000, /*height=*/1000);
@@ -239,8 +228,7 @@ TEST(ScannerSessionTest, DoesNotResizeIfTotalPixelSizeLowerThanMax) {
239228
FakeScannerProfileScopedDelegate delegate;
240229
FetchActionsForImageFuture future;
241230
EXPECT_CALL(delegate, FetchActionsForImage).WillOnce(InvokeFuture(future));
242-
ScannerCommandDelegateImpl command_delegate(&delegate);
243-
ScannerSession session(&delegate, &command_delegate);
231+
ScannerSession session(&delegate);
244232

245233
scoped_refptr<base::RefCountedMemory> bytes =
246234
MakeJpegBytes(/*width=*/4600, /*height=*/1100);

0 commit comments

Comments
 (0)