-
Notifications
You must be signed in to change notification settings - Fork 6k
Updates in flutter/fml for the shell refactor (Patch 5). #4833
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2018 The Flutter 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 "flutter/fml/file.h" | ||
|
||
#include <fcntl.h> | ||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
|
||
#include "lib/fxl/files/eintr_wrapper.h" | ||
|
||
namespace fml { | ||
|
||
fxl::UniqueFD OpenFile(const char* path, | ||
OpenPermission permission, | ||
bool is_directory) { | ||
return OpenFile(fxl::UniqueFD{AT_FDCWD}, path, permission, is_directory); | ||
} | ||
|
||
fxl::UniqueFD OpenFile(const fxl::UniqueFD& base_directory, | ||
const char* path, | ||
OpenPermission permission, | ||
bool is_directory) { | ||
if (path == nullptr) { | ||
return fxl::UniqueFD{}; | ||
} | ||
|
||
int flags = 0; | ||
switch (permission) { | ||
case OpenPermission::kRead: | ||
flags = O_RDONLY; | ||
break; | ||
case OpenPermission::kWrite: | ||
flags = O_WRONLY; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing a break here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
case OpenPermission::kReadWrite: | ||
flags = O_RDWR; | ||
break; | ||
} | ||
|
||
if (is_directory) { | ||
flags |= O_DIRECTORY; | ||
} | ||
|
||
return fxl::UniqueFD{ | ||
HANDLE_EINTR(::openat(base_directory.get(), path, flags))}; | ||
} | ||
|
||
fxl::UniqueFD Duplicate(int descriptor) { | ||
return fxl::UniqueFD{HANDLE_EINTR(::dup(descriptor))}; | ||
} | ||
|
||
bool IsDirectory(const fxl::UniqueFD& directory) { | ||
if (!directory.is_valid()) { | ||
return false; | ||
} | ||
|
||
struct stat stat_result = {}; | ||
|
||
if (::fstat(directory.get(), &stat_result) != 0) { | ||
return false; | ||
} | ||
|
||
return S_ISDIR(stat_result.st_mode); | ||
} | ||
|
||
} // namespace fml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2018 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_FML_FILE_H_ | ||
#define FLUTTER_FML_FILE_H_ | ||
|
||
#include "lib/fxl/files/unique_fd.h" | ||
#include "lib/fxl/macros.h" | ||
|
||
namespace fml { | ||
|
||
enum class OpenPermission { | ||
kRead = 1, | ||
kWrite = 1 << 1, | ||
kReadWrite = kRead | kWrite, | ||
}; | ||
|
||
fxl::UniqueFD OpenFile(const char* path, | ||
OpenPermission permission, | ||
bool is_directory = false); | ||
|
||
fxl::UniqueFD OpenFile(const fxl::UniqueFD& base_directory, | ||
const char* path, | ||
OpenPermission permission, | ||
bool is_directory = false); | ||
|
||
fxl::UniqueFD Duplicate(int descriptor); | ||
|
||
bool IsDirectory(const fxl::UniqueFD& directory); | ||
|
||
} // namespace fml | ||
|
||
#endif // FLUTTER_FML_FILE_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2018 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef FLUTTER_FML_MACROS_H_ | ||
#define FLUTTER_FML_MACROS_H_ | ||
|
||
#include "lib/fxl/macros.h" | ||
|
||
#ifndef FML_USED_ON_EMBEDDER | ||
|
||
#define FML_EMBEDDER_ONLY [[deprecated]] | ||
|
||
#else // FML_USED_ON_EMBEDDER | ||
|
||
#define FML_EMBEDDER_ONLY | ||
|
||
#endif // FML_USED_ON_EMBEDDER | ||
|
||
#endif // FLUTTER_FML_MACROS_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2018 The Flutter 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 "flutter/fml/mapping.h" | ||
|
||
namespace fml { | ||
|
||
DataMapping::DataMapping(std::vector<uint8_t> data) : data_(std::move(data)) {} | ||
|
||
DataMapping::~DataMapping() = default; | ||
|
||
size_t DataMapping::GetSize() const { | ||
return data_.size(); | ||
} | ||
|
||
const uint8_t* DataMapping::GetMapping() const { | ||
return data_.data(); | ||
} | ||
} // namespace fml |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "lib/fxl/build_config.h" | ||
|
||
|
@@ -39,11 +40,11 @@ std::unique_ptr<Mapping> GetResourceMapping(const std::string& resource_name); | |
|
||
class FileMapping : public Mapping { | ||
public: | ||
FileMapping(const std::string& path); | ||
FileMapping(const std::string& path, bool executable = false); | ||
|
||
// fxl::UniqueFD isn't supported for Windows handles. | ||
#if !OS_WIN | ||
FileMapping(const fxl::UniqueFD& fd); | ||
FileMapping(const fxl::UniqueFD& fd, bool executable = false); | ||
#endif | ||
|
||
~FileMapping() override; | ||
|
@@ -63,6 +64,22 @@ class FileMapping : public Mapping { | |
FXL_DISALLOW_COPY_AND_ASSIGN(FileMapping); | ||
}; | ||
|
||
class DataMapping : public Mapping { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Working with asset bundles and such on Fuchsia. |
||
public: | ||
DataMapping(std::vector<uint8_t> data); | ||
|
||
~DataMapping() override; | ||
|
||
size_t GetSize() const override; | ||
|
||
const uint8_t* GetMapping() const override; | ||
|
||
private: | ||
std::vector<uint8_t> data_; | ||
|
||
FXL_DISALLOW_COPY_AND_ASSIGN(DataMapping); | ||
}; | ||
|
||
} // namespace fml | ||
|
||
#endif // FLUTTER_FML_MAPPING_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2016 The Fuchsia Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
// A class for checking that the current thread is/isn't the same as an initial | ||
// thread. | ||
|
||
#ifndef LIB_FXL_SYNCHRONIZATION_THREAD_CHECKER_H_ | ||
#define LIB_FXL_SYNCHRONIZATION_THREAD_CHECKER_H_ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we worried that someone will pull in both this and the original? (re: the header guard name) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
|
||
#include "lib/fxl/build_config.h" | ||
|
||
#if defined(OS_WIN) | ||
#include <windows.h> | ||
#else | ||
#include <pthread.h> | ||
#endif | ||
|
||
#include "lib/fxl/logging.h" | ||
#include "lib/fxl/macros.h" | ||
|
||
namespace fml { | ||
|
||
// A simple class that records the identity of the thread that it was created | ||
// on, and at later points can tell if the current thread is the same as its | ||
// creation thread. This class is thread-safe. | ||
// | ||
// Note: Unlike Chromium's |base::ThreadChecker|, this is *not* Debug-only (so | ||
// #ifdef it out if you want something Debug-only). (Rationale: Having a | ||
// |CalledOnValidThread()| that lies in Release builds seems bad. Moreover, | ||
// there's a small space cost to having even an empty class. ) | ||
class ThreadChecker final { | ||
public: | ||
#if defined(OS_WIN) | ||
ThreadChecker() : self_(GetCurrentThreadId()) {} | ||
~ThreadChecker() {} | ||
|
||
bool IsCreationThreadCurrent() const { return GetCurrentThreadId() == self_; } | ||
|
||
private: | ||
DWORD self_; | ||
|
||
#else | ||
ThreadChecker() : self_(pthread_self()) {} | ||
~ThreadChecker() {} | ||
|
||
// Returns true if the current thread is the thread this object was created | ||
// on and false otherwise. | ||
bool IsCreationThreadCurrent() const { | ||
return !!pthread_equal(pthread_self(), self_); | ||
} | ||
|
||
private: | ||
pthread_t self_; | ||
#endif | ||
}; | ||
|
||
#ifndef NDEBUG | ||
#define FML_DECLARE_THREAD_CHECKER(c) fml::ThreadChecker c | ||
#define FML_DCHECK_CREATION_THREAD_IS_CURRENT(c) \ | ||
FXL_DCHECK((c).IsCreationThreadCurrent()) | ||
#else | ||
#define FML_DECLARE_THREAD_CHECKER(c) | ||
#define FML_DCHECK_CREATION_THREAD_IS_CURRENT(c) ((void)0) | ||
#endif | ||
|
||
} // namespace fml | ||
|
||
#endif // LIB_FXL_SYNCHRONIZATION_THREAD_CHECKER_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and elswhere: keep as
The Chromium Authors
for now for consistency.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saying that would be factually incorrect though. We don't modify existing headers but use the latest message for new files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @Hixie for clarification on all things licence-y since I'm not 100% sure what we're meant to do in these cases.