-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathusb_modem_one_shot_switcher.cc
53 lines (40 loc) · 1.5 KB
/
usb_modem_one_shot_switcher.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mist/usb_modem_one_shot_switcher.h"
#include <base/bind.h>
#include "mist/context.h"
#include "mist/event_dispatcher.h"
#include "mist/metrics.h"
#include "mist/usb_modem_switch_context.h"
#include "mist/usb_modem_switch_operation.h"
namespace mist {
// TODO(benchan): Add unit tests for UsbModemOneShotSwitcher.
UsbModemOneShotSwitcher::UsbModemOneShotSwitcher(Context* context)
: context_(context), is_success_(false) {
CHECK(context_);
}
UsbModemOneShotSwitcher::~UsbModemOneShotSwitcher() {
if (operation_) {
operation_->Cancel();
operation_.reset();
}
}
void UsbModemOneShotSwitcher::Start(UsbModemSwitchContext* switch_context) {
// Ownership of |switch_context| is transferred to |operation_|.
operation_.reset(new UsbModemSwitchOperation(context_, switch_context));
CHECK(operation_);
operation_->Start(
base::Bind(&UsbModemOneShotSwitcher::OnSwitchOperationCompleted,
base::Unretained(this)));
}
void UsbModemOneShotSwitcher::OnSwitchOperationCompleted(
UsbModemSwitchOperation* operation, bool success) {
CHECK_EQ(operation_.get(), operation);
operation_.reset();
is_success_ = success;
context_->metrics()->RecordSwitchResult(success);
// Stop the message loop upon the completion of the switch operation.
context_->event_dispatcher()->Stop();
}
} // namespace mist