Vladislav Kaznacheev | 92edf62e | 2017-10-13 22:08:01 | [diff] [blame] | 1 | // 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 | |
| 7 | namespace ash { |
| 8 | |
| 9 | NoteTakingController::NoteTakingController() : binding_(this) {} |
| 10 | |
| 11 | NoteTakingController::~NoteTakingController() = default; |
| 12 | |
| 13 | void NoteTakingController::BindRequest( |
| 14 | mojom::NoteTakingControllerRequest request) { |
| 15 | binding_.Bind(std::move(request)); |
| 16 | } |
| 17 | |
| 18 | void 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 | |
| 26 | bool NoteTakingController::CanCreateNote() const { |
| 27 | return static_cast<bool>(client_); |
| 28 | } |
| 29 | |
| 30 | void NoteTakingController::CreateNote() { |
| 31 | DCHECK(client_); |
| 32 | client_->CreateNote(); |
| 33 | } |
| 34 | |
| 35 | void NoteTakingController::OnClientConnectionLost() { |
| 36 | client_.reset(); |
| 37 | binding_.Close(); |
| 38 | } |
| 39 | |
| 40 | void NoteTakingController::FlushMojoForTesting() { |
| 41 | if (client_) |
| 42 | client_.FlushForTesting(); |
| 43 | } |
| 44 | |
| 45 | } // namespace ash |