Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: mojo/file_utils/lib/file_util.cc

Issue 1915193002: Simplify the organization of //mojo_file_utils. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/file_utils/file_util_unittest.cc ('k') | mojo/file_utils/tests/file_util_test_base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/file_utils/lib/file_util.cc
diff --git a/mojo/file_utils/lib/file_util.cc b/mojo/file_utils/lib/file_util.cc
deleted file mode 100644
index 28d7f1db4ee159528d8b0bd4b4d0f85cdf7478a2..0000000000000000000000000000000000000000
--- a/mojo/file_utils/lib/file_util.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-// 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/file_utils/file_util.h"
-
-#include <stdint.h>
-
-#include "mojo/services/files/interfaces/directory.mojom.h"
-#include "mojo/services/files/interfaces/file.mojom.h"
-#include "mojo/services/files/interfaces/types.mojom.h"
-
-namespace file_utils {
-
-mojo::files::FilePtr CreateTemporaryFileInDir(
- mojo::files::DirectoryPtr* directory,
- std::string* path_name) {
- std::string internal_path_name;
- const std::string charset("abcdefghijklmnopqrstuvwxyz1234567890");
- const unsigned kSuffixLength = 6;
- const unsigned kMaxNumAttempts = 10;
- mojo::files::FilePtr temp_file;
- mojo::files::Error error = mojo::files::Error::INTERNAL;
- uint64_t random_value = 0;
- for (unsigned attempt = 0; attempt < kMaxNumAttempts; attempt++) {
- internal_path_name = ".org.chromium.Mojo.";
- uint64_t microseconds = static_cast<uint64_t>(MojoGetTimeTicksNow());
- for (unsigned i = 0; i < kSuffixLength; i++) {
- // This roughly matches glibc's mapping from time to "random_time_bits",
- // it seems to be good enough for creating temporary files.
- random_value += (microseconds << 16) ^ (microseconds / 1000000);
- internal_path_name.push_back(charset[random_value % charset.length()]);
- }
- (*directory)
- ->OpenFile(internal_path_name, GetProxy(&temp_file),
- mojo::files::kOpenFlagWrite | mojo::files::kOpenFlagRead |
- mojo::files::kOpenFlagCreate |
- mojo::files::kOpenFlagExclusive,
- [&error](mojo::files::Error e) { error = e; });
- if (!directory->WaitForIncomingResponse())
- return nullptr;
- // TODO(smklein): React to error code when ErrnoToError can return something
- // other than Error::UNKNOWN. We only want to retry when "EEXIST" is thrown.
- if (error == mojo::files::Error::OK) {
- *path_name = internal_path_name;
- return temp_file;
- }
- }
- return nullptr;
-}
-
-} // namespace file_utils
« no previous file with comments | « mojo/file_utils/file_util_unittest.cc ('k') | mojo/file_utils/tests/file_util_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698