Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 Google, Inc. |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at: |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | // |
| 16 | |
| 17 | #include "service/settings.h" |
| 18 | |
| 19 | #include <base/command_line.h> |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 20 | #include <base/logging.h> |
| 21 | |
| 22 | #include "service/switches.h" |
| 23 | |
| 24 | namespace bluetooth { |
| 25 | |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 26 | Settings::Settings() : initialized_(false) { |
| 27 | } |
| 28 | |
| 29 | Settings::~Settings() { |
| 30 | } |
| 31 | |
| 32 | bool Settings::Init() { |
| 33 | CHECK(!initialized_); |
| 34 | auto command_line = base::CommandLine::ForCurrentProcess(); |
Arman Uguray | fe65fb7 | 2015-07-24 19:14:42 -0700 | [diff] [blame] | 35 | const auto& switches = command_line->GetSwitches(); |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 36 | |
Arman Uguray | fe65fb7 | 2015-07-24 19:14:42 -0700 | [diff] [blame] | 37 | for (const auto& iter : switches) { |
Ian Coolidge | c6760d8 | 2015-07-30 20:51:47 -0700 | [diff] [blame^] | 38 | if (iter.first == switches::kCreateIPCSocketPath) { |
| 39 | // kCreateIPCSocketPath: An optional argument that initializes an IPC |
| 40 | // socket path for IPC. |
Arman Uguray | fe65fb7 | 2015-07-24 19:14:42 -0700 | [diff] [blame] | 41 | base::FilePath path(iter.second); |
| 42 | if (path.empty() || path.EndsWithSeparator()) { |
Ian Coolidge | c6760d8 | 2015-07-30 20:51:47 -0700 | [diff] [blame^] | 43 | LOG(ERROR) << "Invalid IPC create socket path"; |
Arman Uguray | fe65fb7 | 2015-07-24 19:14:42 -0700 | [diff] [blame] | 44 | return false; |
| 45 | } |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 46 | |
Ian Coolidge | c6760d8 | 2015-07-30 20:51:47 -0700 | [diff] [blame^] | 47 | create_ipc_socket_path_ = path; |
| 48 | } else if (iter.first == switches::kAndroidIPCSocketSuffix) { |
| 49 | // kAndroidIPCSocketSuffix: An optional argument used to express |
| 50 | // a socket that Android init created for us. We bind to this. |
| 51 | const std::string& suffix = iter.second; |
| 52 | if (suffix.empty()) { |
| 53 | LOG(ERROR) << "Invalid Android socket suffix"; |
| 54 | return false; |
| 55 | } |
| 56 | |
| 57 | android_ipc_socket_suffix_ = suffix; |
Arman Uguray | fe65fb7 | 2015-07-24 19:14:42 -0700 | [diff] [blame] | 58 | } else { |
| 59 | LOG(ERROR) << "Unexpected command-line switches found"; |
| 60 | return false; |
| 61 | } |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Ian Coolidge | c6760d8 | 2015-07-30 20:51:47 -0700 | [diff] [blame^] | 64 | // Two IPC methods/paths were provided. |
| 65 | if (!android_ipc_socket_suffix_.empty() && |
| 66 | !create_ipc_socket_path_.empty()) { |
| 67 | LOG(ERROR) << "Too many IPC methods provided"; |
| 68 | return false; |
| 69 | } |
| 70 | |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 71 | // The daemon has no arguments |
| 72 | if (command_line->GetArgs().size()) { |
| 73 | LOG(ERROR) << "Unexpected command-line arguments found"; |
| 74 | return false; |
| 75 | } |
| 76 | |
Arman Uguray | 065d0f7 | 2015-07-16 18:12:13 -0700 | [diff] [blame] | 77 | initialized_ = true; |
| 78 | return true; |
| 79 | } |
| 80 | |
| 81 | } // namespace bluetooth |