Chromium Code Reviews| Index: mojo/runner/scoped_user_data_dir.cc |
| diff --git a/mojo/runner/scoped_user_data_dir.cc b/mojo/runner/scoped_user_data_dir.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9960312b4701b12c3b8b3cc83ba828ad0ef0ee95 |
| --- /dev/null |
| +++ b/mojo/runner/scoped_user_data_dir.cc |
| @@ -0,0 +1,39 @@ |
| +// Copyright 2015 The Chromium 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 "mojo/runner/scoped_user_data_dir.h" |
| + |
| +#include "base/command_line.h" |
| +#include "base/logging.h" |
| +#include "mojo/runner/switches.h" |
| + |
| +namespace mojo { |
| +namespace runner { |
| + |
| +ScopedUserDataDir::ScopedUserDataDir() { |
| + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| + if (command_line->HasSwitch(switches::kUseTemporaryUserDataDir)) { |
|
jam
2015/06/25 15:28:23
nit: early return here would remove indentation
|
| + if (command_line->HasSwitch(switches::kUserDataDir)) { |
|
jam
2015/06/25 15:28:23
nit: just CHECK(!command_line->HasSwitch(switches:
Elliot Glaysher
2015/06/25 22:46:48
Disagree. Errors that users can trigger should hav
|
| + // User should not specify a --user-data-dir manually when using |
| + // --use-temporary-user-data-dir. The point of the flag is to let the |
| + // mojo runner process manage the lifetime of the user data dir. |
| + LOG(ERROR) << "Can not have both --user-data-dir and " |
| + << "--use-temporary-user-data-dir in the same process."; |
| + return; |
| + } |
| + |
| + if (!temp_dir_.CreateUniqueTempDir()) { |
| + LOG(ERROR) << "Failed to create a temporary user data dir."; |
| + return; |
| + } |
| + |
| + command_line->AppendSwitchPath(switches::kUserDataDir, temp_dir_.path()); |
| + } |
| +} |
| + |
| +ScopedUserDataDir::~ScopedUserDataDir() { |
| +} |
| + |
| +} // namespace runner |
| +} // namespace mojo |