blob: 6e9312c71c401ca70e32c4da395bc718970f56c9 [file] [log] [blame]
Vladislav Kaznacheev92edf62e2017-10-13 22:08:011// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ash/note_taking_controller.h"
6
7namespace ash {
8
9NoteTakingController::NoteTakingController() : binding_(this) {}
10
11NoteTakingController::~NoteTakingController() = default;
12
13void NoteTakingController::BindRequest(
14 mojom::NoteTakingControllerRequest request) {
15 binding_.Bind(std::move(request));
16}
17
18void NoteTakingController::SetClient(
19 mojom::NoteTakingControllerClientPtr client) {
20 DCHECK(!client_);
21 client_ = std::move(client);
22 client_.set_connection_error_handler(base::Bind(
23 &NoteTakingController::OnClientConnectionLost, base::Unretained(this)));
24}
25
26bool NoteTakingController::CanCreateNote() const {
27 return static_cast<bool>(client_);
28}
29
30void NoteTakingController::CreateNote() {
31 DCHECK(client_);
32 client_->CreateNote();
33}
34
35void NoteTakingController::OnClientConnectionLost() {
36 client_.reset();
37 binding_.Close();
38}
39
40void NoteTakingController::FlushMojoForTesting() {
41 if (client_)
42 client_.FlushForTesting();
43}
44
45} // namespace ash