| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/client/core/settings/settings_feature.h" | 5 #include "blimp/client/core/settings/settings_feature.h" |
| 6 | 6 |
| 7 #include "blimp/client/core/settings/settings.h" |
| 7 #include "blimp/common/create_blimp_message.h" | 8 #include "blimp/common/create_blimp_message.h" |
| 8 #include "blimp/common/proto/blimp_message.pb.h" | 9 #include "blimp/common/proto/blimp_message.pb.h" |
| 9 #include "blimp/common/proto/settings.pb.h" | 10 #include "blimp/common/proto/settings.pb.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 11 | 12 |
| 12 namespace blimp { | 13 namespace blimp { |
| 13 namespace client { | 14 namespace client { |
| 14 | 15 |
| 15 SettingsFeature::SettingsFeature() : record_whole_document_(false) {} | 16 SettingsFeature::SettingsFeature(Settings* settings) |
| 17 : settings_(settings) {} |
| 16 | 18 |
| 17 SettingsFeature::~SettingsFeature() {} | 19 SettingsFeature::~SettingsFeature() = default; |
| 18 | 20 |
| 19 void SettingsFeature::set_outgoing_message_processor( | 21 void SettingsFeature::set_outgoing_message_processor( |
| 20 std::unique_ptr<BlimpMessageProcessor> processor) { | 22 std::unique_ptr<BlimpMessageProcessor> processor) { |
| 21 outgoing_message_processor_ = std::move(processor); | 23 outgoing_message_processor_ = std::move(processor); |
| 22 } | 24 } |
| 23 | 25 |
| 24 void SettingsFeature::SetRecordWholeDocument(bool record_whole_document) { | 26 // TODO(mlliu): remove this method once we set the user agent in PushSettings() |
| 25 if (record_whole_document_ == record_whole_document) | 27 // http://crbug.com/652032. |
| 26 return; | |
| 27 | |
| 28 record_whole_document_ = record_whole_document; | |
| 29 | |
| 30 EngineSettingsMessage* engine_settings; | |
| 31 std::unique_ptr<BlimpMessage> message = CreateBlimpMessage(&engine_settings); | |
| 32 engine_settings->set_record_whole_document(record_whole_document_); | |
| 33 outgoing_message_processor_->ProcessMessage(std::move(message), | |
| 34 net::CompletionCallback()); | |
| 35 } | |
| 36 | |
| 37 void SettingsFeature::SendUserAgentOSVersionInfo(const std::string& osVersion) { | 28 void SettingsFeature::SendUserAgentOSVersionInfo(const std::string& osVersion) { |
| 38 EngineSettingsMessage* engine_settings; | 29 EngineSettingsMessage* engine_settings; |
| 39 std::unique_ptr<BlimpMessage> message = CreateBlimpMessage(&engine_settings); | 30 std::unique_ptr<BlimpMessage> message = CreateBlimpMessage(&engine_settings); |
| 40 engine_settings->set_client_os_info(osVersion); | 31 engine_settings->set_client_os_info(osVersion); |
| 41 outgoing_message_processor_->ProcessMessage(std::move(message), | 32 outgoing_message_processor_->ProcessMessage(std::move(message), |
| 42 net::CompletionCallback()); | 33 net::CompletionCallback()); |
| 43 } | 34 } |
| 44 | 35 |
| 45 void SettingsFeature::ProcessMessage(std::unique_ptr<BlimpMessage> message, | 36 void SettingsFeature::ProcessMessage(std::unique_ptr<BlimpMessage> message, |
| 46 const net::CompletionCallback& callback) { | 37 const net::CompletionCallback& callback) { |
| 47 // We don't receive any messages from the engine yet. | 38 // We don't receive any messages from the engine yet. |
| 48 NOTREACHED() << "Invalid settings message received from the engine."; | 39 NOTREACHED() << "Invalid settings message received from the engine."; |
| 49 callback.Run(net::OK); | 40 callback.Run(net::OK); |
| 50 } | 41 } |
| 51 | 42 |
| 43 void SettingsFeature::OnRecordWholeDocumentChanged(bool enable) { |
| 44 EngineSettingsMessage* engine_settings; |
| 45 std::unique_ptr<BlimpMessage> message = CreateBlimpMessage(&engine_settings); |
| 46 engine_settings->set_record_whole_document(enable); |
| 47 outgoing_message_processor_->ProcessMessage(std::move(message), |
| 48 net::CompletionCallback()); |
| 49 } |
| 50 |
| 51 void SettingsFeature::PushSettings() { |
| 52 // TODO(mlliu): set the user agent on the proto as well after moving |
| 53 // blimp/client/app/user_agent.* to this directory (http://crbug.com/652032). |
| 54 EngineSettingsMessage* engine_settings; |
| 55 std::unique_ptr<BlimpMessage> message = CreateBlimpMessage(&engine_settings); |
| 56 engine_settings->set_record_whole_document( |
| 57 settings_->record_whole_document()); |
| 58 outgoing_message_processor_->ProcessMessage(std::move(message), |
| 59 net::CompletionCallback()); |
| 60 } |
| 61 |
| 52 } // namespace client | 62 } // namespace client |
| 53 } // namespace blimp | 63 } // namespace blimp |
| OLD | NEW |