Skip to content

Commit 6f9896d

Browse files
mlcui-corpChromium LUCI CQ
authored andcommitted
scanner: Remove command delegate from action view model class
The command delegate used for all actions is effectively a per-session singleton in the controller, so storing a reference to it in the action view model is redundant. The command delegate in the session is now unused. It will be removed in https://crrev.com/c/6182423. Bug: b:390305029 Change-Id: I6a6a21003c7ef5a16abc40a8f24ef858e9a7c2cb Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6174827 Reviewed-by: Jon Htin <[email protected]> Commit-Queue: Michael Cui <[email protected]> Cr-Commit-Position: refs/heads/main@{#1408508}
1 parent 44c27d1 commit 6f9896d

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

ash/scanner/scanner_action_view_model.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
#include <utility>
99

1010
#include "ash/resources/vector_icons/vector_icons.h"
11-
#include "ash/scanner/scanner_command_delegate.h"
1211
#include "ash/strings/grit/ash_strings.h"
1312
#include "base/memory/ref_counted_memory.h"
1413
#include "base/memory/scoped_refptr.h"
15-
#include "base/memory/weak_ptr.h"
1614
#include "base/notreached.h"
1715
#include "chromeos/ui/vector_icons/vector_icons.h"
1816
#include "components/manta/proto/scanner.pb.h"
@@ -22,11 +20,9 @@ namespace ash {
2220

2321
ScannerActionViewModel::ScannerActionViewModel(
2422
manta::proto::ScannerAction unpopulated_action,
25-
scoped_refptr<base::RefCountedMemory> downscaled_jpeg_bytes,
26-
base::WeakPtr<ScannerCommandDelegate> delegate)
23+
scoped_refptr<base::RefCountedMemory> downscaled_jpeg_bytes)
2724
: unpopulated_action_(std::move(unpopulated_action)),
28-
downscaled_jpeg_bytes_(std::move(downscaled_jpeg_bytes)),
29-
delegate_(std::move(delegate)) {}
25+
downscaled_jpeg_bytes_(std::move(downscaled_jpeg_bytes)) {}
3026

3127
ScannerActionViewModel::ScannerActionViewModel(const ScannerActionViewModel&) =
3228
default;

ash/scanner/scanner_action_view_model.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "base/functional/callback_helpers.h"
1212
#include "base/memory/ref_counted_memory.h"
1313
#include "base/memory/scoped_refptr.h"
14-
#include "base/memory/weak_ptr.h"
1514
#include "components/manta/proto/scanner.pb.h"
1615

1716
namespace gfx {
@@ -20,16 +19,13 @@ struct VectorIcon;
2019

2120
namespace ash {
2221

23-
class ScannerCommandDelegate;
24-
2522
// A view model wrapper around a `ScannerUnpopulatedAction`, which handles the
2623
// conversion to a user-facing text string, icon, and a callback.
2724
class ASH_EXPORT ScannerActionViewModel {
2825
public:
2926
explicit ScannerActionViewModel(
3027
manta::proto::ScannerAction unpopulated_action,
31-
scoped_refptr<base::RefCountedMemory> downscaled_jpeg_bytes,
32-
base::WeakPtr<ScannerCommandDelegate> delegate);
28+
scoped_refptr<base::RefCountedMemory> downscaled_jpeg_bytes);
3329
ScannerActionViewModel(const ScannerActionViewModel&);
3430
ScannerActionViewModel& operator=(const ScannerActionViewModel&);
3531
ScannerActionViewModel(ScannerActionViewModel&&);
@@ -48,12 +44,10 @@ class ASH_EXPORT ScannerActionViewModel {
4844
const scoped_refptr<base::RefCountedMemory>& downscaled_jpeg_bytes() const {
4945
return downscaled_jpeg_bytes_;
5046
}
51-
base::WeakPtr<ScannerCommandDelegate> delegate() const { return delegate_; }
5247

5348
private:
5449
manta::proto::ScannerAction unpopulated_action_;
5550
scoped_refptr<base::RefCountedMemory> downscaled_jpeg_bytes_;
56-
base::WeakPtr<ScannerCommandDelegate> delegate_;
5751
};
5852

5953
} // namespace ash

ash/scanner/scanner_controller.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,19 @@ void ScannerController::ExecuteAction(
315315
if (!scanner_session_) {
316316
return;
317317
}
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_);
318323
const manta::proto::ScannerAction::ActionCase action_case =
319324
scanner_action.GetActionCase();
320325
scanner_session_->PopulateAction(
321326
scanner_action.downscaled_jpeg_bytes(),
322327
scanner_action.unpopulated_action(),
323328
base::BindOnce(
324329
&ExecutePopulatedAction, action_case, base::TimeTicks::Now(),
325-
scanner_action.delegate(),
330+
command_delegate_->GetWeakPtr(),
326331
base::BindOnce(&ScannerController::OnActionFinished,
327332
weak_ptr_factory_.GetWeakPtr(), action_case)));
328333
ShowActionProgressNotification(action_case);

ash/scanner/scanner_session.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ void ScannerSession::OnActionsReturned(
215215
if (proto_action.action_case() !=
216216
manta::proto::ScannerAction::ACTION_NOT_SET) {
217217
action_view_models.emplace_back(std::move(proto_action),
218-
downscaled_jpeg_bytes,
219-
command_delegate_->GetWeakPtr());
218+
downscaled_jpeg_bytes);
220219
}
221220
}
222221

0 commit comments

Comments
 (0)